| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 6 | my $element = $start_word; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 6 | $element = $element->snext_sibling(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 6 | ▶ | return unless $element | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$element and $element->isa("PPI::Token::Operator") and $element->content eq "->"
$element and $element->isa("PPI::Token::Operator")
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 "->"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%2/6
$element and $element->isa("PPI::Token::Word") and $element->content eq "meta"
$element and $element->isa("PPI::Token::Word")
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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%2/6
$element and $element->isa("PPI::Token::Operator") and $element->content eq "->"
$element and $element->isa("PPI::Token::Operator")
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 "->"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%2/6
$element and $element->isa("PPI::Token::Word") and $element->content eq "make_immutable"
$element and $element->isa("PPI::Token::Word")
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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition77%7/9
$_[1]->isa("PPI::Statement::Include") and defined $_[1]->module and $_[1]->module eq "Moo" and $_[1]->type eq "use"
$_[1]->isa("PPI::Statement::Include") and defined $_[1]->module and $_[1]->module eq "Moo"
$_[1]->isa("PPI::Statement::Include") and defined $_[1]->module
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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 43 | ▶ | if ($element->isa('PPI::Statement::Package')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 3 | return 'main'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||