The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

TooMuchCode::ProhibitUnusedImport -- Find unused imports

DESCRIPTION

An "Unused Import" is usually a subroutine name imported by a use statement. For example, the word Dumper in the following statement:

    use Foo qw( baz );

The word baz can be removed if it is not mentioned in the rest of this program.

Conventionally, this policy looks only for the use statement with a qw() operator at the end. This syntax is easier to deal with. It also works with the usage of Importer module -- as long as a qw() is there at the end:

    use Importer 'Foo' => qw( baz );

This may be adjusted to be a bit smarter, but it is a clear convention in the beginning.

Modules which will be ignored, generally because the args of import do not mean the symbols to be imported.

    [TooMuchCode::ProhibitUnusedImport]
    ignored_modules = Git::Sub Regexp::Common

Moose Types

When importing types from a Moose type library, you may run into the following situation:

    use My::Type::Library::Numeric qw( PositiveInt );

    my $foo = 'bar';
    my $ok  = is_PositiveInt($foo);

In this case, My::Type::Library::Numeric exports is_PositiveInt as well as PositiveInt. Even though PositiveInt has not specifically been called by the code, it should be considered as being used. In order to allow for this case, you can specify class names of Moose-like type libraries which you intend to import from.

A similar case exists for coercions:

    use My::Type::Library::String qw( LowerCaseStr );
    my $foo   = 'Bar';
    my $lower = to_LowerCaseStr($foo);

In the above case, LowerCaseStr has not specifically been called by the code, but it should be considered as being used.

The imports of is_* and to_* from the following modules be handled by default:

    * MooseX::Types::Moose
    * MooseX::Types::Common::Numeric
    * MooseX::Types::Common::String

You can configure this behaviour by adding more modules to the list:

    [TooMuchCode::ProhibitUnusedImport]
    moose_type_modules = My::Type::Library::Numeric My::Type::Library::String