blib/lib/Perl/Critic/Policy/Moo/ProhibitMakeImmutable.pm

filter: Statementstmt 98.0% 49 / 50 Branchbran 72.7% 16 / 22 Conditioncond 50.0% 18 / 36 MC/DCmcdc 22.2% 4 / 18 Subroutinesub 92.3% 12 / 13 Podpod 80.0% 4 / 5 totaltotal 71.5% 103 / 144 CC 24 SCAR 25.1
CC
24
Cov
77%
violates
24.6
_find_package
6.0
__ANON__
5.1
CRAP 12.3
↑ Summary
1 package Perl::Critic::Policy::Moo::ProhibitMakeImmutable;
2 1 ▶use 5.008001;
Subroutine BEGIN: called CC=1 SCAR=0.0
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 our $VERSION = '0.06';
6  
7 1 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Perl::Critic::Utils qw{ :severities :classification :ppi };
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶use base 'Perl::Critic::Policy';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 Readonly::Scalar my $DESC => q{Moo class should not call ->make_immutable};
13 1 Readonly::Scalar my $EXPL => q{When migrating from Moose to Moo it is easy to leave in __PACKAGE__->meta->make_immutable; statements which will cause Moose to be loaded and a metaclass created};
14  
15 6 ▶sub supported_parameters { return() }
Subroutine supported_parameters: called CC=1 SCAR=0.0
Pod undocumented
16 2 ▶sub default_severity { return $SEVERITY_MEDIUM }
Subroutine default_severity: called CC=1 SCAR=0.0
Pod documented
17 0 ▶sub default_themes { return qw( performance ) }
Subroutine default_themes: not called CC=1 SCAR=6.9
Pod documented
18 6 ▶sub applies_to { return 'PPI::Token::Word' }
Subroutine applies_to: called CC=1 SCAR=0.0
Pod documented
19  
20 59 ▶sub violates {
Subroutine violates: called CC=15 SCAR=32.0
Pod documented
21 59 my ($self, $start_word, $doc) = @_;
22  
23 59 ▶ return unless $start_word->content() eq '__PACKAGE__';
Branch: 1 branch
BranchTrueFalseTotal
unless $start_word->content eq "__PACKAGE__" 53 6 59
24 6 my $element = $start_word;
25  
26 6 $element = $element->snext_sibling();
27 6 ▶ return unless $element
Branch: 1 branch
BranchTrueFalseTotal
unless $element and $element->isa("PPI::Token::Operator") and $element->content eq "->" 0 6 6
Condition33%2/6
$element and $element->isa("PPI::Token::Operator") and $element->content eq "->"
!ll&&!rl&&r
006
$element and $element->isa("PPI::Token::Operator")
!ll&&!rl&&r
006
MC/DC0%0/3
$element and $element->isa("PPI::Token::Operator") and $element->content eq "->"
$element $element->isa("PPI::Token::Operator") $element->content eq "->"
Truth table25%1/4
A and B and C
A= $elementB= $element->isa("PPI::Token::Operator")C= $element->content eq "->"
ABCresult
0XX0
10X0
1100
1111
28 and $element->isa('PPI::Token::Operator')
29 and $element->content() eq '->';
30  
31 6 $element = $element->snext_sibling();
32 6 ▶ return unless $element
Branch: 1 branch
BranchTrueFalseTotal
unless $element and $element->isa("PPI::Token::Word") and $element->content eq "meta" 0 6 6
Condition33%2/6
$element and $element->isa("PPI::Token::Word") and $element->content eq "meta"
!ll&&!rl&&r
006
$element and $element->isa("PPI::Token::Word")
!ll&&!rl&&r
006
MC/DC0%0/3
$element and $element->isa("PPI::Token::Word") and $element->content eq "meta"
$element $element->isa("PPI::Token::Word") $element->content eq "meta"
Truth table25%1/4
A and B and C
A= $elementB= $element->isa("PPI::Token::Word")C= $element->content eq "meta"
ABCresult
0XX0
10X0
1100
1111
33 and $element->isa('PPI::Token::Word')
34 and $element->content() eq 'meta';
35  
36 6 $element = $element->snext_sibling();
37 6 ▶ return unless $element
Branch: 1 branch
BranchTrueFalseTotal
unless $element and $element->isa("PPI::Token::Operator") and $element->content eq "->" 0 6 6
Condition33%2/6
$element and $element->isa("PPI::Token::Operator") and $element->content eq "->"
!ll&&!rl&&r
006
$element and $element->isa("PPI::Token::Operator")
!ll&&!rl&&r
006
MC/DC0%0/3
$element and $element->isa("PPI::Token::Operator") and $element->content eq "->"
$element $element->isa("PPI::Token::Operator") $element->content eq "->"
Truth table25%1/4
A and B and C
A= $elementB= $element->isa("PPI::Token::Operator")C= $element->content eq "->"
ABCresult
0XX0
10X0
1100
1111
38 and $element->isa('PPI::Token::Operator')
39 and $element->content() eq '->';
40  
41 6 $element = $element->snext_sibling();
42 6 ▶ return unless $element
Branch: 1 branch
BranchTrueFalseTotal
unless $element and $element->isa("PPI::Token::Word") and $element->content eq "make_immutable" 0 6 6
Condition33%2/6
$element and $element->isa("PPI::Token::Word") and $element->content eq "make_immutable"
!ll&&!rl&&r
006
$element and $element->isa("PPI::Token::Word")
!ll&&!rl&&r
006
MC/DC0%0/3
$element and $element->isa("PPI::Token::Word") and $element->content eq "make_immutable"
$element $element->isa("PPI::Token::Word") $element->content eq "make_immutable"
Truth table25%1/4
A and B and C
A= $elementB= $element->isa("PPI::Token::Word")C= $element->content eq "make_immutable"
ABCresult
0XX0
10X0
1100
1111
43 and $element->isa('PPI::Token::Word')
44 and $element->content() eq 'make_immutable';
45  
46 6 my $package = _find_package( $start_word );
47  
48 277 ▶ my $included = $doc->find_any(sub{
Subroutine __ANON__: called CC=5 SCAR=16.3
49 277 ▶ $_[1]->isa('PPI::Statement::Include')
Branch: 1 branch
BranchTrueFalseTotal
$_[1]->isa("PPI::Statement::Include") and defined $_[1]->module and $_[1]->module eq "Moo" and $_[1]->type eq "use" and _find_package($_[1]) eq $package 8 269 277
Condition77%7/9
$_[1]->isa("PPI::Statement::Include") and defined $_[1]->module and $_[1]->module eq "Moo" and $_[1]->type eq "use"
!ll&&!rl&&r
26908
$_[1]->isa("PPI::Statement::Include") and defined $_[1]->module and $_[1]->module eq "Moo"
!ll&&!rl&&r
26188
$_[1]->isa("PPI::Statement::Include") and defined $_[1]->module
!ll&&!rl&&r
261016
MC/DC50%2/4
$_[1]->isa("PPI::Statement::Include") and defined $_[1]->module and $_[1]->module eq "Moo" and $_[1]->type eq "use"
$_[1]->isa("PPI::Statement::Include") defined $_[1]->module $_[1]->module eq "Moo" $_[1]->type eq "use"
Truth table60%3/5
A and B and C and D
A= $_[1]->isa("PPI::Statement::Include")B= defined $_[1]->moduleC= $_[1]->module eq "Moo"D= $_[1]->type eq "use"
ABCDresult
0XXX0
10XX0
110X0
11100
11111
50 and
51 defined( $_[1]->module() )
52 and
53 $_[1]->module() eq 'Moo'
54 and
55 $_[1]->type() eq 'use'
56 and
57 _find_package( $_[1] ) eq $package
58 6 });
59  
60 6 ▶ return if !$included;
Branch: 1 branch
BranchTrueFalseTotal
unless $included 4 2 6
61  
62 2 return $self->violation( $DESC, $EXPL, $start_word );
63 }
64  
65 14 ▶sub _find_package {
Subroutine _find_package: called CC=6 SCAR=18.0
66 14 my ($element) = @_;
67  
68 14 my $original = $element;
69  
70 14 ▶ while ($element) {
Branch: 1 branch
BranchTrueFalseTotal
if ($element) 43 3 46
71 43 ▶ if ($element->isa('PPI::Statement::Package')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($element->isa("PPI::Statement::Package")) 11 32 43
72 # If this package statements is a block package, meaning: package { # stuff in package }
73 # then if we're a descendant of it its our package.
74 11 ▶ return $element->namespace() if $element->ancestor_of( $original );
Branch: 1 branch
BranchTrueFalseTotal
if $element->ancestor_of($original) 0 11 11
75  
76 # If we've hit a non-block package then thats our package.
77 11 my $blocks = $element->find_any('PPI::Structure::Block');
78 11 ▶ return $element->namespace() if !$blocks;
Branch: 1 branch
BranchTrueFalseTotal
unless $blocks 11 0 11
79 }
80  
81 # Keep walking backwards until we match the above logic or we get to
82 # the document root (main).
83 32 ▶ $element = $element->sprevious_sibling() || $element->parent();
Condition100%3/3
$element->sprevious_sibling || $element->parent
l!l&&r!l&&!r
18113
MC/DC100%2/2
$element->sprevious_sibling || $element->parent
$element->sprevious_sibling $element->parent
Truth table100%3/3
A || B
A= $element->sprevious_siblingB= $element->parent
ABresult
1X1
011
000
84 }
85  
86 3 return 'main';
87 }
88  
89 1 1;
90 __END__
↑ Summary