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) $
6 ##############################################################################
8 package Perl::Critic::Policy::Subroutines::ProhibitNestedSubs;
15 use Perl::Critic::Utils qw{ :severities };
16 use base 'Perl::Critic::Policy';
18 our $VERSION = '1.088';
20 #-----------------------------------------------------------------------------
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};
27 #-----------------------------------------------------------------------------
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' }
34 #-----------------------------------------------------------------------------
37 my ($self, $elem, $doc) = @_;
39 my $inner = $elem->find_first('PPI::Statement::Sub');
42 # Must be a violation...
43 return $self->violation($DESC, $EXPL, $inner);
50 #-----------------------------------------------------------------------------
54 =for stopwords RJBS SIGNES
58 Perl::Critic::Policy::Subroutines::ProhibitNestedSubs - C<sub never { sub correct {} }>.
62 This Policy is part of the core L<Perl::Critic> distribution.
67 B<Attention would-be clever Perl writers (including Younger RJBS):>
69 This does not do what you think:
79 C<do_subprocess()> is global, despite where it is declared.
80 Either write your subs without nesting or use anonymous code
87 This Policy is not configurable except for the standard options.
92 Originally part of L<Perl::Critic::Tics>.
97 Ricardo SIGNES <rjbs@cpan.org>
101 Copyright (c) 2007-2008 Ricardo SIGNES.
103 This program is free software; you can redistribute it and/or modify it under
104 the same terms as Perl itself.
110 # cperl-indent-level: 4
112 # indent-tabs-mode: nil
113 # c-indentation-style: bsd
115 # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :