2 ##############################################################################
3 # $URL: http://perlcritic.tigris.org/svn/perlcritic/trunk/Perl-Critic/t/Variables/RequireLocalizedPunctuationVars.run.PL $
4 # $Date: 2008-06-06 00:48:04 -0500 (Fri, 06 Jun 2008) $
7 ##############################################################################
13 use English qw(-no_match_vars);
17 use List::MoreUtils qw< apply uniq >;
19 my $this_program = __FILE__;
20 (my $test_file_name = $this_program) =~ s/ \.PL \z //xms;
21 if ($this_program eq $test_file_name) {
23 'Was not able to figure out the name of the file to generate.'
24 . "This program: $this_program.";
27 print "\n\nGenerating $test_file_name.\n";
31 open my $test_file, '>', $test_file_name
32 or die "Could not open $test_file_name: $ERRNO";
37 @B::Keywords::Scalars,
39 push @globals, uniq apply { s/ \A ([^*]) /*$1/xms } @B::Keywords::Filehandles;
40 my %exceptions = map {$_ => 1} qw(
46 my $carat_re = qr/\A [\$%]\^\w+ /xms;
48 my $numvars = @globals - keys %exceptions;
49 my $numcarats = grep {!$exceptions{$_} && m/ $carat_re /xms} @globals;
51 print {$test_file} <<'EOF';
53 ## name Named magic variables, special case passes
58 local $SIG{__DIE__} = sub { print "AAAAAAARRRRRGGGGHHHHH....\n"; };
63 #-----------------------------------------------------------------------------
65 ## name Named magic variables, special case failures
67 ## TODO we are not handling dereferences yet...
70 $SIG{__DIE__} = sub { print "AAAAAAARRRRRGGGGHHHHH....\n"; };
72 #-----------------------------------------------------------------------------
74 ## name Named magic variables, pass local
80 for my $varname (@globals) {
81 print {$test_file} "local $varname = ();\n";
84 print {$test_file} <<"EOF";
86 #-----------------------------------------------------------------------------
88 ## name Named magic variables, pass local()
94 for my $varname (@globals) {
95 print {$test_file} "local ($varname) = ();\n";
98 print {$test_file} <<"EOF";
100 #-----------------------------------------------------------------------------
102 ## name Named magic variables, pass (local)
108 for my $varname (@globals) {
109 print {$test_file} "(local $varname) = ();\n";
112 print {$test_file} <<"EOF";
114 #-----------------------------------------------------------------------------
116 ## name Named magic variables, pass = (local) =
122 for my $varname (@globals) {
123 print {$test_file} "\@foo = (local $varname) = ();\n";
126 print {$test_file} <<"EOF";
128 #-----------------------------------------------------------------------------
130 ## name Named magic variables, fail non-local, non-carats
131 ## failures @{[$numvars - $numcarats]}
136 for my $varname (@globals) {
137 next if $exceptions{$varname};
138 next if $varname =~ m/ $carat_re /xms;
139 print {$test_file} "$varname = ();\n";
142 print {$test_file} <<"EOF";
144 #-----------------------------------------------------------------------------
146 ## name Named magic variables, fail non-local, carats
147 ## failures $numcarats
152 for my $varname (@globals) {
153 next if $exceptions{$varname};
154 next if $varname !~ m/ $carat_re /xms;
155 print {$test_file} "$varname = ();\n";
158 print {$test_file} <<"EOF";
160 #-----------------------------------------------------------------------------
162 ## name Named magic variables, fail non-local, carats, no space
163 ## failures $numcarats
168 for my $varname (@globals) {
169 next if $exceptions{$varname};
170 next if $varname !~ m/ $carat_re /xms;
171 print {$test_file} "$varname= ();\n";
174 print {$test_file} <<"EOF";
176 #-----------------------------------------------------------------------------
178 ## name Named magic variables, fail = (non-local) =
184 for my $varname (@globals) {
185 next if $exceptions{$varname};
186 print {$test_file} "\@foo = ($varname) = ();\n";
189 print {$test_file} <<"EOF";
191 #-----------------------------------------------------------------------------
193 ## name Named magic variables, fail (non-local)
199 for my $varname (@globals) {
200 next if $exceptions{$varname};
201 print {$test_file} "($varname) = ();\n";
205 print {$test_file} <<'EOF';
207 #-----------------------------------------------------------------------------
209 ## name Allow "my" as well, RT #33937
215 my @a = split m{,}xms, $a;
216 my @b = split m{,}xms, $b;
217 $a[0] cmp $b[0] || $a[1] <=> $b[1]
224 #-----------------------------------------------------------------------------
226 ##############################################################################
231 ##############################################################################
235 # cperl-indent-level: 4
237 # indent-tabs-mode: nil
238 # c-indentation-style: bsd
240 # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :