blib/lib/Perl/Critic/Policy/Modules/ProhibitMultiplePackages.pm

filter: Statementstmt 91.1% 31 / 34 Branchbran 75.0% 3 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 11 / 11 Podpod 80.0% 4 / 5 totaltotal 90.7% 49 / 54 CC 3 SCAR 4.2
CC
3
Cov
89%
violates
3.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.5
« blib/lib/Perl/Critic/Policy/ValuesAndExpressions/ProhibitConstantPragma.pm ↑ Summary blib/lib/Perl/Critic/ThemeListing.pm »
1 package Perl::Critic::Policy::Modules::ProhibitMultiplePackages;
2  
3 40 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 40 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 40 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 40 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 40 ▶use Perl::Critic::Utils qw{ :severities };
Subroutine BEGIN: called CC=1 SCAR=0.0
9 40 ▶use parent 'Perl::Critic::Policy';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 40 our $VERSION = '1.150';
12  
13 #-----------------------------------------------------------------------------
14  
15 40 Readonly::Scalar my $DESC => q{Multiple "package" declarations};
16 40 Readonly::Scalar my $EXPL => q{Limit to one per file};
17  
18 #-----------------------------------------------------------------------------
19  
20 90 ▶sub supported_parameters { return () }
Subroutine supported_parameters: called CC=1 SCAR=0.0
Pod undocumented
21 75 ▶sub default_severity { return $SEVERITY_HIGH }
Subroutine default_severity: called CC=1 SCAR=0.0
Pod documented
22 74 ▶sub default_themes { return qw( core bugs ) }
Subroutine default_themes: called CC=1 SCAR=0.0
Pod documented
23 33 ▶sub applies_to { return 'PPI::Document' }
Subroutine applies_to: called CC=1 SCAR=0.0
Pod documented
24  
25 #-----------------------------------------------------------------------------
26  
27 sub violates {
28 33 ▶ my ( $self, $elem, $doc ) = @_;
Subroutine violates: called CC=3 SCAR=11.8
Pod documented
29 33 my $nodes_ref = $doc->find('PPI::Statement::Package');
30 33 ▶ return if !$nodes_ref;
Branch: 1 branch
BranchTrueFalseTotal
unless $nodes_ref 3 30 33
31 30 ▶ my @matches = @{$nodes_ref} > 1 ? @{$nodes_ref}[ 1 .. $#{$nodes_ref} ] :();
Branch: 1 branch
BranchTrueFalseTotal
@{$nodes_ref;} > 1 ? : 0 30 30
32  
33 30 return map {$self->violation($DESC, $EXPL, $_)} @matches;
34 }
35  
36 40 1;
37  
38 __END__
39  
40 #-----------------------------------------------------------------------------
41  
42 =pod
43  
44 =head1 NAME
45  
46 Perl::Critic::Policy::Modules::ProhibitMultiplePackages - Put packages (especially subclasses) in separate files.
47  
48  
49 =head1 AFFILIATION
50  
51 This Policy is part of the core L<Perl::Critic|Perl::Critic>
52 distribution.
53  
54  
55 =head1 DESCRIPTION
56  
57 Conway doesn't specifically mention this, but I find it annoying when
58 there are multiple packages in the same file. When searching for
59 methods or keywords in your editor, it makes it hard to find the right
60 chunk of code, especially if each package is a subclass of the same
61 base.
62  
63  
64 =head1 CONFIGURATION
65  
66 This Policy is not configurable except for the standard options.
67  
68  
69 =head1 AUTHOR
70  
71 Jeffrey Ryan Thalhammer <jeff@imaginative-software.com>
72  
73  
74 =head1 COPYRIGHT
75  
76 Copyright (c) 2005-2011 Imaginative Software Systems. All rights reserved.
77  
78 This program is free software; you can redistribute it and/or modify
79 it under the same terms as Perl itself. The full text of this license
80 can be found in the LICENSE file included with this module.
81  
82 =cut
83  
84 # Local Variables:
85 # mode: cperl
86 # cperl-indent-level: 4
87 # fill-column: 78
88 # indent-tabs-mode: nil
89 # c-indentation-style: bsd
90 # End:
91 # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :
« blib/lib/Perl/Critic/Policy/ValuesAndExpressions/ProhibitConstantPragma.pm ↑ Summary blib/lib/Perl/Critic/ThemeListing.pm »