Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 177 lines (123 sloc) 5.906 kB
55a96b2 Deprecation scanner added
Zbigniew Lukasiak authored
1 package Perl::Critic::Policy::FormHandler::Deprecations;
2
3 our $VERSION = '0.001';
4
5 use warnings;
6 use strict;
7 use Carp;
8
9 use Perl::Critic::Utils qw( :severities :classification first_arg parse_arg_list split_nodes_on_comma );
10
11 use base 'Perl::Critic::Policy';
12
13 sub supported_parameters { return (); }
14 sub default_severity { return $SEVERITY_HIGH; }
15 sub default_themes { return qw( bugs formhandler); }
16 sub applies_to { return 'PPI::Token::Word' }
17
18 sub violates {
19 my ($self, $elem ) = @_;
20
21 return if ! is_function_call($elem);
22 if( $elem eq 'has' ){
23 my $farg = first_arg( $elem );
24 return if ! $farg->can( 'string' );
25 $farg = $farg->string;
26 if( $farg eq '+min_length' ){
27 return $self->violation('The "min_length" attribute used.',
28 'The "min_length" attribute is deprecated - use minlength instead.',
29 $elem);
30 }
31 }
32 elsif( $elem eq 'has_field' ){
33 my @args = parse_arg_list( $elem );
34 return if ref $args[1][0] ne 'PPI::Structure::List';
35 for my $e( $args[1][0]->children ){
36 next if ref $e ne 'PPI::Statement::Expression';
37 my $i = 0;
38 for my $attr ( split_nodes_on_comma( $e->children ) ){
39 next if $i++ % 2;
40 next if ref $attr ne 'ARRAY';
41 for my $a( @$attr ){
42 next if ref $a ne 'PPI::Token::Word';
43 next if $a->literal ne 'min_length';
44 return $self->violation('The "min_length" attribute used.',
45 'The "min_length" attribute is deprecated - use minlength instead.',
46 $elem);
47 }
48 }
49 }
50 }
51 return;
52 }
53
54 1; # Magic true value required at end of module
55 __END__
56
57 =head1 NAME
58
59 Perl::Critic::Policy::FormHandler::Deprecations - Checks if deprecated parts of the HTML::FormHandlers API are used
60
61
62 =head1 VERSION
63
64 This document describes Perl::Critic::Policy::FormHandler::Deprecations version 0.0.1
65
66
67 =head1 SYNOPSIS
68
69 perlcritic --theme formhandler lib # assuming Perl::Critic::Policy::FormHandler::Deprecations is in the path
70
71 =head1 DESCRIPTION
72
73 This is a L<Perl::Critic> policy for code using HTML::FormHandler - it detects constructs deprecated in latest
74 HTML::FormHandler version.
75
76
77 =head1 INTERFACE
78
79 =head1 DIAGNOSTICS
80
81 =over
82
83 =item C<< Error message here, perhaps with %s placeholders >>
84
85 [Description of error here]
86
87 =item C<< Another error message here >>
88
89 [Description of error here]
90
91 [Et cetera, et cetera]
92
93 =back
94
95
96 =head1 CONFIGURATION AND ENVIRONMENT
97
98 =for author to fill in:
99 A full explanation of any configuration system(s) used by the
100 module, including the names and locations of any configuration
101 files, and the meaning of any environment variables or properties
102 that can be set. These descriptions must also include details of any
103 configuration language used.
104
105 Perl::Critic::Policy::FormHandler::Deprecations requires no configuration files or environment variables.
106
107
108 =head1 DEPENDENCIES
109
110 L<Perl::Critic>
111
112 =head1 INCOMPATIBILITIES
113
114 =for author to fill in:
115 A list of any modules that this module cannot be used in conjunction
116 with. This may be due to name conflicts in the interface, or
117 competition for system or program resources, or due to internal
118 limitations of Perl (for example, many modules that use source code
119 filters are mutually incompatible).
120
121 None reported.
122
123
124 =head1 BUGS AND LIMITATIONS
125
126 =for author to fill in:
127 A list of known problems with the module, together with some
128 indication Whether they are likely to be fixed in an upcoming
129 release. Also a list of restrictions on the features the module
130 does provide: data types that cannot be handled, performance issues
131 and the circumstances in which they may arise, practical
132 limitations on the size of data sets, special cases that are not
133 (yet) handled, etc.
134
135 No bugs have been reported.
136
137 Please report any bugs or feature requests to
138 C<bug-perl-critic-policy-formhandler-deprecations@rt.cpan.org>, or through the web interface at
139 L<http://rt.cpan.org>.
140
141
142 =head1 AUTHOR
143
144 Zbigniew Lukasiak C<< <<zby @ cpan.org >> >>
145 based on idea from L<http://blog.robin.smidsrod.no/index.php/2009/07/03/deprecated-code-analyzer-for-perl>
146
147 =head1 LICENCE AND COPYRIGHT
148
149 Copyright (c) 2009, Zbigniew Lukasiak C<< << zbigniew @ lukasiak.name >> >>. All rights reserved.
150
151 This module is free software; you can redistribute it and/or
152 modify it under the same terms as Perl itself. See L<perlartistic>.
153
154
155 =head1 DISCLAIMER OF WARRANTY
156
157 BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
158 FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
159 OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
160 PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
161 EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
162 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
163 ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH
164 YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL
165 NECESSARY SERVICING, REPAIR, OR CORRECTION.
166
167 IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
168 WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
169 REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE
170 LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL,
171 OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE
172 THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
173 RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
174 FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
175 SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
176 SUCH DAMAGES.
Something went wrong with that request. Please try again.