Policy/Moose/ProhibitNewMethod.pm

filter: Statementstmt 97.8% 46 / 47 Branchbran 100% 8 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 93.3% 14 / 15 Podpod 83.3% 5 / 6 totaltotal 96.0% 73 / 76 CC 8 SCAR 8.4
CC
8
Cov
98%
violates
5.0
_is_interesting_document
3.0
default_themes
2.0
CRAP 2.3
« Policy/Moose/ProhibitDESTROYMethod.pm ↑ Summary Moose.pm »
1 package Perl::Critic::Policy::Moose::ProhibitNewMethod;
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 namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 our $VERSION = '1.05';
8  
9 1 ▶use Readonly ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 ▶use Perl::Critic::Utils qw< :booleans :severities >;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Perl::Critic::Utils::PPI qw< is_ppi_generic_statement >;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 1 ▶use base 'Perl::Critic::Policy';
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 1 Readonly::Scalar my $DESCRIPTION =>
17 q<"new" method/subroutine declared in a Moose class.>;
18 1 Readonly::Scalar my $EXPLANATION =>
19 q<Use BUILDARGS and BUILD instead of writing your own constructor.>;
20  
21 6 ▶sub supported_parameters {
Subroutine supported_parameters: called CC=1 SCAR=0.0
Pod undocumented
22 return (
23 {
24 6 name => 'equivalent_modules',
25 description =>
26 q<The additional modules to treat as equivalent to "Moose", "Moose::Role", or "MooseX::Role::Parameterized".>,
27 default_string => 'Moose Moose::Role MooseX::Role::Parameterized',
28 behavior => 'string list',
29 list_always_present_values =>
30 [qw< Moose Moose::Role MooseX::Role::Parameterized >],
31 },
32 );
33 }
34  
35 3 ▶sub default_severity { return $SEVERITY_HIGH; }
Subroutine default_severity: called CC=1 SCAR=0.0
Pod documented
36 0 ▶sub default_themes { return qw< moose bugs >; }
Subroutine default_themes: not called CC=1 SCAR=6.9
Pod documented
37 6 ▶sub applies_to { return 'PPI::Document' }
Subroutine applies_to: called CC=1 SCAR=0.0
Pod documented
38  
39 6 ▶sub prepare_to_scan_document {
Subroutine prepare_to_scan_document: called CC=1 SCAR=0.0
Pod documented
40 6 my ( $self, $document ) = @_;
41  
42 6 return $self->_is_interesting_document($document);
43 }
44  
45 13 ▶sub _is_interesting_document {
Subroutine _is_interesting_document: called CC=3 SCAR=11.0
46 13 my ( $self, $document ) = @_;
47  
48 13 foreach my $module ( keys %{ $self->{_equivalent_modules} } ) {
49 27 ▶ return $TRUE if $document->uses_module($module);
Branch: 1 branch
BranchTrueFalseTotal
if $document->uses_module($module) 12 15 27
50 }
51  
52 1 return $FALSE;
53 }
54  
55 6 ▶sub violates {
Subroutine violates: called CC=5 SCAR=16.1
Pod documented
56 6 my ( $self, undef, $document ) = @_;
57  
58 6 my @violations;
59 6 foreach my $namespace ( $document->namespaces() ) {
60 SUBDOCUMENT:
61 7 foreach my $subdocument (
62 $document->subdocuments_for_namespace($namespace) ) {
63 next SUBDOCUMENT
64 7 ▶ if not $self->_is_interesting_document($subdocument);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_interesting_document($subdocument) 1 6 7
65  
66 6 ▶ if ( my $destructor
Branch: 1 branch
BranchTrueFalseTotal
if (my $destructor = $subdocument->find_first(\&Perl::Critic::Policy::Moose::ProhibitNewMethod::_is_constructor)) 3 3 6
67 = $subdocument->find_first( \&_is_constructor ) ) {
68 3 push
69 @violations,
70 $self->violation(
71 $DESCRIPTION, $EXPLANATION,
72 $destructor
73 );
74 }
75 }
76 }
77  
78 6 return @violations;
79 }
80  
81 131 ▶sub _is_constructor {
Subroutine _is_constructor: called CC=2 SCAR=6.9
82 131 my ( undef, $element ) = @_;
83  
84 131 ▶ return $FALSE if not $element->isa('PPI::Statement::Sub');
Branch: 1 branch
BranchTrueFalseTotal
unless $element->isa("PPI::Statement::Sub") 127 4 131
85  
86 4 return $element->name() eq 'new';
87 }
88  
89 1 1;
90  
91 # ABSTRACT: Don't override Moose's standard constructors.
92  
93 __END__
« Policy/Moose/ProhibitDESTROYMethod.pm ↑ Summary Moose.pm »