diff --git a/lib/App/perlimports/Include.pm b/lib/App/perlimports/Include.pm index bb0e935..95c3490 100644 --- a/lib/App/perlimports/Include.pm +++ b/lib/App/perlimports/Include.pm @@ -340,7 +340,8 @@ sub _build_imports { $self->_document->my_own_inspector->explicit_export_names ) ) { - if ( $self->_is_importable($symbol) ) { + if ( $self->_is_importable($symbol) + && !$self->_document->is_sub_name("$symbol") ) { $found{$symbol} = 1; } } @@ -350,7 +351,8 @@ sub _build_imports { # Sub::Exporter if ( $self->_imports_remain( \%found ) ) { for my $func ( $self->_document->sub_exporter_export_list ) { - if ( $self->_is_importable($func) ) { + if ( $self->_is_importable($func) + && !$self->_document->is_sub_name("$func") ) { $found{$func}++; } } diff --git a/t/locally-defined-sub.t b/t/locally-defined-sub.t new file mode 100644 index 0000000..92dba15 --- /dev/null +++ b/t/locally-defined-sub.t @@ -0,0 +1,38 @@ +use strict; +use warnings; + +use lib 't/lib', 'test-data/lib'; + +use Test::Differences qw( eq_or_diff ); +use TestHelper qw( doc ); +use Test::More import => [qw( done_testing )]; + +my ( $doc, $log ) = doc( + filename => 'test-data/lib/Local/Round.pm', preserve_unused => 0, +); + +my $expected = <<'END'; +package Round; +use parent 'Exporter'; + +use strict; +use warnings; + +use Math::Round qw(nearest); +our @EXPORT_OK = qw(round); + +sub round { + my ( $number, $places ) = @_; + return nearest( 10**-$places, $number ); +} + +1; +END + +eq_or_diff( + $doc->tidied_document, + $expected, + 'locally defined sub is not ignored' +); + +done_testing(); diff --git a/test-data/lib/Local/Round.pm b/test-data/lib/Local/Round.pm new file mode 100644 index 0000000..298d077 --- /dev/null +++ b/test-data/lib/Local/Round.pm @@ -0,0 +1,15 @@ +package Local::Round; +use parent 'Exporter'; + +use strict; +use warnings; + +use Math::Round qw( nearest ); +our @EXPORT_OK = qw(round); + +sub round { + my ( $number, $places ) = @_; + return nearest( 10**-$places, $number ); +} + +1;