Skip to content

Instantly share code, notes, and snippets.

@gray
Created March 31, 2011 01:46
Show Gist options
  • Save gray/895678 to your computer and use it in GitHub Desktop.
Save gray/895678 to your computer and use it in GitHub Desktop.
Find specific XS distribution examples
#!/usr/bin/env perl
use 5.012;
use warnings;
use CPAN::DistnameInfo;
use CPAN::Mini::Visit;
use File::Find::Rule;
use File::pushd;
CPAN::Mini::Visit->new(
minicpan => "$ENV{HOME}/local/minicpan",
acme => 0,
prefer_bin => 1, # conserves memory and CPU
callback => sub {
my $data = shift;
my $dir = pushd $data->{tempdir};
my $xs = () = File::Find::Rule->name('*.xs')->file->in('.');
return unless $xs;
# Find distributions that include .c source in a subdirectory.
my $c_in_subdir = () = File::Find::Rule
->mindepth(2)
->name('*.c')
->file
->in('.');
# Find c++ distributions.
# TODO: ? look in (Makefile|Build)\.PL for g++
my $cpp = () = File::Find::Rule
->name(qr/ \. (?: C | (?:(?i) cc | cpp )) $/x)
->file->in('.');
# Find all XS distributions that might call the configure command.
my $configure = () = File::Find::Rule
->maxdepth(1)
->name(qw(Makefile.PL Build.PL))
->file
->grep(qr/\bconfigure\b/)
->in('.');
return unless $c_in_subdir or $cpp or $configure;
my $dist = CPAN::DistnameInfo->new($data->{dist});
say 'c in subdir: ', $dist->dist if $c_in_subdir;
say 'c++: ', $dist->dist if $cpp;
say 'configure: ', $dist->dist if $configure;
}
)->run;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment