| 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
| |||||||||||||||||||||||||||||
| 32 | 0 | ▶ | if ( my $exp = _has_exports($doc) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
Condition0%0/3
_our_export(@_) or _vars_export(@_)
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(@_)
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 68 | 0 | ▶ | $elem->type() eq 'our' or return 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 79 | 0 | ▶ | $elem->pragma() eq 'vars' or return 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||