« Policy/Modules/RequireExplicitInclusion.pm
↑ Summary
Policy/Subroutines/ProhibitCallsToUnexportedSubs.pm »
| 1 | package Perl::Critic::Policy::Subroutines::ProhibitExportingUndeclaredSubs; | ||||||||||||
| 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 | 1 | ▶ | use Carp qw(croak); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | 1 | ▶ | use English qw(-no_match_vars); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | 1 | ▶ | use base 'Perl::Critic::Policy'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | |||||||||||||
| 9 | 1 | ▶ | use Perl::Critic::Utils qw( | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | :severities | ||||||||||||
| 11 | &hashify | ||||||||||||
| 12 | &policy_short_name | ||||||||||||
| 13 | 1 | ); | |||||||||||
| 14 | |||||||||||||
| 15 | 1 | ▶ | use Perl::Critic::StricterSubs::Utils qw( | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 16 | &find_declared_constant_names | ||||||||||||
| 17 | &find_declared_subroutine_names | ||||||||||||
| 18 | &find_exported_subroutine_names | ||||||||||||
| 19 | 1 | ); | |||||||||||
| 20 | |||||||||||||
| 21 | #----------------------------------------------------------------------------- | ||||||||||||
| 22 | |||||||||||||
| 23 | 1 | our $VERSION = '0.08'; | |||||||||||
| 24 | |||||||||||||
| 25 | #----------------------------------------------------------------------------- | ||||||||||||
| 26 | |||||||||||||
| 27 | 6 | ▶ | sub supported_parameters { return } | ||||||||||
|
Subroutine
supported_parameters: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 28 | 5 | ▶ | sub default_severity { return $SEVERITY_HIGH } | ||||||||||
|
Subroutine
default_severity: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 29 | 0 | ▶ | sub default_themes { return qw( strictersubs bugs ) } | ||||||||||
|
Subroutine
default_themes: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 30 | 6 | ▶ | sub applies_to { return 'PPI::Document' } | ||||||||||
|
Subroutine
applies_to: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 31 | |||||||||||||
| 32 | #----------------------------------------------------------------------------- | ||||||||||||
| 33 | |||||||||||||
| 34 | 6 | ▶ | sub violates { | ||||||||||
|
Subroutine
violates: called CC=6 SCAR=20.3
Pod
documented
| |||||||||||||
| 35 | 6 | my ($self, undef, $doc) = @_; | |||||||||||
| 36 | |||||||||||||
| 37 | 6 | my @exported_sub_names; | |||||||||||
| 38 | eval { | ||||||||||||
| 39 | 6 | @exported_sub_names = find_exported_subroutine_names( $doc ); | |||||||||||
| 40 | 6 | 1; | |||||||||||
| 41 | 6 | ▶ | } or do { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 42 | |||||||||||||
| 43 | 0 | ▶ | if ( $EVAL_ERROR =~ m/Found \s multiple/mxs ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 44 | 0 | my $pname = policy_short_name(__PACKAGE__); | |||||||||||
| 45 | 0 | ▶ | my $fname = $doc->filename() || 'unknown'; | ||||||||||
|
Condition0%0/2
$doc->filename || 'unknown'
MC/DC0%0/1
$doc->filename || 'unknown'
$doc->filename
Truth table0%0/2
A
A= $doc->filename
| |||||||||||||
| 46 | 0 | warn qq{$pname: $EVAL_ERROR in file "$fname"\n}; | |||||||||||
| 47 | 0 | return; | |||||||||||
| 48 | } | ||||||||||||
| 49 | |||||||||||||
| 50 | }; | ||||||||||||
| 51 | |||||||||||||
| 52 | 6 | my @declared_sub_names = find_declared_subroutine_names( $doc ); | |||||||||||
| 53 | 6 | my @declared_constants = find_declared_constant_names( $doc ); | |||||||||||
| 54 | 6 | my %declared_sub_names = hashify( @declared_sub_names, | |||||||||||
| 55 | @declared_constants ); | ||||||||||||
| 56 | |||||||||||||
| 57 | 6 | my @violations; | |||||||||||
| 58 | 6 | for my $sub_name ( @exported_sub_names ) { | |||||||||||
| 59 | 13 | ▶ | if ( not exists $declared_sub_names{ $sub_name } ){ | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 60 | 5 | my $desc = qq{Subroutine "$sub_name" is exported but not declared}; | |||||||||||
| 61 | 5 | my $expl = qq{Perhaps you forgot to define "$sub_name"}; | |||||||||||
| 62 | 5 | push @violations, $self->violation( $desc, $expl, $doc ); | |||||||||||
| 63 | } | ||||||||||||
| 64 | } | ||||||||||||
| 65 | |||||||||||||
| 66 | 6 | return @violations; | |||||||||||
| 67 | } | ||||||||||||
| 68 | |||||||||||||
| 69 | #----------------------------------------------------------------------------- | ||||||||||||
| 70 | |||||||||||||
| 71 | 1 | 1; | |||||||||||
| 72 | |||||||||||||
| 73 | __END__ | ||||||||||||