| 1 | package Perl::Critic::Policy::Community::POSIXImports; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Perl::Critic::Utils qw(:severities :classification :ppi); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use parent 'Perl::Critic::Policy'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | our $VERSION = 'v1.0.4'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use constant DESC => 'Using POSIX.pm without an explicit import list'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use constant EXPL => 'Using the POSIX module without specifying an import list results in importing hundreds of symbols. Import the functions or constants you want explicitly, or prevent the import with ().'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 4 | ▶ | sub supported_parameters { () } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
supported_parameters: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 2 | ▶ | sub default_severity { $SEVERITY_LOW } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
default_severity: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 0 | ▶ | sub default_themes { 'community' } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
default_themes: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 4 | ▶ | sub applies_to { 'PPI::Statement::Include' } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
applies_to: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 5 | ▶ | sub violates { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
violates: called CC=6 SCAR=19.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 5 | my ($self, $elem) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 5 | ▶ | return $self->violation(DESC, EXPL, $elem) if ($elem->type // '') eq 'use' | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%5/10
($elem->type // "") eq "use" and ($elem->module // "") eq "POSIX" and not $elem->arguments
($elem->type // "") eq "use" and ($elem->module // "") eq "POSIX"
$elem->type // ""
$elem->module // ""
MC/DC33%1/3
($elem->type // "") eq "use" and ($elem->module // "") eq "POSIX" and not $elem->arguments
$elem->type
$elem->module
not $elem->arguments
Truth table50%2/4
A and B and not(C)
A= $elem->typeB= $elem->moduleC= not $elem->arguments
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | and ($elem->module // '') eq 'POSIX' and !$elem->arguments; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 3 | return (); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | Perl::Critic::Policy::Community::POSIXImports - Don't use POSIX without | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | specifying an import list | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | The L<POSIX> module imports hundreds of symbols (functions and constants) by | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | default for backwards compatibility reasons. To avoid this, and to assist in | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | finding where functions have been imported from, specify the symbols you want | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | to import explicitly in the C<use> statement. Alternatively, specify an empty | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | import list with C<use POSIX ()> to avoid importing any symbols, and fully | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | qualify the functions or constants, such as C<POSIX::strftime>. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | use POSIX; # not ok | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | use POSIX (); # ok | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | use POSIX 'fcntl'; # ok | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | use POSIX qw(O_APPEND O_CREAT O_EXCL O_RDONLY O_RDWR O_WRONLY); # ok | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | =head1 AFFILIATION | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | This policy is part of L<Perl::Critic::Community>. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | =head1 CONFIGURATION | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | This policy is not configurable except for the standard options. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | Dan Book, C<dbook@cpan.org> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | Copyright 2015, Dan Book. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | This library is free software; you may redistribute it and/or modify it under | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | the terms of the Artistic License version 2.0. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | L<Perl::Critic> | ||||||||||||||||||||||||||||||||||||||||||||||||||