blib/lib/Perl/Critic/Policy/ProhibitUsageSubs.pm

filter: Statementstmt 85.7% 12 / 14 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod n/a totaltotal 89.4% 17 / 19 CC 1 SCAR 0.6
CC
1
Cov
86%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
↑ Summary
1 package Perl::Critic::Policy::ProhibitUsageSubs;
2 $Perl::Critic::Policy::ProhibitUsageSubs::VERSION = '1.000';
3 # ABSTRACT: Document the interface once, in POD, and let Pod::Usage print it.
4  
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use 5.014;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶use re '/aa';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 0 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=2.6
13  
14 use Perl::Critic::Utils qw{ :severities :classification :ppi };
15 use parent qw{Perl::Critic::Policy};
16  
17  
18 Readonly::Scalar my $DESC => q{usage() subs duplicate documentation that belongs in POD};
19 Readonly::Scalar my $EXPL => q{Document the interface in POD and print it with Pod::Usage::pod2usage()};
20  
21  
22 sub supported_parameters {
23 return ({
24 name => 'sub_names',
25 description => 'Subroutine names that should be POD instead.',
26 default_string => 'usage _usage print_usage usage_message help',
27 behavior => 'string list',
28 });
29 }
30  
31 sub default_severity { return $SEVERITY_MEDIUM }
32 sub default_themes { return qw(maintenance documentation) }
33 sub applies_to { return 'PPI::Statement::Sub' }
34  
35  
36 sub violates {
37 my ( $self, $elem, undef ) = @_;
38  
39 # A forward declaration has no body, so it isn't a duplicate of the POD yet.
40 return if $elem->forward();
41  
42 my $name = $elem->name();
43 return if !defined $name;
44  
45 # Fully qualified names count too; it is the last segment that matters.
46 $name =~ s/\A .* :://xms;
47 return if !$self->{_sub_names}{$name};
48  
49 return $self->violation( $DESC, $EXPL, $elem );
50 }
51  
52 1;
53  
54 __END__
↑ Summary