1Padre::Document::Perl::UBseegrinCnoenrt(r3i)buted Perl DPoacdurmee:n:tDaotciuomnent::Perl::Beginner(3)
2
3
4

NAME

6       Padre::Document::Perl::Beginner - naive implementation of some beginner
7       specific error checking
8

SYNOPSIS

10         use Padre::Document::Perl::Beginner;
11         my $beginner = Padre::Document::Perl::Beginner->new;
12         if (not $beginner->check($data)) {
13             warn $beginner->error;
14         }
15

DESCRIPTION

17       This is a naive implementation. It needs to be replaced by one using
18       PPI.
19
20       In Perl 5 there are lots of pitfalls the unaware, especially the
21       beginner can easily fall in. While some might expect the Perl compiler
22       itself would catch those it does not (yet ?) do it. So we took the
23       initiative and added a beginners mode to Padre in which these extra
24       issues are checked. Some are real problems that would trigger an error
25       anyway we just make them a special case with a more specific error
26       message.  (e.g. "use warning;" without the trailing s) Others are valid
27       code that can be useful in the hands of a master but that are poisonous
28       when written by mistake by someone who does not understand them.  (e.g.
29       "if ($x = /value/) { }" ).
30
31       This module provides a method called "check" that can check a Perl
32       script (provided as parameter as a single string) and recognize
33       problematic code.
34

Examples

36       See <http://padre.perlide.org/ticket/52> and
37       <http://www.perlmonks.org/?node_id=728569>
38

Cases

40       ·
41
42
43             split /,/, @data;
44
45           Here @data is in scalar context returning the number of elements.
46           Spotted in this form:
47
48             split /,/, @ARGV;
49
50       ·
51
52
53             use warning;
54
55           s is missing at the end.
56
57       ·
58
59
60             map { $_; } (@items),$extra_item;
61
62           is the same as
63
64             map { $_; } (@items,$extra_item);
65
66           but you usually want
67
68             (map { $_; } (@items)),$extra_item;
69
70           which means: map all @items and them add $extra_item without
71           mapping it.
72
73       ·   Warn about Perl-standard package names being reused
74
75             package DB;
76
77       ·
78
79
80             $x = chomp $y;
81             print chomp $y;
82
83       ·
84
85
86             map { s/foo/bar/; } (@items);
87
88           This returns an array containing true or false values (s/// -
89           return value).
90
91           Use
92
93             map { s/foo/bar/; $_; } (@items);
94
95           to actually change the array via s///.
96
97       ·
98
99
100             <@X>
101
102       ·
103
104
105             if ($x = /bla/) {
106             }
107
108       ·   Pipe | in open() not at the end or the beginning.
109
110       ·
111
112
113             open($ph, "|  something |");
114
115       ·   Regular expression starting with a quantifier such as
116
117             /+.../
118
119       ·
120
121
122             } else if {
123
124       ·
125
126
127            } elseif {
128
129       ·
130
131
132            close;
133

HOW TO ADD ANOTHER ONE

135       Please feel free to add as many checks as you like. This is done in
136       three steps:
137
138   Add the test
139       Add one (or more) tests for this case to t/75-perl-beginner.t
140
141       The test should be successful when your supplied sample fails the check
142       and returns the correct error message. As texts of error messages may
143       change, try to match a good part which allows identification of the
144       message but don't match the very exact text.
145
146       Tests could use either one-liners written as strings within the test
147       file or external support files. There are samples for both ways in the
148       test script.
149
150   Add the check
151       Add the check to the check-sub of this file
152       (Document/Perl/Beginner.pm). There are plenty samples here. Remember to
153       add a sample (and maybe short description) what would fail the test.
154
155       Run the test script to match your test case(s) to the new check.
156
157   Add the configuration option
158       Go to Config.pm, look for the beginner error checks configuration and
159       add a new setting for your new check there. It defaults to 1 (run the
160       check), but a user could turn it off by setting this to 0 within the
161       Padre configuration file.
162
164       Copyright 2008-2011 The Padre development team as listed in Padre.pm.
165
166       This program is free software; you can redistribute it and/or modify it
167       under the same terms as Perl itself.
168
169       The full text of the license can be found in the LICENSE file included
170       with this module.
171
172
173
174perl v5.28.0                      2011-08-16Padre::Document::Perl::Beginner(3)
Impressum