App-perlimports
view release on metacpan or search on metacpan
lib/App/perlimports/Document.pm view on Meta::CPAN
}
my %symbols = map { $_ => 1 } @symbols;
return \%symbols;
}
# Returns a HashRef of modules which will always be converted to avoid imports.
# This is mostly for speed and a matter of convenience so that we don't have to
# examine modules (like strictly Object Oriented modules) which we know will
# not have anything to export.
sub _build_never_exports {
my $self = shift;
my %modules = (
'App::perlimports::Include' => 1,
'File::Spec' => 1,
'HTTP::Daemon' => 1,
'HTTP::Headers' => 1,
'HTTP::Response' => 1,
'HTTP::Tiny' => 1,
'LWP::UserAgent' => 1,
'URI' => 1,
'WWW::Mechanize' => 1,
);
if ( $self->_has_never_export_modules ) {
for my $module ( @{ $self->_never_export_modules } ) {
$modules{$module} = 1;
}
}
return \%modules;
}
sub _build_sub_names {
my $self = shift;
my %sub_names;
for my $sub (
@{
$self->ppi_document->find(
sub { $_[1]->isa('PPI::Statement::Sub') }
)
|| []
}
) {
my @children = $sub->schildren;
if ( $children[0] eq 'sub'
&& $children[1]->isa('PPI::Token::Word') ) {
$sub_names{"$children[1]"} = 1;
}
}
return \%sub_names;
}
sub _has_import_switches {
my $self = shift;
my $module_name = shift;
# If switches are being passed to import, we can't guess as what is correct
# here.
#
# Getopt::Long uses a leading colon rather than a dash. This overrides
# Exporter's defaults. You would normally assume that :config is an export
# tag, but instead it's something entirely different.
#
# use Getopt::Long qw(:config no_ignore_case bundling);
#
# We will leave this case as broken for the time being. I'm not sure how
# common that invocation is.
if ( exists $self->found_imports->{$module_name}
&& any { $_ =~ m{^[\-]} }
@{ $self->found_imports->{$module_name} || [] } ) {
return 1;
}
return 0;
}
sub _is_used_fully_qualified {
my $self = shift;
my $module_name = shift;
# We could tighten this up and check that the word following "::" is a sub
# which exists in that package.
#
# Module::function
# Module::->new
# isa => ArrayRef[Module::]
return 1 if $self->ppi_document->find(
sub {
(
$_[1]->isa('PPI::Token::Word')
&& (
$_[1]->content =~ m{\A${module_name}::[a-zA-Z0-9_]*\z}
|| ( $_[1]->content eq ${module_name}
&& $_[1]->snext_sibling eq '->' )
)
)
|| ( $_[1]->isa('PPI::Token::Symbol')
&& $_[1] =~ m{\A[&*\$\@\%]+${module_name}::[a-zA-Z0-9_]} );
}
);
# We could combine the regexes, but this is easy to read.
for my $key ( keys %{ $self->interpolated_symbols } ) {
# package level variable
return 1 if $key =~ m{\A[&*\$\@\%]+${module_name}::[a-zA-Z0-9_]+\z};
# function
return 1 if $key =~ m/\A${module_name}::[a-zA-Z0-9_]+\z/;
}
return 0;
}
sub _is_ignored {
my $self = shift;
my $element = shift;
( run in 2.137 seconds using v1.01-cache-2.11-cpan-524268b4103 )