lib/Perl/Critic/Policy/Modules/ProhibitAutomaticExportation.pm

filter: Statementstmt 67.2% 37 / 55 Branchbran 16.6% 3 / 18 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 70.0% 14 / 20 Podpod 80.0% 4 / 5 totaltotal 56.3% 58 / 103 CC 11 SCAR 16.3
CC
11
Cov
53%
__ANON__
12.0
_our_export
12.0
_vars_export
12.0
CRAP 5.1
« lib/Perl/Critic/Statistics.pm ↑ Summary lib/Perl/Critic/UserProfile.pm »
1 package Perl::Critic::Policy::Modules::ProhibitAutomaticExportation;
2  
3 40 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 40 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 40 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 40 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 40 ▶use Perl::Critic::Utils qw{ :severities };
Subroutine BEGIN: called CC=1 SCAR=0.0
9 40 ▶use List::SomeUtils qw(any);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 40 ▶use parent 'Perl::Critic::Policy';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 40 our $VERSION = '1.156';
13  
14 #-----------------------------------------------------------------------------
15  
16 40 Readonly::Scalar my $DESC => q{Symbols are exported by default};
17 40 Readonly::Scalar my $EXPL => q{Use '@EXPORT_OK' or '%EXPORT_TAGS' instead}; ## no critic (RequireInterpolation)
18  
19 #-----------------------------------------------------------------------------
20  
21 90 ▶sub supported_parameters { return () }
Subroutine supported_parameters: called CC=1 SCAR=0.0
Pod undocumented
22 74 ▶sub default_severity { return $SEVERITY_HIGH }
Subroutine default_severity: called CC=1 SCAR=0.0
Pod documented
23 73 ▶sub default_themes { return qw( core bugs ) }
Subroutine default_themes: called CC=1 SCAR=0.0
Pod documented
24 33 ▶sub applies_to { return 'PPI::Document' }
Subroutine applies_to: called CC=1 SCAR=0.0
Pod documented
25  
26 #-----------------------------------------------------------------------------
27  
28 33 ▶sub violates {
Subroutine violates: called CC=3 SCAR=15.1
Pod documented
29 33 my ( $self, undef, $doc ) = @_;
30  
31 33 ▶ if ( _uses_exporter($doc) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (_uses_exporter($doc)) 0 33 33
32 0 ▶ if ( my $exp = _has_exports($doc) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $exp = _has_exports($doc)) 0 0 0
33 0 return $self->violation( $DESC, $EXPL, $exp );
34 }
35 }
36 33 return; #ok
37 }
38  
39 #-----------------------------------------------------------------------------
40  
41 33 ▶sub _uses_exporter {
Subroutine _uses_exporter: called CC=2 SCAR=6.9
42 33 my ($doc) = @_;
43  
44 33 my $includes_ref = $doc->find('PPI::Statement::Include');
45 33 ▶ return if not $includes_ref;
Branch: 1 branch
BranchTrueFalseTotal
unless $includes_ref 3 30 33
46  
47 # This covers both C<use Exporter;> and C<use parent 'Exporter';>
48 30 ▶ return any { m/ \b Exporter \b/xms } @{ $includes_ref };
Subroutine __ANON__: called CC=1 SCAR=0.0
49 }
50  
51 #------------------
52  
53 0 ▶sub _has_exports {
Subroutine _has_exports: not called CC=1 SCAR=6.9
54 0 my ($doc) = @_;
55  
56 my $wanted =
57 0 ▶ sub { _our_export(@_) or _vars_export(@_) or _package_export(@_) };
Subroutine __ANON__: not called CC=3 SCAR=24.8
Branch: 1 branch
BranchTrueFalseTotal
_our_export(@_) or _vars_export(@_) or _package_export(@_) 0 0 0
Condition0%0/3
_our_export(@_) or _vars_export(@_)
l!l&&r!l&&!r
000
MC/DC0%0/2
_our_export(@_) or _vars_export(@_)
_our_export(@_) _vars_export(@_)
Truth table0%0/3
A or B
A= _our_export(@_)B= _vars_export(@_)
ABresult
1X1
011
000
58  
59 0 return $doc->find_first( $wanted );
60 }
61  
62 #------------------
63  
64 0 ▶sub _our_export {
Subroutine _our_export: not called CC=3 SCAR=24.8
65 0 my (undef, $elem) = @_;
66  
67 0 ▶ $elem->isa('PPI::Statement::Variable') or return 0;
Branch: 1 branch
BranchTrueFalseTotal
$elem->isa("PPI::Statement::Variable") or return 0 0 0 0
68 0 ▶ $elem->type() eq 'our' or return 0;
Branch: 1 branch
BranchTrueFalseTotal
$elem->type eq "our" or return 0 0 0 0
69  
70 0 ▶ return any { $_ eq '@EXPORT' } $elem->variables(); ## no critic(RequireInterpolationOfMetachars)
Subroutine __ANON__: not called CC=1 SCAR=6.9
71 }
72  
73 #------------------
74  
75 0 ▶sub _vars_export {
Subroutine _vars_export: not called CC=3 SCAR=24.8
76 0 my (undef, $elem) = @_;
77  
78 0 ▶ $elem->isa('PPI::Statement::Include') or return 0;
Branch: 1 branch
BranchTrueFalseTotal
$elem->isa("PPI::Statement::Include") or return 0 0 0 0
79 0 ▶ $elem->pragma() eq 'vars' or return 0;
Branch: 1 branch
BranchTrueFalseTotal
$elem->pragma eq "vars" or return 0 0 0 0
80  
81 0 return $elem =~ m{ \@EXPORT \b }xms; #Crude, but usually works
82 }
83  
84 #------------------
85  
86 0 ▶sub _package_export {
Subroutine _package_export: not called CC=2 SCAR=17.9
87 0 my (undef, $elem) = @_;
88  
89 0 ▶ $elem->isa('PPI::Token::Symbol') or return 0;
Branch: 1 branch
BranchTrueFalseTotal
$elem->isa("PPI::Token::Symbol") or return 0 0 0 0
90  
91 0 return $elem =~ m{ \A \@ \S+ ::EXPORT \z }xms;
92 #TODO: ensure that it is in _this_ package!
93 }
94  
95 40 1;
96  
97 __END__
« lib/Perl/Critic/Statistics.pm ↑ Summary lib/Perl/Critic/UserProfile.pm »