Policy/Moose/RequireCleanNamespace.pm

filter: Statementstmt 97.8% 45 / 46 Branchbran 90.0% 9 / 10 Conditioncond 66.6% 4 / 6 MC/DCmcdc 50.0% 2 / 4 Subroutinesub 90.9% 10 / 11 Podpod 80.0% 4 / 5 totaltotal 90.2% 74 / 82 CC 9 SCAR 15.8
CC
9
Cov
94%
violates
9.0
default_themes
2.0
BEGIN
1.0
CRAP 4.9
« Policy/Moose/RequireMakeImmutable.pm ↑ Summary Policy/Moose/ProhibitMultipleWiths.pm »
1 package Perl::Critic::Policy::Moose::RequireCleanNamespace;
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 $PERIOD >;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 1 ▶use base 'Perl::Critic::Policy';
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 1 Readonly::Scalar my $EXPLANATION =>
16 q<Don't leave things used for implementation in your interface.>;
17  
18 12 ▶sub supported_parameters {
Subroutine supported_parameters: called CC=1 SCAR=0.0
Pod undocumented
19 return (
20 {
21 12 name => 'modules',
22 description => 'The modules that need to be unimported.',
23 default_string =>
24 'Moose Moose::Role Moose::Util::TypeConstraints MooseX::Role::Parameterized',
25 behavior => 'string list',
26 },
27 {
28 name => 'cleaners',
29 description => 'Modules that clean imports.',
30 default_string => 'namespace::autoclean',
31 behavior => 'string list',
32 },
33 );
34 }
35  
36 5 ▶sub default_severity { return $SEVERITY_MEDIUM; }
Subroutine default_severity: called CC=1 SCAR=0.0
Pod documented
37 0 ▶sub default_themes { return qw( moose maintenance ); }
Subroutine default_themes: not called CC=1 SCAR=6.9
Pod documented
38 12 ▶sub applies_to { return 'PPI::Document' }
Subroutine applies_to: called CC=1 SCAR=0.0
Pod documented
39  
40 12 ▶sub violates {
Subroutine violates: called CC=9 SCAR=22.0
Pod documented
41 12 my ( $self, undef, $document ) = @_;
42  
43 12 my %modules = ( use => {}, require => {}, no => {} );
44 12 my $includes = $document->find('PPI::Statement::Include');
45 12 ▶ return if not $includes;
Branch: 1 branch
BranchTrueFalseTotal
unless $includes 0 12 12
46  
47 12 for my $include ( @{$includes} ) {
48  
49 # skip if nothing imported
50 21 ▶ if ( $include->type eq 'use' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($include->type eq "use") 16 5 21
51 16 my $lists = $include->find('PPI::Structure::List');
52 16 ▶ next if $lists and not grep { $_->children > 0 } @{$lists};
Branch: 1 branch
BranchTrueFalseTotal
if $lists and not grep({$_->children > 0;} @{$lists;}) 1 15 16
Condition66%2/3
$lists and not grep({$_->children > 0;} @{$lists;})
!ll&&!rl&&r
1501
MC/DC50%1/2
$lists and not grep({$_->children > 0;} @{$lists;})
$lists not grep({$_->children > 0;} @{$lists;})
Truth table66%2/3
A and not(B)
A= $listsB= not grep({$_->children > 0;} @{$lists;})
ABresult
0X0
100
111
53 }
54  
55 20 $modules{ $include->type }->{ $include->module } = 1;
56 }
57  
58 12 ▶ return if grep { $modules{use}{$_} } keys %{ $self->{_cleaners} };
Branch: 1 branch
BranchTrueFalseTotal
if grep {$modules{"use"}{$_};} keys %{$$self{"_cleaners"};} 2 10 12
59  
60 10 my $modules_to_unimport = $self->{_modules};
61 my @used_but_not_unimported
62 11 ▶ = grep { $modules_to_unimport->{$_} and not $modules{no}->{$_} }
Condition66%2/3
$modules_to_unimport->{$_} && !$modules{'no'}{$_}
!ll&&!rl&&r
056
MC/DC50%1/2
$modules_to_unimport->{$_} && !$modules{'no'}{$_}
$modules_to_unimport->{$_} !$modules{'no'}{$_}
Truth table66%2/3
A && not(B)
A= $modules_to_unimport->{$_}B= !$modules{'no'}{$_}
ABresult
0X0
100
111
63 10 keys %{ $modules{use} };
64  
65 10 ▶ return if not @used_but_not_unimported;
Branch: 1 branch
BranchTrueFalseTotal
unless @used_but_not_unimported 5 5 10
66  
67 5 return $self->violation(
68 q<Didn't unimport >
69 . ( join q<, >, sort @used_but_not_unimported )
70 . $PERIOD,
71 $EXPLANATION,
72 $document,
73 );
74 }
75  
76 1 1;
77  
78 # ABSTRACT: Require removing implementation details from you packages.
79  
80 __END__
« Policy/Moose/RequireMakeImmutable.pm ↑ Summary Policy/Moose/ProhibitMultipleWiths.pm »