Policy/Moose/ProhibitMultipleWiths.pm

filter: Statementstmt 98.1% 54 / 55 Branchbran 81.2% 13 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 93.3% 14 / 15 Podpod 83.3% 5 / 6 totaltotal 93.4% 86 / 92 CC 12 SCAR 11.7
CC
12
Cov
94%
violates
6.0
_is_with_statement
5.2
_is_interesting_document
3.0
CRAP 3.2
« Policy/Moose/RequireCleanNamespace.pm ↑ Summary Policy/Moose/ProhibitLazyBuild.pm »
1 package Perl::Critic::Policy::Moose::ProhibitMultipleWiths;
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 $EMPTY >;
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 => 'Multiple calls to with() were made.';
17 1 Readonly::Scalar my $EXPLANATION =>
18 q<Roles cannot protect against name conflicts if they are not composed.>;
19  
20 13 ▶sub supported_parameters {
Subroutine supported_parameters: called CC=1 SCAR=0.0
Pod undocumented
21 return (
22 {
23 13 name => 'equivalent_modules',
24 description =>
25 q<The additional modules to treat as equivalent to "Moose", "Moose::Role", or "MooseX::Role::Parameterized".>,
26 default_string => 'Moose Moose::Role MooseX::Role::Parameterized',
27 behavior => 'string list',
28 list_always_present_values =>
29 [qw< Moose Moose::Role MooseX::Role::Parameterized >],
30 },
31 );
32 }
33  
34 5 ▶sub default_severity { return $SEVERITY_HIGH; }
Subroutine default_severity: called CC=1 SCAR=0.0
Pod documented
35 0 ▶sub default_themes { return qw( bugs moose roles ); }
Subroutine default_themes: not called CC=1 SCAR=6.9
Pod documented
36 12 ▶sub applies_to { return 'PPI::Document' }
Subroutine applies_to: called CC=1 SCAR=0.0
Pod documented
37  
38 13 ▶sub prepare_to_scan_document {
Subroutine prepare_to_scan_document: called CC=1 SCAR=0.0
Pod documented
39 13 my ( $self, $document ) = @_;
40  
41 13 return $self->_is_interesting_document($document);
42 }
43  
44 28 ▶sub _is_interesting_document {
Subroutine _is_interesting_document: called CC=3 SCAR=11.0
45 28 my ( $self, $document ) = @_;
46  
47 28 foreach my $module ( keys %{ $self->{_equivalent_modules} } ) {
48 61 ▶ return $TRUE if $document->uses_module($module);
Branch: 1 branch
BranchTrueFalseTotal
if $document->uses_module($module) 26 35 61
49 }
50  
51 2 return $FALSE;
52 }
53  
54 12 ▶sub violates {
Subroutine violates: called CC=6 SCAR=17.9
Pod documented
55 12 my ( $self, undef, $document ) = @_;
56  
57 12 my @violations;
58 12 foreach my $namespace ( $document->namespaces() ) {
59 SUBDOCUMENT:
60 15 foreach my $subdocument (
61 $document->subdocuments_for_namespace($namespace) ) {
62 next SUBDOCUMENT
63 15 ▶ if not $self->_is_interesting_document($subdocument);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_interesting_document($subdocument) 1 14 15
64  
65 14 my $with_statements = $subdocument->find( \&_is_with_statement );
66  
67 14 ▶ next SUBDOCUMENT if not $with_statements;
Branch: 1 branch
BranchTrueFalseTotal
unless $with_statements 1 13 14
68 13 ▶ next SUBDOCUMENT if @{$with_statements} < 2;
Branch: 1 branch
BranchTrueFalseTotal
if @{$with_statements;} < 2 8 5 13
69  
70 5 my $second_with = $with_statements->[1];
71 5 push
72 @violations,
73 $self->violation( $DESCRIPTION, $EXPLANATION, $second_with );
74 }
75 }
76  
77 12 return @violations;
78 }
79  
80 305 ▶sub _is_with_statement {
Subroutine _is_with_statement: called CC=5 SCAR=16.5
81 305 my ( undef, $element ) = @_;
82  
83 305 ▶ return $FALSE if not is_ppi_generic_statement($element);
Branch: 1 branch
BranchTrueFalseTotal
unless is_ppi_generic_statement($element) 287 18 305
84  
85 18 my $current_token = $element->schild(0);
86 18 ▶ return $FALSE if not $current_token;
Branch: 1 branch
BranchTrueFalseTotal
unless $current_token 0 18 18
87 18 ▶ return $FALSE if not $current_token->isa('PPI::Token::Word');
Branch: 1 branch
BranchTrueFalseTotal
unless $current_token->isa("PPI::Token::Word") 0 18 18
88 18 ▶ return $FALSE if $current_token->content() ne 'with';
Branch: 1 branch
BranchTrueFalseTotal
if $current_token->content ne "with" 0 18 18
89  
90 18 return $TRUE;
91 }
92  
93 1 1;
94  
95 # ABSTRACT: Require role composition
96  
97 __END__
« Policy/Moose/RequireCleanNamespace.pm ↑ Summary Policy/Moose/ProhibitLazyBuild.pm »