Perl::Critic::Policy::Modules::ProhibitPOSIXimport - don't import the whole of POSIX into a module


Perl-Critic-Pulp documentation  | view source Contained in the Perl-Critic-Pulp distribution.

Index


NAME

Top

Perl::Critic::Policy::Modules::ProhibitPOSIXimport - don't import the whole of POSIX into a module

DESCRIPTION

Top

This policy is part of the Perl::Critic::Pulp|Perl::Critic::Pulp addon. It asks you not to use POSIX with an import of all the symbols from that module if you're only using a few things.

    package Foo;
    use POSIX;    # bad

The aim is to save some memory, and maybe run a bit faster. A full POSIX import adds about 550 symbols to your module and that's about 30 to 40 kbytes in Perl 5.10 on a 32-bit system, or about 115 kbytes in Perl 5.8. If lots of modules do this it adds up.

As noted in the POSIX docs, the way it exports everything by default is an historical accident, not something to encourage.

Allowed Forms

A full import is allowed in package main, which is the top-level of a script etc, since in a script you want convenience rather than a bit of memory, at least initially.

    #!/usr/bin/perl
    use POSIX;        # ok

An import of no symbols is allowed and you simply add a POSIX:: qualifier to each call or constant. Qualifiers like this can make it clear where the function is coming from.

    package Foo;
    use POSIX (); # ok

    my $fd = POSIX::dup(0);
    if ($! == POSIX::ENOENT())

An import of an explicit set of functions and constants is allowed. This allows short names without the memory penalty of a full import. It can be error-prone to update the imports with what you actually use (see ProhibitCallsToUndeclaredSubs for some checking).

    package Foo;
    use POSIX qw(dup ENOENT); # ok
    ...
    my $fd = dup(0);

A full import is allowed in a module if there's 15 or more calls to POSIX module functions. This rule will probably change or be configurable in the future, but the intention is that a module making heavy use of POSIX shouldn't be burdened by a POSIX:: on every call or maintaining a list of explicit imports.

    package Foo;
    use POSIX;         # ok
    ...
    tzset(); dup(1)... # 15 or more calls to POSIX stuff

Disabling

If you don't care this sort of thing you can always disable ProhibitPOSIXimport from your .perlcriticrc in the usual way (see CONFIGURATION in Perl::Critic),

    [-Modules::ProhibitPOSIXimport]

SEE ALSO

Top

POSIX, Perl::Critic::Pulp, Perl::Critic, Perl::Critic::Policy::Subroutines::ProhibitCallsToUndeclaredSubs

HOME PAGE

Top

http://user42.tuxfamily.org/perl-critic-pulp/index.html

COPYRIGHT

Top


Perl-Critic-Pulp documentation  | view source Contained in the Perl-Critic-Pulp distribution.