« blib/lib/Perl/Critic/Policy/ValuesAndExpressions/RequireNumberSeparators.pm
↑ Summary
blib/lib/Perl/Critic/Policy/ValuesAndExpressions/ProhibitSpecialLiteralHeredocTerminator.pm »
| 1 | package Perl::Critic::Policy::Modules::RequireEndWithOne; | ||||||||||||||||||||||||||||
| 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 :classification }; | ||||||||||||||||||||||||||
|
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 $EXPL => q{Must end with a recognizable true value}; | |||||||||||||||||||||||||||
| 16 | 40 | Readonly::Scalar my $DESC => q{Module does not end with "1;"}; | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 90 | ▶ | sub supported_parameters { return () } | ||||||||||||||||||||||||||
|
Subroutine
supported_parameters: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 21 | 81 | ▶ | sub default_severity { return $SEVERITY_HIGH } | ||||||||||||||||||||||||||
|
Subroutine
default_severity: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 22 | 92 | ▶ | sub default_themes { return qw( core bugs pbp certrule ) } | ||||||||||||||||||||||||||
|
Subroutine
default_themes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 23 | 32 | ▶ | sub applies_to { return 'PPI::Document' } | ||||||||||||||||||||||||||
|
Subroutine
applies_to: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | sub prepare_to_scan_document { | ||||||||||||||||||||||||||||
| 28 | 33 | ▶ | my ( $self, $document ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
prepare_to_scan_document: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 33 | return $document->is_module(); # Must be a library or module. | |||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | sub violates { | ||||||||||||||||||||||||||||
| 34 | 32 | ▶ | my ( $self, $elem, $doc ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
violates: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | # Last statement should be just "1;" | ||||||||||||||||||||||||||||
| 37 | 32 | my @significant = grep { _is_code($_) } $doc->schildren(); | |||||||||||||||||||||||||||
| 38 | 32 | my $match = $significant[-1]; | |||||||||||||||||||||||||||
| 39 | 32 | ▶ | return if !$match; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | 30 | ▶ | return if ((ref $match) eq 'PPI::Statement' && | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
ref $match eq "PPI::Statement" and $match =~ /\A 1 \s* ; \z/msx
MC/DC100%2/2
ref $match eq "PPI::Statement" and $match =~ /\A 1 \s* ; \z/msx
ref $match eq "PPI::Statement"
$match =~ /\A 1 \s* ; \z/msx
Truth table100%3/3
A and B
A= ref $match eq "PPI::Statement"B= $match =~ /\A 1 \s* ; \z/msx
| |||||||||||||||||||||||||||||
| 41 | $match =~ m{\A 1 \s* ; \z}xms ); | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | # Must be a violation... | ||||||||||||||||||||||||||||
| 44 | 6 | return $self->violation( $DESC, $EXPL, $match ); | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | sub _is_code { | ||||||||||||||||||||||||||||
| 48 | 247 | ▶ | my $elem = shift; | ||||||||||||||||||||||||||
|
Subroutine
_is_code: called CC=2 SCAR=8.1
| |||||||||||||||||||||||||||||
| 49 | 247 | ▶ | return ! ( $elem->isa('PPI::Statement::End') | ||||||||||||||||||||||||||
|
Condition33%1/3
$elem->isa('PPI::Statement::End') || $elem->isa('PPI::Statement::Data')
MC/DC0%0/2
$elem->isa('PPI::Statement::End') || $elem->isa('PPI::Statement::Data')
$elem->isa('PPI::Statement::End')
$elem->isa('PPI::Statement::Data')
Truth table33%1/3
A || B
A= $elem->isa('PPI::Statement::End')B= $elem->isa('PPI::Statement::Data')
| |||||||||||||||||||||||||||||
| 50 | || $elem->isa('PPI::Statement::Data')); | ||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 40 | 1; | |||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | __END__ | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | =pod | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | =head1 NAME | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | Perl::Critic::Policy::Modules::RequireEndWithOne - End each module with an explicitly C<1;> instead of some funky expression. | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | =head1 AFFILIATION | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | This Policy is part of the core L<Perl::Critic|Perl::Critic> | ||||||||||||||||||||||||||||
| 69 | distribution. | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | All files included via C<use> or C<require> must end with a true value | ||||||||||||||||||||||||||||
| 75 | to indicate to the caller that the include was successful. The | ||||||||||||||||||||||||||||
| 76 | standard practice is to conclude your .pm files with C<1;>, but some | ||||||||||||||||||||||||||||
| 77 | authors like to get clever and return some other true value like | ||||||||||||||||||||||||||||
| 78 | C<return "Club sandwich";>. We cannot tolerate such frivolity! OK, | ||||||||||||||||||||||||||||
| 79 | we can, but we don't recommend it since it confuses the newcomers. | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | =head1 CONFIGURATION | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | This Policy is not configurable except for the standard options. | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | Chris Dolan C<cdolan@cpan.org> | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | Some portions cribbed from | ||||||||||||||||||||||||||||
| 92 | L<Perl::Critic::Policy::Modules::RequireExplicitPackage|Perl::Critic::Policy::Modules::RequireExplicitPackage>. | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | Copyright (c) 2005-2011 Chris Dolan and Imaginative Software Systems. All | ||||||||||||||||||||||||||||
| 98 | rights reserved. | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | This program is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||
| 101 | it under the same terms as Perl itself. The full text of this license | ||||||||||||||||||||||||||||
| 102 | can be found in the LICENSE file included with this module. | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | =cut | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | # Local Variables: | ||||||||||||||||||||||||||||
| 107 | # mode: cperl | ||||||||||||||||||||||||||||
| 108 | # cperl-indent-level: 4 | ||||||||||||||||||||||||||||
| 109 | # fill-column: 78 | ||||||||||||||||||||||||||||
| 110 | # indent-tabs-mode: nil | ||||||||||||||||||||||||||||
| 111 | # c-indentation-style: bsd | ||||||||||||||||||||||||||||
| 112 | # End: | ||||||||||||||||||||||||||||
| 113 | # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround : | ||||||||||||||||||||||||||||