App-perlimports
view release on metacpan or search on metacpan
lib/App/perlimports/Document.pm view on Meta::CPAN
#
# becomes:
#
# {
# Carp => undef,
# 'Data::Dumper' => ['Dumper'],
# POSIX => [],
# }
#
# The name is a bit of a misnomer. It starts out as a list of original imports,
# but with each include that gets processed, this list also gets updated. We do
# this so that we can keep track of what previous modules are really importing.
# Might not be bad to rename this.
sub _build_original_imports {
my $self = shift;
# We're missing requires which could be followed by an import.
my $found = $self->ppi_document->find(
sub {
$_[1]->isa('PPI::Statement::Include')
script/perlimports view on Meta::CPAN
The C<--no-padding> arg allows you to disable the additional padding inside
parentheses.
# --no-padding
use Foo qw(bar baz);
=head2 --[no-]tidy-whitespace
C<--tidy-whitespace> is enabled by default. This means that use statements will
be updated even when the only change is in whitespace. Disabling this can help
reduce the churn involved when running C<perlimports>, especially if the codebase
does not have automated tidying.
If you have changed from C<--padding> to C<--no-padding> or vice versa, you'll
probably want to ensure that C<--tidy-whitespace> has also been enabled so that
you can see the whitespace changes.
=head2 --libs
A comma separated list of module directories which are not in your C<@INC>
script/perlimports view on Meta::CPAN
You are encouraged to make this tool part of your automated tidying workflow.
Some guidance on how to configure this follows.
=head2 VIM
If you're a C<vim> user, you can pipe your import statements to perlimports directly.
:vnoremap <silent> im :!perlimports --read-stdin --filename '%:p'<CR>
The above statement will allow you to visually select one or more lines of code
and have them updated in place by C<perlimports>. Once you have selected the
code enter C<im> to have your imports (re)formatted.
=head2 VIM and ALE
If you use ALE with vim, you can add something like this to your C<vim>
configuration. Note that this function will save your buffer before running
C<perlimports>.
function! Perlimports(buffer) abort
write
eq_or_diff(
$doc->tidied_document,
$expected,
'verbose is not inserted'
);
is_deeply(
$doc->original_imports,
{ Carp => ['croak'] },
'original imports updated'
);
};
done_testing();
( run in 0.419 second using v1.01-cache-2.11-cpan-05444aca049 )