| 1 | package Perl::Critic::Policy::Community::StrictWarnings; | ||||||||||||||||||||||||||||
| 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 | |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Perl::Critic::Utils qw(:severities :classification :ppi); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Perl::Critic::Utils::Constants qw(@STRICT_EQUIVALENT_MODULES @WARNINGS_EQUIVALENT_MODULES); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use parent 'Perl::Critic::Policy'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use version; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 1 | our $VERSION = 'v1.0.4'; | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use constant DESC => 'Missing strict or warnings'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use constant EXPL => 'The strict and warnings pragmas are important to avoid common pitfalls and deprecated/experimental functionality. Make sure each script or module contains "use strict; use warnings;" or a module that does this for you.'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 19 | ▶ | sub supported_parameters { | ||||||||||||||||||||||||||
|
Subroutine
supported_parameters: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 17 | ( | ||||||||||||||||||||||||||||
| 18 | { | ||||||||||||||||||||||||||||
| 19 | 19 | name => 'extra_importers', | |||||||||||||||||||||||||||
| 20 | description => 'Non-standard modules to recognize as importing strict and warnings', | ||||||||||||||||||||||||||||
| 21 | behavior => 'string list', | ||||||||||||||||||||||||||||
| 22 | }, | ||||||||||||||||||||||||||||
| 23 | ) | ||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 10 | ▶ | sub default_severity { $SEVERITY_HIGH } | ||||||||||||||||||||||||||
|
Subroutine
default_severity: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 27 | 0 | ▶ | sub default_themes { 'community' } | ||||||||||||||||||||||||||
|
Subroutine
default_themes: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 28 | 19 | ▶ | sub applies_to { 'PPI::Document' } | ||||||||||||||||||||||||||
|
Subroutine
applies_to: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 1 | my @incomplete_importers = qw(common::sense sanity); | |||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 19 | ▶ | sub violates { | ||||||||||||||||||||||||||
|
Subroutine
violates: called CC=21 SCAR=30.5
Pod
documented
| |||||||||||||||||||||||||||||
| 33 | 19 | my ($self, $elem) = @_; | |||||||||||||||||||||||||||
| 34 | 19 | ▶ | my $includes = $elem->find('PPI::Statement::Include') || []; | ||||||||||||||||||||||||||
|
Condition100%2/2
$elem->find('PPI::Statement::Include') || []
MC/DC100%1/1
$elem->find('PPI::Statement::Include') || []
$elem->find('PPI::Statement::Include')
Truth table100%2/2
A
A= $elem->find('PPI::Statement::Include')
| |||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | # Add importers from Perl::Critic core | ||||||||||||||||||||||||||||
| 37 | 19 | my %strict_importers = map { ($_ => 1) } @STRICT_EQUIVALENT_MODULES; | |||||||||||||||||||||||||||
| 38 | 19 | my %warnings_importers = map { ($_ => 1) } @WARNINGS_EQUIVALENT_MODULES; | |||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | # Remove incomplete importers if added | ||||||||||||||||||||||||||||
| 41 | 19 | delete $strict_importers{$_} for @incomplete_importers; | |||||||||||||||||||||||||||
| 42 | 19 | delete $warnings_importers{$_} for @incomplete_importers; | |||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | # Add extra importers | ||||||||||||||||||||||||||||
| 45 | 19 | $strict_importers{$_} = $warnings_importers{$_} = 1 foreach keys %{$self->{_extra_importers}}; | |||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 19 | my ($has_strict, $has_warnings); | |||||||||||||||||||||||||||
| 48 | 19 | foreach my $include (@$includes) { | |||||||||||||||||||||||||||
| 49 | 25 | ▶ | if ($include->pragma) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | 10 | ▶ | $has_strict = 1 if $include->pragma eq 'strict'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | 10 | ▶ | $has_warnings = 1 if $include->pragma eq 'warnings'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | 25 | ▶ | if ($include->type//'' eq 'use') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$include->type //
MC/DC0%0/1
$include->type //
$include->type
Truth table50%1/2
A
A= $include->type
| |||||||||||||||||||||||||||||
| 54 | 25 | ▶ | $has_strict = 1 if $include->version and version->parse($include->version) >= version->parse('v5.12'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$include->version and "version"->parse($include->version) >= "version"->parse("v5.12")
MC/DC100%2/2
$include->version and "version"->parse($include->version) >= "version"->parse("v5.12")
$include->version
"version"->parse($include->version) >= "version"->parse("v5.12")
Truth table100%3/3
A and B
A= $include->versionB= "version"->parse($include->version) >= "version"->parse("v5.12")
| |||||||||||||||||||||||||||||
| 55 | 25 | ▶ | $has_strict = 1 if defined $include->module and exists $strict_importers{$include->module}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $include->module and exists $strict_importers{$include->module}
MC/DC50%1/2
defined $include->module and exists $strict_importers{$include->module}
defined $include->module
exists $strict_importers{$include->module}
Truth table66%2/3
A and B
A= defined $include->moduleB= exists $strict_importers{$include->module}
| |||||||||||||||||||||||||||||
| 56 | 25 | ▶ | $has_warnings = 1 if $include->version and version->parse($include->version) >= version->parse('v5.36'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$include->version and "version"->parse($include->version) >= "version"->parse("v5.36")
MC/DC100%2/2
$include->version and "version"->parse($include->version) >= "version"->parse("v5.36")
$include->version
"version"->parse($include->version) >= "version"->parse("v5.36")
Truth table100%3/3
A and B
A= $include->versionB= "version"->parse($include->version) >= "version"->parse("v5.36")
| |||||||||||||||||||||||||||||
| 57 | 25 | ▶ | $has_warnings = 1 if defined $include->module and exists $warnings_importers{$include->module}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $include->module and exists $warnings_importers{$include->module}
MC/DC50%1/2
defined $include->module and exists $warnings_importers{$include->module}
defined $include->module
exists $warnings_importers{$include->module}
Truth table66%2/3
A and B
A= defined $include->moduleB= exists $warnings_importers{$include->module}
| |||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | 25 | ▶ | return () if $has_strict and $has_warnings; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$has_strict and $has_warnings
MC/DC100%2/2
$has_strict and $has_warnings
$has_strict
$has_warnings
Truth table100%3/3
A and B
A= $has_strictB= $has_warnings
| |||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 10 | return $self->violation(DESC, EXPL, $elem); | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 1 | 1; | |||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | =head1 NAME | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | Perl::Critic::Policy::Community::StrictWarnings - Always use strict and | ||||||||||||||||||||||||||||
| 70 | warnings, or a module that imports these | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | The L<strict> and L<warnings> pragmas help avoid many common pitfalls such as | ||||||||||||||||||||||||||||
| 75 | misspellings, scoping issues, and performing operations on undefined values. | ||||||||||||||||||||||||||||
| 76 | Warnings can also alert you to deprecated or experimental functionality. The | ||||||||||||||||||||||||||||
| 77 | pragmas may either be explicitly imported with C<use>, or indirectly through a | ||||||||||||||||||||||||||||
| 78 | number of importer modules such as L<Moose> or L<strictures>. L<strict> is also | ||||||||||||||||||||||||||||
| 79 | enabled automatically with a C<use> declaration of perl version 5.12 or higher, | ||||||||||||||||||||||||||||
| 80 | as is L<warnings> with a C<use> declaration of 5.36 or higher. | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | use strict; | ||||||||||||||||||||||||||||
| 83 | use warnings; | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | use Moose; | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | use 5.012; | ||||||||||||||||||||||||||||
| 88 | use warnings; | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | use 5.036; | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | This policy is similar to the core policies | ||||||||||||||||||||||||||||
| 93 | L<Perl::Critic::Policy::TestingAndDebugging::RequireUseStrict> and | ||||||||||||||||||||||||||||
| 94 | L<Perl::Critic::Policy::TestingAndDebugging::RequireUseWarnings>, but combines | ||||||||||||||||||||||||||||
| 95 | them into one policy in the C<community> theme. The default modules recognized | ||||||||||||||||||||||||||||
| 96 | as importing L<strict> and L<warnings> are defined by the same constants as the | ||||||||||||||||||||||||||||
| 97 | core policies, L<Perl::Critic::Utils::Constants/"@STRICT_EQUIVALENT_MODULES">. | ||||||||||||||||||||||||||||
| 98 | To define additional modules, see L</"CONFIGURATION">. | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | =head1 AFFILIATION | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | This policy is part of L<Perl::Critic::Community>. | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | =head1 CONFIGURATION | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | This policy can be configured to recognize additional modules as importers of | ||||||||||||||||||||||||||||
| 107 | L<strict> and L<warnings>, by putting an entry in a C<.perlcriticrc> file like | ||||||||||||||||||||||||||||
| 108 | this: | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | [Community::StrictWarnings] | ||||||||||||||||||||||||||||
| 111 | extra_importers = MyApp::Class MyApp::Role | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | Dan Book, C<dbook@cpan.org> | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | Copyright 2015, Dan Book. | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | This library is free software; you may redistribute it and/or modify it under | ||||||||||||||||||||||||||||
| 122 | the terms of the Artistic License version 2.0. | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | L<Perl::Critic> | ||||||||||||||||||||||||||||