diff --git a/Changes b/Changes index cbef381..c135de0 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,5 @@ Release history for Perl-PrereqScanner-Scanner-Runtime -0.001000 2016-04-09T18:01:04Z b57c196 +0.001000 2016-04-09T18:05:02Z 71219d7 - First version. diff --git a/MANIFEST b/MANIFEST index dc61d61..c5c130c 100644 --- a/MANIFEST +++ b/MANIFEST @@ -33,6 +33,7 @@ t/00-report-prereqs.dd t/00-report-prereqs.t t/all_scanners.t t/class-load/basic.t +t/class-load/ignore.t t/module-load/basic.t t/module-load/ignored.t t/module-runtime/fully_qualified.t diff --git a/lib/Perl/PrereqScanner/Scanner/Class/Load.pm b/lib/Perl/PrereqScanner/Scanner/Class/Load.pm index 2ab4076..f8397af 100644 --- a/lib/Perl/PrereqScanner/Scanner/Class/Load.pm +++ b/lib/Perl/PrereqScanner/Scanner/Class/Load.pm @@ -22,9 +22,7 @@ my %functions = ( try_load_class => '_get_pn', load_optional_class => '_get_pn', ); -my %subs = ( - map { ( "Class::Load::$_" => [ $functions{$_}, $_ ], "$_" => [ $functions{$_}, $_ ], ) } keys %functions -); +my %subs = ( map { ( "Class::Load::$_" => [ $functions{$_}, $_ ], "$_" => [ $functions{$_}, $_ ], ) } keys %functions ); @@ -47,13 +45,19 @@ sub scan_for_prereqs { sub { return q[] unless $_[1]->isa('PPI::Statement'); my (@children) = $_[1]->schildren; - while ( my $child = shift @children ) { + my ( $child, $previous ); + while (@children) { + $previous = $child; + $child = shift @children; # Match sub call next unless $child->isa('PPI::Token::Word') and $child->literal =~ qr/$literal_re/sx; + # Skip methods + next if $previous and $previous->isa('PPI::Token::Operator') and q{->} eq $previous->content; + # Handle a list of arguments as token->next if ( $children[0]->isa('PPI::Structure::List') ) { push @interesting, [ $child->literal, shift @children ]; diff --git a/t/class-load/ignore.t b/t/class-load/ignore.t new file mode 100644 index 0000000..5d955ce --- /dev/null +++ b/t/class-load/ignore.t @@ -0,0 +1,32 @@ +use strict; +use warnings; + +use Test::More; + +# ABSTRACT: Basic class load tests + +use Perl::PrereqScanner; +my $scanner = Perl::PrereqScanner->new( extra_scanners => [qw( Class::Load )], ); +my $prereqs = $scanner->scan_string( + q[ + use Class::Load; + + $thing->load_class("My::ClassA"); + $thing->try_load_class(q{My::ClassB}); + $thing->load_optional_class('My::ClassC'); + +] +)->as_string_hash; + +my $diag_needed; + +$diag_needed = 1 unless ok( !exists $prereqs->{"My::ClassA"}, "ClassA reported" ); +$diag_needed = 1 unless ok( !exists $prereqs->{"My::ClassB"}, "ClassB reported" ); +$diag_needed = 1 unless ok( !exists $prereqs->{"My::ClassC"}, "ClassC reported" ); + +if ($diag_needed) { + diag explain $prereqs; +} + +done_testing; + diff --git a/xt/author/eol.t b/xt/author/eol.t index 0bd67c4..dca6b5e 100644 --- a/xt/author/eol.t +++ b/xt/author/eol.t @@ -19,6 +19,7 @@ my @files = ( 't/00-report-prereqs.t', 't/all_scanners.t', 't/class-load/basic.t', + 't/class-load/ignore.t', 't/module-load/basic.t', 't/module-load/ignored.t', 't/module-runtime/fully_qualified.t',