Modified source files and compiled any and armel versions of packages
[pkg-perl] / deb-src / libperl-critic-perl / libperl-critic-perl-1.088 / lib / Perl / Critic / Policy / Subroutines / ProhibitNestedSubs.pm
1 ##############################################################################
2 #      $URL: http://perlcritic.tigris.org/svn/perlcritic/trunk/Perl-Critic/lib/Perl/Critic/Policy/Subroutines/ProhibitNestedSubs.pm $
3 #     $Date: 2008-07-03 10:19:10 -0500 (Thu, 03 Jul 2008) $
4 #   $Author: clonezone $
5 # $Revision: 2489 $
6 ##############################################################################
7
8 package Perl::Critic::Policy::Subroutines::ProhibitNestedSubs;
9
10 use 5.006001;
11 use strict;
12 use warnings;
13 use Readonly;
14
15 use Perl::Critic::Utils qw{ :severities };
16 use base 'Perl::Critic::Policy';
17
18 our $VERSION = '1.088';
19
20 #-----------------------------------------------------------------------------
21
22 Readonly::Scalar my $DESC => q{Nested named subroutine};
23 Readonly::Scalar my $EXPL =>
24     q{Declaring a named sub inside another named sub does not prevent the }
25         . q{inner sub from being global};
26
27 #-----------------------------------------------------------------------------
28
29 sub supported_parameters { return ()                    }
30 sub default_severity     { return $SEVERITY_HIGHEST     }
31 sub default_themes       { return qw(core bugs)         }
32 sub applies_to           { return 'PPI::Statement::Sub' }
33
34 #-----------------------------------------------------------------------------
35
36 sub violates {
37     my ($self, $elem, $doc) = @_;
38
39     my $inner = $elem->find_first('PPI::Statement::Sub');
40     return if not $inner;
41
42     # Must be a violation...
43     return $self->violation($DESC, $EXPL, $inner);
44 }
45
46 1;
47
48 __END__
49
50 #-----------------------------------------------------------------------------
51
52 =pod
53
54 =for stopwords RJBS SIGNES
55
56 =head1 NAME
57
58 Perl::Critic::Policy::Subroutines::ProhibitNestedSubs - C<sub never { sub correct {} }>.
59
60 =head1 AFFILIATION
61
62 This Policy is part of the core L<Perl::Critic> 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.
80 Either write your subs without nesting or use anonymous code
81 references.
82
83
84
85 =head1 CONFIGURATION
86
87 This Policy is not configurable except for the standard options.
88
89
90 =head1 NOTE
91
92 Originally part of L<Perl::Critic::Tics>.
93
94
95 =head1 AUTHOR
96
97 Ricardo SIGNES <rjbs@cpan.org>
98
99 =head1 COPYRIGHT
100
101 Copyright (c) 2007-2008 Ricardo SIGNES.
102
103 This program is free software; you can redistribute it and/or modify it under
104 the same terms as Perl itself.
105
106 =cut
107
108 # Local Variables:
109 #   mode: cperl
110 #   cperl-indent-level: 4
111 #   fill-column: 78
112 #   indent-tabs-mode: nil
113 #   c-indentation-style: bsd
114 # End:
115 # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :