| 1 | package MyCPAN::App::DPAN::SkipQueue; | ||
| 2 | use strict; | ||
| 3 | use warnings; | ||
| 4 | |||
| 5 | use base qw(MyCPAN::Indexer::Queue); | ||
| 6 | use vars qw($VERSION $logger); | ||
| 7 | $VERSION = '1.281'; | ||
| 8 | |||
| 9 | use File::Basename; | ||
| 10 | use File::Find; | ||
| 11 | use File::Find::Closures qw( find_by_regex ); | ||
| 12 | use File::Path qw(mkpath); | ||
| 13 | use File::Spec::Functions qw( catfile rel2abs ); | ||
| 14 | use Log::Log4perl; | ||
| 15 | |||
| 16 | BEGIN { | ||
| 17 | $logger = Log::Log4perl->get_logger( 'Queue' ); | ||
| 18 | } | ||
| 19 | |||
| 20 | =encoding utf8 | ||
| 21 | |||
| 22 | =head1 NAME | ||
| 23 | |||
| 24 | MyCPAN::App::DPAN::Queue - Find distributions to index, possibly skipping some | ||
| 25 | |||
| 26 | =head1 SYNOPSIS | ||
| 27 | |||
| 28 | Use this from your C<dpan> configuration file by specifying it as the | ||
| 29 | queue class: | ||
| 30 | |||
| 31 | queue_class MyCPAN::App::DPAN::SkipQueue | ||
| 32 | skip_perl 1 | ||
| 33 | |||
| 34 | # not yet implemented | ||
| 35 | skip_name Foo::Bar Bar::Baz | ||
| 36 | skip_regex Foo::.* | ||
| 37 | |||
| 38 | =head1 DESCRIPTION | ||
| 39 | |||
| 40 | This class returns a list of Perl distributions for the BackPAN | ||
| 41 | indexer to process. | ||
| 42 | |||
| 43 | =head2 Methods | ||
| 44 | |||
| 45 | =over 4 | ||
| 46 | |||
| 47 | =item get_queue | ||
| 48 | |||
| 49 | This extends the C<get_queue> method from C<MyCPAN::Indexer::Queue> | ||
| 50 | to filter the list of files it returns. | ||
| 51 | |||
| 52 | C<get_queue> sets the key C<queue> in C<$Notes> hash reference. It | ||
| 53 | finds all of the tarballs or zip archives in under the directories | ||
| 54 | named in C<dpan_dir> and C<merge_dirs> in the configuration. | ||
| 55 | |||
| 56 | It specifically skips files that end in C<.txt.gz> or C<.data.gz> | ||
| 57 | since PAUSE creates those meta files near the actual module | ||
| 58 | installations. | ||
| 59 | |||
| 60 | If the C<organize_dists> configuration value is true, it also copies | ||
| 61 | any distributions it finds into a PAUSE-like structure using the | ||
| 62 | value of the C<pause_id> configuration to create the path. | ||
| 63 | |||
| 64 | If C<skip_perl> is true, it filters out any distributions matching | ||
| 65 | C<\bperl->. | ||
| 66 | |||
| 67 | =cut | ||
| 68 | |||
| 69 | sub _get_file_list | ||
| 70 | { | ||
| 71 | my( $self, @dirs ) = @_; | ||
| 72 | |||
| 73 | my $files = $self->SUPER::_get_file_list( @dirs ); | ||
| 74 | |||
| 75 | $logger->debug( "There are " . @$files . " files in the queue" ); | ||
| 76 | |||
| 77 | for( my $i = $#$files; $i >= 0; $i-- ) | ||
| 78 | { | ||
| 79 | splice @$files, $i, 1, () | ||
| 80 | if $self->_basename_matches_skip( $files->[$i] ); | ||
| 81 | } | ||
| 82 | |||
| 83 | $logger->debug( "After filtering, there are " . | ||
| 84 | @$files . " files in the queue" ); | ||
| 85 | return $files; | ||
| 86 | } | ||
| 87 | |||
| 88 | sub _basename_matches_skip | ||
| 89 | { | ||
| 90 | my( $self, $distname ) = @_; | ||
| 91 | |||
| 92 | my $skip_perl = $self->get_coordinator->get_config->get( 'skip_perl' ) || 0; | ||
| 93 | my @skip_regexes = grep { defined } | ||
| 94 | $self->get_coordinator->get_config->get( 'skip_dists_regexes' ); | ||
| 95 | |||
| 96 | my @compiled_regexes = map { | ||
| 97 | $logger->debug( "Trying to compile regex [$_]" ); | ||
| 98 | my $compiled = eval { qr/$_/ }; | ||
| 99 | $logger->fatal( "Could not compile regex [$_] from skip_dists_regexes: $@" ) | ||
| 100 | unless ref $compiled eq ref qr//; | ||
| 101 | } @skip_regexes; | ||
| 102 | |||
| 103 | push @skip_regexes, qr/^(?:strawberry-)?perl-/ if $skip_perl; | ||
| 104 | |||
| 105 | $logger->debug( "skip_perl is [$skip_perl]" ); | ||
| 106 | $logger->debug( "skip_dists_regexes is [@skip_regexes]" ); | ||
| 107 | |||
| 108 | my $basename = basename( $distname ); | ||
| 109 | foreach my $regex ( @skip_regexes ) | ||
| 110 | { | ||
| 111 | if( $basename =~ m/$regex/ ) | ||
| 112 | { | ||
| 113 | $logger->debug( "Dist $basename matches $regex" ); | ||
| 114 | return $regex; | ||
| 115 | } | ||
| 116 | } | ||
| 117 | |||
| 118 | return 0; | ||
| 119 | } | ||
| 120 | |||
| 121 | =back | ||
| 122 | |||
| 123 | =head1 SEE ALSO | ||
| 124 | |||
| 125 | MyCPAN::Indexer::Queue | ||
| 126 | |||
| 127 | =head1 SOURCE AVAILABILITY | ||
| 128 | |||
| 129 | This code is in Github: | ||
| 130 | |||
| 131 | git://github.com/briandfoy/mycpan-app-dpan.git | ||
| 132 | |||
| 133 | =head1 AUTHOR | ||
| 134 | |||
| 135 | brian d foy, C<< <bdfoy@cpan.org> >> | ||
| 136 | |||
| 137 | =head1 COPYRIGHT AND LICENSE | ||
| 138 | |||
| 139 | Copyright © 2010-2018, brian d foy <bdfoy@cpan.org>. All rights reserved. | ||
| 140 | |||
| 141 | You may redistribute this under the terms of the Artistic License 2.0. | ||
| 142 | |||
| 143 | =cut |