Policy/Moose/RequireMakeImmutable.pm

filter: Statementstmt 96.9% 64 / 66 Branchbran 62.5% 25 / 40 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 93.3% 14 / 15 Podpod 83.3% 5 / 6 totaltotal 85.0% 108 / 127 CC 22 SCAR 26.0
CC
22
Cov
84%
__ANON__
24.1
_is_interesting_document
3.0
violates
2.0
CRAP 13.5
↑ Summary Policy/Moose/RequireCleanNamespace.pm »
1 package Perl::Critic::Policy::Moose::RequireMakeImmutable;
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 => 'No call was made to make_immutable().';
17 1 Readonly::Scalar my $EXPLANATION =>
18 q<Moose can't optimize itself if classes remain mutable.>;
19  
20 4 ▶sub supported_parameters {
Subroutine supported_parameters: called CC=1 SCAR=0.0
Pod undocumented
21 return (
22 {
23 4 name => 'equivalent_modules',
24 description =>
25 q<The additional modules to treat as equivalent to "Moose".>,
26 default_string => 'Moose',
27 behavior => 'string list',
28 list_always_present_values => [qw< Moose >],
29 },
30 );
31 }
32  
33 2 ▶sub default_severity { return $SEVERITY_MEDIUM; }
Subroutine default_severity: called CC=1 SCAR=0.0
Pod documented
34 0 ▶sub default_themes { return qw( moose performance ); }
Subroutine default_themes: not called CC=1 SCAR=6.9
Pod documented
35 4 ▶sub applies_to { return 'PPI::Document' }
Subroutine applies_to: called CC=1 SCAR=0.0
Pod documented
36  
37 4 ▶sub prepare_to_scan_document {
Subroutine prepare_to_scan_document: called CC=1 SCAR=0.0
Pod documented
38 4 my ( $self, $document ) = @_;
39  
40 4 return $self->_is_interesting_document($document);
41 }
42  
43 4 ▶sub _is_interesting_document {
Subroutine _is_interesting_document: called CC=3 SCAR=11.1
44 4 my ( $self, $document ) = @_;
45  
46 4 foreach my $module ( keys %{ $self->{_equivalent_modules} } ) {
47 5 ▶ return $TRUE if $document->uses_module($module);
Branch: 1 branch
BranchTrueFalseTotal
if $document->uses_module($module) 4 1 5
48 }
49  
50 0 return $FALSE;
51 }
52  
53 4 ▶sub violates {
Subroutine violates: called CC=2 SCAR=7.1
Pod documented
54 4 my ( $self, undef, $document ) = @_;
55  
56 my $makes_immutable = $document->find_any(
57 155 ▶ sub {
Subroutine __ANON__: called CC=19 SCAR=31.8
58 155 my ( undef, $element ) = @_;
59  
60 155 ▶ return $FALSE if not is_ppi_generic_statement($element);
Branch: 1 branch
BranchTrueFalseTotal
unless is_ppi_generic_statement($element) 149 6 155
61  
62 6 my $current_token = $element->schild(0);
63 6 ▶ return $FALSE if not $current_token;
Branch: 1 branch
BranchTrueFalseTotal
unless $current_token 0 6 6
64 6 ▶ return $FALSE if not $current_token->isa('PPI::Token::Word');
Branch: 1 branch
BranchTrueFalseTotal
unless $current_token->isa("PPI::Token::Word") 0 6 6
65 6 ▶ return $FALSE if $current_token->content() ne '__PACKAGE__';
Branch: 1 branch
BranchTrueFalseTotal
if $current_token->content ne "__PACKAGE__" 4 2 6
66  
67 2 $current_token = $current_token->snext_sibling();
68 2 ▶ return $FALSE if not $current_token;
Branch: 1 branch
BranchTrueFalseTotal
unless $current_token 0 2 2
69 2 ▶ return $FALSE if not $current_token->isa('PPI::Token::Operator');
Branch: 1 branch
BranchTrueFalseTotal
unless $current_token->isa("PPI::Token::Operator") 0 2 2
70 2 ▶ return $FALSE if $current_token->content() ne '->';
Branch: 1 branch
BranchTrueFalseTotal
if $current_token->content ne "->" 0 2 2
71  
72 2 $current_token = $current_token->snext_sibling();
73 2 ▶ return $FALSE if not $current_token;
Branch: 1 branch
BranchTrueFalseTotal
unless $current_token 0 2 2
74 2 ▶ return $FALSE if not $current_token->isa('PPI::Token::Word');
Branch: 1 branch
BranchTrueFalseTotal
unless $current_token->isa("PPI::Token::Word") 0 2 2
75 2 ▶ return $FALSE if $current_token->content() ne 'meta';
Branch: 1 branch
BranchTrueFalseTotal
if $current_token->content ne "meta" 0 2 2
76  
77 2 $current_token = $current_token->snext_sibling();
78 2 ▶ return $FALSE if not $current_token;
Branch: 1 branch
BranchTrueFalseTotal
unless $current_token 0 2 2
79 2 ▶ if ( $current_token->isa('PPI::Structure::List') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($current_token->isa("PPI::Structure::List")) 1 1 2
80 1 $current_token = $current_token->snext_sibling();
81 1 ▶ return $FALSE if not $current_token;
Branch: 1 branch
BranchTrueFalseTotal
unless $current_token 0 1 1
82 }
83  
84 2 ▶ return $FALSE if not $current_token->isa('PPI::Token::Operator');
Branch: 1 branch
BranchTrueFalseTotal
unless $current_token->isa("PPI::Token::Operator") 0 2 2
85 2 ▶ return $FALSE if $current_token->content() ne '->';
Branch: 1 branch
BranchTrueFalseTotal
if $current_token->content ne "->" 0 2 2
86  
87 2 $current_token = $current_token->snext_sibling();
88 2 ▶ return $FALSE if not $current_token;
Branch: 1 branch
BranchTrueFalseTotal
unless $current_token 0 2 2
89 2 ▶ return $FALSE if not $current_token->isa('PPI::Token::Word');
Branch: 1 branch
BranchTrueFalseTotal
unless $current_token->isa("PPI::Token::Word") 0 2 2
90 2 ▶ return $FALSE if $current_token->content() ne 'make_immutable';
Branch: 1 branch
BranchTrueFalseTotal
if $current_token->content ne "make_immutable" 0 2 2
91  
92 2 return $TRUE;
93 }
94 4 );
95  
96 4 ▶ return if $makes_immutable;
Branch: 1 branch
BranchTrueFalseTotal
if $makes_immutable 2 2 4
97 2 return $self->violation( $DESCRIPTION, $EXPLANATION, $document );
98 }
99  
100 1 1;
101  
102 # ABSTRACT: Ensure that you've made your Moose code fast
103  
104 __END__
↑ Summary Policy/Moose/RequireCleanNamespace.pm »