Build all packages removed dependencies of libtest-exception-perl libtest-warn-perl...
[dh-make-perl] / dev / i386 / libperl-critic-perl / libperl-critic-perl-1.088 / lib / Perl / Critic / Policy / CodeLayout / RequireTrailingCommas.pm
1 ##############################################################################
2 #      $URL: http://perlcritic.tigris.org/svn/perlcritic/trunk/Perl-Critic/lib/Perl/Critic/Policy/CodeLayout/RequireTrailingCommas.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::CodeLayout::RequireTrailingCommas;
9
10 use 5.006001;
11 use strict;
12 use warnings;
13 use Readonly;
14
15 use Perl::Critic::Utils qw{ :characters :severities };
16 use base 'Perl::Critic::Policy';
17
18 our $VERSION = '1.088';
19
20 #-----------------------------------------------------------------------------
21
22 Readonly::Scalar my $DESC => q{List declaration without trailing comma};
23 Readonly::Scalar my $EXPL => [ 17 ];
24
25 #-----------------------------------------------------------------------------
26
27 sub supported_parameters { return ()                     }
28 sub default_severity     { return $SEVERITY_LOWEST       }
29 sub default_themes       { return qw(core pbp cosmetic)  }
30 sub applies_to           { return 'PPI::Structure::List' }
31
32 #-----------------------------------------------------------------------------
33
34 sub violates {
35     my ( $self, $elem, undef ) = @_;
36     $elem =~ m{ \n }mx || return;
37
38     # Is it an assignment of some kind?
39     my $sib = $elem->sprevious_sibling();
40     return if !$sib;
41     $sib->isa('PPI::Token::Operator') && $sib =~ m{ = }mx || return;
42
43     # List elements are children of an expression
44     my $expr = $elem->schild(0);
45     return if !$expr;
46
47     # Does the list have more than 1 element?
48     # This means list element, not PPI element.
49     my @children = $expr->schildren();
50     return if 1 >= grep {    $_->isa('PPI::Token::Operator')
51                           && $_ eq $COMMA } @children;
52
53     # Is the final element a comma?
54     my $final = $children[-1];
55     if ( ! ($final->isa('PPI::Token::Operator') && $final eq $COMMA) ) {
56         return $self->violation( $DESC, $EXPL, $elem );
57     }
58
59     return; #ok!
60 }
61
62 1;
63
64 __END__
65
66 =pod
67
68 =head1 NAME
69
70 Perl::Critic::Policy::CodeLayout::RequireTrailingCommas - Put a comma at the end of every multi-line list declaration, including the last one.
71
72 =head1 AFFILIATION
73
74 This Policy is part of the core L<Perl::Critic> distribution.
75
76
77 =head1 DESCRIPTION
78
79 Conway suggests that all elements in a multi-line list should be
80 separated by commas, including the last element.  This makes it a
81 little easier to re-order the list by cutting and pasting.
82
83   my @list = ($foo,
84               $bar,
85               $baz);  #not ok
86
87   my @list = ($foo,
88               $bar,
89               $baz,); #ok
90
91
92 =head1 CONFIGURATION
93
94 This Policy is not configurable except for the standard options.
95
96
97 =head1 NOTES
98
99 In the PPI parlance, a "list" is almost anything with parentheses.
100 I've tried to make this Policy smart by targeting only "lists" that
101 have at least one element and are being assigned to something.
102 However, there may be some edge cases that I haven't covered.  If you
103 find one, send me a note.
104
105 =head1 AUTHOR
106
107 Jeffrey Ryan Thalhammer <thaljef@cpan.org>
108
109 =head1 COPYRIGHT
110
111 Copyright (c) 2005-2008 Jeffrey Ryan Thalhammer.  All rights reserved.
112
113 This program is free software; you can redistribute it and/or modify
114 it under the same terms as Perl itself.  The full text of this license
115 can be found in the LICENSE file included with this module.
116
117 =cut
118
119 # Local Variables:
120 #   mode: cperl
121 #   cperl-indent-level: 4
122 #   fill-column: 78
123 #   indent-tabs-mode: nil
124 #   c-indentation-style: bsd
125 # End:
126 # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :