Perl::...import(3pm)
π NAME π
Perl::Critic::Policy::Modules::ProhibitPOSIXimport(3pm) β bestie, this is the policy that says: don't import the whole of POSIX into a module. π
π¦ DESCRIPTION π¦
Okay so real talk: this policy is part of the Perl::Critic::Pulp add-on. It's got one job and it's giving protective-bestie energy β 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. And if lots of modules do this?? bestie, it adds up. π
As noted in the POSIX module docs, the way it exports everything by default is an historical accident, not something to encourage. periodt. β
π Allowed Forms π
Not everything is a crime, bestie β let's run the vibe check on what's actually fine:
- 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 then 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. However it can be error-prone to update the imports with what you actually use (see
ProhibitCallsToUndeclaredSubsfor 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
POSIXmodule functions. This rule might change or be configurable in the future, but the intention is that a module making heavy use ofPOSIXshouldn't be burdened by aPOSIX::on every call or by 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 π₯
POSIXPerl::Critic::PulpPerl::CriticPerl::Critic::Policy::Subroutines::ProhibitCallsToUndeclaredSubs
π HOME PAGE π
<http://user42.tuxfamily.org/perl-critic-pulp/index.html>
π COPYRIGHT π
Copyright 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2019, 2021 Kevin Ryde
Perl-Critic-Pulp is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version.
Perl-Critic-Pulp is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with Perl-Critic-Pulp. If not, see <http://www.gnu.org/licenses/>.
and that's the whole page, bestie π§ this one came out of the User Contributed Perl Documentation, rendered by perl v5.40.1 on 2025-10-21 β go forth and stop importing all of POSIX, ily ππΈ
π¦ where this page comes from
- ubuntu resolute: libperl-critic-pulp-perl 100-1 Β· GPL-3.0-or-later
- ubuntu stonking: libperl-critic-pulp-perl 100-1 Β· GPL-3.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms