« blib/lib/Perl/Critic/Policy/Modules/ProhibitAutomaticExportation.pm
↑ Summary
blib/lib/Perl/Critic/Policy/InputOutput/RequireCheckedSyscalls.pm »
| 1 | package Perl::Critic::Policy::Subroutines::ProhibitNestedSubs; | ||||||||||||||||||||||||||||
| 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{Nested named subroutine}; | |||||||||||||||||||||||||||
| 16 | 40 | Readonly::Scalar my $EXPL => | |||||||||||||||||||||||||||
| 17 | q{Declaring a named sub inside another named sub does not prevent the } | ||||||||||||||||||||||||||||
| 18 | . q{inner sub from being global}; | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 90 | ▶ | sub supported_parameters { return () } | ||||||||||||||||||||||||||
|
Subroutine
supported_parameters: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 23 | 75 | ▶ | sub default_severity { return $SEVERITY_HIGHEST } | ||||||||||||||||||||||||||
|
Subroutine
default_severity: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 24 | 74 | ▶ | sub default_themes { return qw(core bugs) } | ||||||||||||||||||||||||||
|
Subroutine
default_themes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 25 | 37 | ▶ | sub applies_to { return 'PPI::Statement::Sub' } | ||||||||||||||||||||||||||
|
Subroutine
applies_to: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | sub violates { | ||||||||||||||||||||||||||||
| 30 | 5 | ▶ | my ($self, $elem, $doc) = @_; | ||||||||||||||||||||||||||
|
Subroutine
violates: called CC=7 SCAR=22.7
Pod
documented
| |||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 5 | ▶ | return if $elem->isa('PPI::Statement::Scheduled') || defined $elem->type; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$elem->isa("PPI::Statement::Scheduled") or defined $elem->type
MC/DC0%0/2
$elem->isa("PPI::Statement::Scheduled") or defined $elem->type
$elem->isa("PPI::Statement::Scheduled")
defined $elem->type
Truth table33%1/3
A or B
A= $elem->isa("PPI::Statement::Scheduled")B= defined $elem->type
| |||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 5 | my $outer = $elem; | |||||||||||||||||||||||||||
| 35 | 5 | ▶ | while ($outer = $outer->parent) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 36 | 5 | ▶ | last if $outer->isa('PPI::Statement::Sub') | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$outer->isa("PPI::Statement::Sub") and not $outer->isa("PPI::Statement::Scheduled")
MC/DC0%0/2
$outer->isa("PPI::Statement::Sub") and not $outer->isa("PPI::Statement::Scheduled")
$outer->isa("PPI::Statement::Sub")
not $outer->isa("PPI::Statement::Scheduled")
Truth table33%1/3
A and not(B)
A= $outer->isa("PPI::Statement::Sub")B= not $outer->isa("PPI::Statement::Scheduled")
| |||||||||||||||||||||||||||||
| 37 | && ! $outer->isa('PPI::Statement::Scheduled'); | ||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | 5 | ▶ | return if not $outer; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | # Must be a violation... | ||||||||||||||||||||||||||||
| 42 | 0 | return $self->violation($DESC, $EXPL, $elem); | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 40 | 1; | |||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | __END__ | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | =pod | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | =for stopwords RJBS SIGNES | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | =head1 NAME | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | Perl::Critic::Policy::Subroutines::ProhibitNestedSubs - C<sub never { sub correct {} }>. | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | =head1 AFFILIATION | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | This Policy is part of the core L<Perl::Critic|Perl::Critic> | ||||||||||||||||||||||||||||
| 62 | distribution. | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | B<Attention would-be clever Perl writers (including Younger RJBS):> | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | This does not do what you think: | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | sub do_something { | ||||||||||||||||||||||||||||
| 72 | ... | ||||||||||||||||||||||||||||
| 73 | sub do_subprocess { | ||||||||||||||||||||||||||||
| 74 | ... | ||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | ... | ||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | C<do_subprocess()> is global, despite where it is declared. Either | ||||||||||||||||||||||||||||
| 80 | write your subs without nesting or use anonymous code references. | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | =head1 CONFIGURATION | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | This Policy is not configurable except for the standard options. | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | =head1 NOTE | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | Originally part of L<Perl::Critic::Tics|Perl::Critic::Tics>. | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | Ricardo SIGNES <rjbs@cpan.org> | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | Copyright (c) 2007-2011 Ricardo SIGNES. | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | This program is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||
| 103 | it under the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | =cut | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | # Local Variables: | ||||||||||||||||||||||||||||
| 108 | # mode: cperl | ||||||||||||||||||||||||||||
| 109 | # cperl-indent-level: 4 | ||||||||||||||||||||||||||||
| 110 | # fill-column: 78 | ||||||||||||||||||||||||||||
| 111 | # indent-tabs-mode: nil | ||||||||||||||||||||||||||||
| 112 | # c-indentation-style: bsd | ||||||||||||||||||||||||||||
| 113 | # End: | ||||||||||||||||||||||||||||
| 114 | # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround : | ||||||||||||||||||||||||||||