NAME

App::perlimports - Make implicit imports explicit

VERSION

version 0.000004

SYNOPSIS

Update a file in place. (Make sure you can revert the file if you need to.)

perlimports --filename test-data/foo.pl --inplace-edit

If some of your imported modules are in local directories, you can give some hints as to where to find them:

perlimports --filename test-data/foo.pl --inplace-edit --libs t/lib,/some/dir/lib

Redirect output to a new file:

perlimports --filename test-data/foo.pl > foo.new.pl

VIM

If you're a 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 perlimports. Once you have selected the code enter im to have your imports (re)formatted.

MOTIVATION

Many Perl modules helpfully export functions and variables by default. These provide handy shortcuts when you're writing a quick or small script, but they can quickly become a maintenance burden as code grows organically. When code increases in complexity, it leads to greater costs in terms of development time. Conversely, reducing code complexity can speed up development. This tool aims to reduce complexity to further this goal.

While importing symbols by default or using export tags provides a convenient shorthand for getting work done, this shorthand requires the developer to retain knowledge of these defaults and tags in order to understand the code. perlimports aims to allow you to develop your code as you see fit, while still giving you a viable option of tidying your imports automatically. In much the same way as you might use perltidy to format your code, you can now automate the process of making your imports easier to understand. Let's look at some examples.

DESCRIPTION

This distribution provides the perlimports binary, which aims to automate the cleanup and maintenance of Perl import statements.

CAVEATS

There are lots of shenanigans that Perl modules can get up to. This code will not find exports for all of those cases, but it should only attempt to rewrite imports which it knows how to handle. Please file a bug report in all other cases.

SEE ALSO

Perl::Critic::Policy::TooMuchCode::ProhibitUnusedImport, Perl::Critic::Policy::TooMuchCode::ProhibitUnusedInclude and Perl::Critic::Policy::TooMuchCode::ProhibitUnusedConstant

AUTHOR

Olaf Alders olaf@wundercounter.com

COPYRIGHT AND LICENSE

This software is copyright (c) 2020 by Olaf Alders.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.