Debian Codegraph @

t/scan/re.t

raw
1 use strict;
2 use warnings;
3 use FindBin;
4 use lib "$FindBin::Bin/../../";
5 use t::scan::Util;
6
7 test(<<'TEST'); # ZDM/Pcore-v0.31.4/lib/Pcore/App/Controller/API.pm
8 my $method_id = $tx->{action} ? q[/] . ( $tx->{action} =~ s[[.]][/]smgr ) . "/$tx->{method}" : $tx->{method};
9 TEST
10
11 test(<<'TEST');
12 while ( $message =~ m{((!)?(?:https?:)(?://[^\s/?#]*)[^\s?#]*(?:\?[^\s#]*)?(?:#.*)?)}g ) {
13 }
14 TEST
15
16 test(<<'TEST'); # FIVE/Mail-MsgStore-1.51/MsgStore.pm
17 sub msgpath
18 {
19 local $_= shift;
20 return '/' if m<^[@*/!?\\]$>; # convenience root
21 return if /^[<|>].*[<|>]$/; # not a path
22 s</{2,}|\\></>g; # clean path
23 return $_ if -d "$mailroot/$_"
24 or s</$><> or not m<^\W?(.*)/(mail[^/]+mail)$>i;
25 return($1,$2);
26 }
27 TEST
28
29 test(<<'TEST'); # AUTRIJUS/Pod-HtmlHelp-1.1/WinHtml.pm
30 $rest =~ s{
31 \b # start at word boundary
32 ( # begin $1 {
33 $urls : # need resource and a colon
34 [$any] +? # followed by on or more
35 # of any valid character, but
36 # be conservative and take only
37 # what you need to....
38 ) # end $1 }
39 (?= # look-ahead non-consumptive assertion
40 [$punc]* # either 0 or more puntuation
41 [^$any] # followed by a non-url char
42 | # or else
43 $ # then end of the string
44 )
45 }{<A HREF="$1">$1</A>}igox;
46 TEST
47
48 test(<<'TEST'); # ROSSI/LaTeX-Authors-0.81/Authors.pm
49 my @list_file_sdir = <*/*.tex>;
50 my @list_file = (@list_file_dir,@list_file_sdir);
51 my $nbr_file = @list_file;
52
53 my $tex_file;
54
55 if ($nbr_file == 1) {
56 $tex_file = $list_file[0];
57 } elsif ($nbr_file > 1) {
58 foreach (@list_file) {
59 open(FILEGREP,"$_");
60 my $tempo_file = $_;
61 while (<FILEGREP>) {
62 s/(^\s*|[^\\])%.*/$1/g;
63 s/^\s*\n$//g;
64 if ((/\\begin\{document\}/) || (/\\bye/) || (/\\documentstyle/) ) {
65 $tex_file = $tempo_file;
66 last;
67 }
68 }
69
70 }
71 }
72 TEST
73
74 test(<<'TEST'); # MICB/wing-0.9/Wing.pm
75 my ($loc, $handler, $username, $url_session, $cmd, @args)
76 = split(m(/), $r->path_info);
77 TEST
78
79 test(<<'TEST'); # DCONWAY/Perl6-Rules-0.03/Rules.pm
80 our $charset = qr{ \[ \]? (?:\\[cCxX]\[ [^]]* \]|\\.|[^]])* \] }xs;
81 TEST
82
83 test(<<'TEST'); # DCONWAY/Perl6-Rules-0.03/Rules.pm
84 our $codeblock = qr{
85 (?{$debug = 2 if $debug})
86 (\{) (?{mark($^N)})
87 (?>
88 (?: ($i_scalar) (?{addscalar_internal $^N, 'rw'})
89 | ($e_scalar) (?{addscalar_external $^N, 'rw'})
90 | ($i_array) (?{addarray_internal $^N, 'rw'})
91 | ($e_array) (?{addarray_external $^N, 'rw'})
92 | ($i_hash) (?{addhash_internal $^N, 'rw'})
93 | ($e_hash) (?{addhash_external $^N, 'rw'})
94 | \$ (\d+) (?{add '$'.$^N, "\$Perl6::Rules::d0[$^N]"})
95 | ((?:\$\^\w+|[^{}\$]|\\[{}\$])+) (?{add $^N, $^N})
96 | (??{$nestedcodeblock})
97 )*
98 )
99 (?{$debug = 1 if $debug})
100 (\}) (?{codeblock($^N)})
101 |
102 (??{$debug=1 if $debug;'(?!)'})
103 }x;
104 TEST
105
106 test(<<'TEST'); # DCONWAY/Perl6-Rules-0.03/Rules.pm
107 our $bspat = qr{ # Bracketed and Slashed patterns
108
109 # Explicit whitespace (possibly repeated)...
110
111 $ows ($ews)
112 (?{add $^N, $ews{$^N}})
113 $stdrep $ows
114
115 # Actual whitespace (insert :words spacing if in appropriate mode)...
116
117 | $ws
118 (?{wordspace})
119
120 # Backreference as literal (interpolated $1, $2, etc.)...
121
122 | \$ (\d+)
123 (?{add '$'.$^N, "(??{quotemeta \$Perl6::Rules::d0[$^N]})"})
124 $stdrep
125
126 # Interpolated variable as literal...
127
128 | ($i_scalar) (?{ addscalar_internal $^N, 'quotemeta' }) $stdrep
129 | ($i_array) (?{ addarray_internal $^N, 'quotemeta' }) $stdrep
130 | ($i_hash) (?{ addhash_internal $^N, 'quotemeta' }) $stdrep
131 | ($e_scalar) (?{ addscalar_external $^N, 'quotemeta' }) $stdrep
132 | ($e_array) (?{ addarray_external $^N, 'quotemeta' }) $stdrep
133 | ($e_hash) (?{ addhash_external $^N, 'quotemeta' }) $stdrep
134 | ($bad_var) (?{error("Can't use unqualified variable ($^N)")})
135
136 # Character class...
137
138 | < (?: ([+-]?) (?{$^N||""}) ($charset)
139 (?{mark ""; add "<$^R.$^N", transcharset($^N, $^R)})
140 | ([+-]?) (?{$^N||""}) < ([-!]? $ident) >
141 (?{mark ""; add "<$^R.$^N", getprop($^N, $^R)})
142 )
143 (?: ([+-]?) (?{$^N||""}) ($charset)
144 (?{add "$^R.$^N", transcharset($^N, $^R)})
145 | ([+-]?) (?{$^N||""}) < ([-!]? $ident) >
146 (?{add "$^R.$^N", getprop($^N, $^R)})
147 )*
148 >
149 (?{make_charset})
150 $stdrep
151
152 # <(...)> assertion block...
153
154 | $assertblock
155
156 # Backreference as pattern (interpolated <$1>, <$2>, etc.)...
157
158 | <(\$ \d+)>
159 (?{add "<$^N>", error("Cannot interpolate $^N as pattern")})
160
161 # Interpolate variable as pattern...
162
163 | <($i_scalar)> (?{addscalar_internal $^N}) $stdrep
164 | <($i_array)> (?{addarray_internal $^N}) $stdrep
165 | <($i_hash)> (?{addhash_internal $^N}) $stdrep
166 | <($e_scalar)> (?{addscalar_external $^N}) $stdrep
167 | <($e_array)> (?{addarray_external $^N}) $stdrep
168 | <($e_hash)> (?{addhash_external $^N}) $stdrep
169 | <($bad_var)> (?{error("Can't use unqualified variable (<$^N>)")})
170
171 # Code block as action...
172
173 | $codeblock
174
175 # Code block as interpolated pattern...
176
177 | <($braceblock)>
178 (?{add $^N, "(??{Perl6::Rules::ispat do$^N})"})
179
180 # Literal in <'...'> format...
181
182 | <' ( [^'\\]* (\\. [^'\\])* ) '>
183 (?{add "<'$^N'>", "\Q$^N\E"})
184
185 # Match any Unicode character, regardless of :uN level...
186
187 | (< \. >)
188 (?{add $^N, '(?:\X)'})
189
190 # Match newline or anything-but-newline...
191
192 | \\n
193 (?{add '\n', $newline}) $stdrep
194 | \\N
195 (?{add '\N', $notnewline}) $stdrep
196
197 # Quotemeta's literal (\Q[...])...
198
199 | \\Q ( $squareblock )
200 (?{add "\\Q$^N", quotemeta substr($^N,1,-1)}) $stdrep
201
202 # Named and numbered characters (\c[...], \C[...], \x[...], \0[...], etc)...
203
204 | ( \\[cCxX0] $squareblock
205 | \\[xX][0-9A-Fa-f]+
206 | \\0[0-7]+
207 )
208 (?{add $^N, transchars($^N)}) $stdrep
209
210 | (\\[cCxX0] \[) (?{$^N}) ((?>.*))
211 (?{error "Untermimated $^R...] escape: $^R$^N"})
212
213 # Literal dot...
214
215 | (\\.)
216 (?{add $^N, $^N}) $stdrep
217
218 # Backtracking limiter...
219
220 | : (?=\s|\z)
221 (?{nobacktrack})
222
223 # Lexical insensitivity...
224
225 | :i
226 (?{add ":i", '(?i)'})
227
228 # Continuation marker...
229
230 | :c (?{add '\G'})
231
232 # Other lexical flags (NOT YET IMPLEMENTED)...
233
234 | :(u0|u1|u2|u3|w|p5)
235 (?{error "In-pattern :$^N not yet implemented"})
236
237 # Match any character...
238
239 | \.
240 (?{add '.', '[\s\S]'}) $stdrep
241
242 # Start of line marker...
243
244 | \^\^
245 (?{add '^^', '(?:(?<=\n)|(?<=\A))'})
246
247 # End of line marker...
248
249 | \$\$
250 (?{add '$$', '(?:(?<=\n)|(?=\z))'})
251
252 # Start of string marker...
253
254 | \^
255 (?{add '^', '\A'})
256
257 # End of string marker...
258
259 | \$
260 (?{add '$', '\z'})
261
262 # Non-capturing subrule or property...
263
264 | < ($callident) >
265 (?{subrule($^N,"")}) $stdrep
266
267 | < - ($callident) >
268 (?{subrule($^N,"","","-")}) $stdrep
269
270 | < ! ($callident) >
271 (?{subrule($^N,"","","!")}) $stdrep
272
273 # Capturing subrule...
274
275 | < \? ($callident) >
276 (?{$Perl6::Rules::srname=$^N})
277 $ows $rep
278 (?{ subrule($Perl6::Rules::srname, $^N, "cap")})
279 | < \? ($callident) >
280 (?{ subrule($^N, "", "cap")})
281
282 # Alternative marker...
283
284 | \|
285 (?{alternative})
286
287 # Comment...
288
289 | $comment
290
291 # Unattached repetition marker...
292
293 | ($orep)
294 (?{$^N&&badrep()})
295
296 }x;
297 TEST
298
299 test(<<'TEST'); # MLEHMANN/Games-Sokoban-1.01/Sokoban.pm
300 for ($self->{data} = join "\n", @data) {
301 s/#$//mg until /[^#]#$/m; # right
302 s/^#//mg until /^#[^#]/m; # left
303 }
304 TEST
305
306 test(<<'TEST'); # KARASIK/Prima-1.39/Prima/Edit.pm
307 sub set_hilite_res
308 {
309 my ($self, $hi) = @_;
310 if ( $hi) {
311 push @{$hi}, cl::Fore if scalar @{$hi} / 2 != 0;
312 $hi = [@{$hi}];
313 }
314 $self-> {hiliteREs} = $hi;
315 if ( $self-> {syntaxHilite}) {
316 $self-> reset_syntaxer;
317 $self-> repaint;
318 }
319 }
320
321 sub set_insert_mode
322 {
323 my ( $self, $insert) = @_;
324 my $oi = $self-> {insertMode};
325 $self-> {insertMode} = $insert;
326 $self-> reset_cursor if $oi != $insert;
327 $::application-> insertMode( $insert);
328 $self-> push_group_undo_action( 'insertMode', $oi) if $oi != $insert;
329 }
330
331
332 sub set_offset
333 {
334 my ( $self, $offset) = @_;
335 $offset = 0 if $offset < 0;
336 $offset = 0 if $self-> {wordWrap};
337 return if $self-> {offset} == $offset;
338 if ( $self-> {delayPanning}) {
339 $self-> {delay_offset} = $offset;
340 return;
341 }
342 my $dt = $offset - $self-> {offset};
343 $self-> push_group_undo_action( 'offset', $self-> {offset});
344 $self-> {offset} = $offset;
345 if ( $self-> {hScroll} && $self-> {scrollTransaction} != 2) {
346 $self-> {scrollTransaction} = 2;
347 $self-> {hScrollBar}-> value( $offset);
348 $self-> {scrollTransaction} = 0;
349 }
350 $self-> reset_cursor;
351 $self-> scroll( -$dt, 0,
352 clipRect => [ $self-> get_active_area]);
353 }
354
355
356 sub set_selection
357 {
358 my ( $self, $sx, $sy, $ex, $ey) = @_;
359 my $maxY = $self-> {maxLine};
360 my ( $osx, $osy, $oex, $oey) = $self-> selection;
361 my $onsel = ( $osx == $oex && $osy == $oey);
362 if ( $maxY < 0) {
363 $self-> {selStart} = [0,0];
364 $self-> {selEnd} = [0,0];
365 $self-> {selStartl} = [0,0];
366 $self-> {selEndl } = [0,0];
367 $self-> repaint unless $onsel;
368 return;
369 }
370 $sy = $maxY if $sy < 0 || $sy > $maxY;
371 $ey = $maxY if $ey < 0 || $ey > $maxY;
372 ( $sy, $ey, $sx, $ex) = ( $ey, $sy, $ex, $sx) if $sy > $ey;
373 $osx = $oex = $sx, $osy = $oey = $ey if $onsel;
374 if ( $sx == $ex && $sy == $ey) {
375 $osy = $maxY if $osy < 0 || $osy > $maxY;
376 $oey = $maxY if $oey < 0 || $oey > $maxY;
377 $sx = $ex = $osx;
378 $sy = $ey = $osy;
379 }
380 my ($firstChunk, $lastChunk) = ( $self-> get_line( $sy), $self-> get_line( $ey));
381 my ($fcl, $lcl) = ( length( $firstChunk), length( $lastChunk));
382 my $bt = $self-> {blockType};
383 $sx = $fcl if ( $bt != bt::Vertical && $sx > $fcl) || ( $sx < 0);
384 $ex = $lcl if ( $bt != bt::Vertical && $ex > $lcl) || ( $ex < 0);
385 ( $sx, $ex) = ( $ex, $sx) if $sx > $ex && (( $sy == $ey && $bt == bt::CUA) || ( $bt == bt::Vertical));
386 my ( $lsx, $lsy) = $self-> make_logical( $sx, $sy);
387 my ( $lex, $ley) = $self-> make_logical( $ex, $ey);
388 ( $lsx, $lex) = ( $lex, $lsx) if $lsx > $lex && (( $lsy == $ley && $bt == bt::CUA) || ( $bt == bt::Vertical));
389 $sy = $ey if $sx == $ex and $bt == bt::Vertical;
390 my ( $_osx, $_osy) = @{$self-> {selStartl}};
391 my ( $_oex, $_oey) = @{$self-> {selEndl}};
392 $self-> {selStart} = [ $sx, $sy];
393 $self-> {selStartl} = [ $lsx, $lsy];
394 $self-> {selEnd} = [ $ex, $ey];
395 $self-> {selEndl} = [ $lex, $ley];
396 return if $sx == $osx && $ex == $oex && $sy == $osy && $ey == $oey;
397 return if $sx == $ex && $sy == $ey && $onsel;
398 $self-> push_group_undo_action('selection', $osx, $osy, $oex, $oey);
399 ( $osx, $osy, $oex, $oey) = ( $_osx, $_osy, $_oex, $_oey);
400 ( $sx, $sy) = @{$self-> {selStartl}};
401 ( $ex, $ey) = @{$self-> {selEndl}};
402 $osx = $oex = $sx, $osy = $oey = $ey if $onsel;
403 if (( $osy > $ey && $oey > $ey) || ( $oey < $sy && $oey < $sy))
404 {
405 $self-> repaint;
406 return;
407 }
408 # connective selection
409 my ( $start, $end);
410 if ( $bt == bt::CUA || ( $sx == $osx && $ex == $oex)) {
411 if ( $sy == $osy) {
412 if ( $ey == $oey) {
413 if ( $sx == $osx) {
414 $start = $end = $ey;
415 } elsif ( $ex == $oex) {
416 $start = $end = $sy;
417 } else {
418 ($start, $end) = ( $sy, $ey);
419 }
420 } else {
421 ( $start, $end) = ( $ey < $oey) ? ( $ey, $oey) : ( $oey, $ey);
422 }
423 } elsif ( $ey == $oey) {
424 ( $start, $end) = ( $sy < $osy) ? ( $sy, $osy) : ( $osy, $sy);
425 } else {
426 $start = ( $sy < $osy) ? $sy : $osy;
427 $end = ( $ey > $oey) ? $ey : $oey;
428 }
429 } else {
430 $start = ( $sy < $osy) ? $sy : $osy;
431 $end = ( $ey > $oey) ? $ey : $oey;
432 }
433 my ( $ofs, $tl, $fh, $r, $yT) = (
434 $self-> {offset}, $self-> {topLine },
435 $self-> font-> height, $self-> {rows},
436 $self-> {yTail}
437 );
438 my @a = $self-> get_active_area( 0);
439 return if $end < $tl || $start >= $tl + $r + $yT;
440 if ( $start == $end && $bt == bt::CUA) {
441 # single connective line paint
442 my $chunk;
443 my ( $xstart, $xend);
444 if ( $sx == $osx) {
445 ( $xstart, $xend) = ( $ex < $oex) ? ( $ex, $oex) : ( $oex, $ex);
446 } elsif ( $ex == $oex) {
447 ( $xstart, $xend) = ( $sx < $osx) ? ( $sx, $osx) : ( $osx, $sx);
448 } else {
449 $xstart = ( $sx < $osx) ? $sx : $osx;
450 $xend = ( $ex > $oex) ? $ex : $oex;
451 }
452 unless ( $self-> {wordWrap}) {
453 if ( $start == $sy) {
454 $chunk = $firstChunk;
455 } elsif ( $start == $ey) {
456 $chunk = $lastChunk;
457 } else {
458 $chunk = $self-> get_chunk( $start);
459 }
460 } else {
461 $chunk = $self-> get_chunk( $start);
462 }
463 $self-> invalidate_rect(
464 $a[0] - $ofs + $self-> get_chunk_width( $chunk, 0, $xstart) - 1,
465 $a[3] - $fh * ( $start - $tl + 1),
466 $a[0] - $ofs + $self-> get_chunk_width( $chunk, 0, $xend),
467 $a[3] - $fh * ( $start - $tl)
468 );
469 } else {
470 # general connected lines paint
471 $self-> invalidate_rect(
472 $a[0], $a[3] - $fh * ( $end - $tl + 1),
473 $a[2], $a[3] - $fh * ( $start - $tl),
474 );
475 }
476 }
477
478 sub set_tab_indent
479 {
480 my ( $self, $ti) = @_;
481 $ti = 0 if $ti < 0;
482 $ti = 256 if $ti > 256;
483 return if $ti == $self-> {tabIndent};
484 $self-> {tabIndent} = $ti;
485 $self-> reset;
486 $self-> repaint;
487 }
488
489 sub set_syntax_hilite
490 {
491 my ( $self, $sh) = @_;
492 $sh = 0 if $self-> {wordWrap};
493 return if $sh == $self-> {syntaxHilite};
494 $self-> {syntaxHilite} = $sh;
495 $self-> reset_syntaxer if $sh;
496 $self-> reset_syntax;
497 $self-> repaint;
498 }
499
500 sub set_word_wrap
501 {
502 my ( $self, $ww) = @_;
503 return if $ww == $self-> {wordWrap};
504 $self-> {wordWrap} = $ww;
505 $self-> syntaxHilite(0) if $ww;
506 $self-> reset;
507 $self-> reset_scrolls;
508 $self-> repaint;
509 }
510
511 sub cut
512 {
513 my $self = $_[0];
514 return if $self-> {readOnly};
515 $self-> begin_undo_group;
516 $self-> copy;
517 $self-> delete_block;
518 $self-> end_undo_group;
519 }
520
521 sub copy
522 {
523 my $self = $_[0];
524 my $text = $self-> get_selected_text;
525 $::application-> Clipboard-> text($text) if defined $text;
526 }
527
528 sub get_selected_text
529 {
530 my $self = $_[0];
531 return undef unless $self-> has_selection;
532 my @sel = $self-> selection;
533 my $text = '';
534 my $bt = $self-> blockType;
535 if ( $bt == bt::CUA) {
536 if ( $sel[1] == $sel[3]) {
537 $text = substr( $self-> get_line( $sel[1]), $sel[0], $sel[2] - $sel[0]);
538 } else {
539 my $c = $self-> get_line( $sel[1]);
540 $text = substr( $c, $sel[0], length( $c) - $sel[0])."\n";
541 my $i;
542 for ( $i = $sel[1] + 1; $i < $sel[3]; $i++) {
543 $text .= $self-> get_line( $i)."\n";
544 }
545 $c = $self-> get_line( $sel[3]);
546 $text .= substr( $c, 0, $sel[2]);
547 }
548 } elsif ( $bt == bt::Horizontal) {
549 my $i;
550 for ( $i = $sel[1]; $i <= $sel[3]; $i++) {
551 $text .= $self-> get_line( $i)."\n";
552 }
553 } else {
554 my $i;
555 for ( $i = $sel[1]; $i <= $sel[3]; $i++) {
556 my $c = $self-> get_line( $i);
557 my $cl = $sel[2] - length( $c);
558 $c .= ' 'x$cl if $cl > 0;
559 $text .= substr($c, $sel[0], $sel[2] - $sel[0])."\n";
560 }
561 chomp( $text);
562 }
563 return $text;
564 }
565
566 sub lock_change
567 {
568 my ( $self, $lock) = @_;
569 $lock = $lock ? 1 : -1;
570 $self-> {notifyChangeLock} += $lock;
571 $self-> {notifyChangeLock} = 0 if $lock > 0 && $self-> {notifyChangeLock} < 0;
572 $self-> notify(q(Change)) if $self-> {notifyChangeLock} == 0 && $lock < 0;
573 }
574
575 sub change_locked
576 {
577 my $self = $_[0];
578 return $self-> {notifyChangeLock} != 0;
579 }
580
581 sub insert_text
582 {
583 my ( $self, $s, $hilite) = @_;
584 return if !defined($s) or length( $s) == 0;
585 $self-> begin_undo_group;
586 $self-> cancel_block unless $self-> {blockType} == bt::CUA;
587 my @cs = $self-> cursor;
588 my @ln = split( "\n", $s, -1);
589 pop @ln unless length $ln[-1];
590 $s = $self-> get_line( $cs[1]);
591 my $cl = $cs[0] - length( $s);
592 $s .= ' 'x$cl if $cl > 0;
593 $cl = 0 if $cl < 0;
594 $self-> lock_change(1);
595 if ( scalar @ln == 1) {
596 substr( $s, $cs[0], 0) = $ln[0];
597 $self-> set_line( $cs[1], $s, q(add), $cs[0], $cl + length( $ln[0]));
598 $self-> selection( $cs[0], $cs[1], $cs[0] + length( $ln[0]), $cs[1])
599 if $hilite && $self-> {blockType} == bt::CUA;
600 } else {
601 my $spl = substr( $s, $cs[0], length( $s) - $cs[0]);
602 substr( $s, $cs[0], length( $s) - $cs[0]) = $ln[0];
603 $self-> lock;
604 $self-> set_line( $cs[1], $s);
605 shift @ln;
606 $self-> insert_line( $cs[1] + 1, (@ln, $spl));
607 $self-> selection( $cs[0], $cs[1], length( $ln[-1]), $cs[1]+scalar(@ln))
608 if $hilite && $self-> {blockType} == bt::CUA;
609 $self-> unlock;
610 }
611 $self-> lock_change(0);
612 $self-> end_undo_group;
613 }
614
615 sub paste
616 {
617 my $self = $_[0];
618 return if $self-> {readOnly};
619 $self-> insert_text( $::application-> Clipboard-> text, 1);
620 }
621
622 sub make_logical
623 {
624 my ( $self, $x, $y) = @_;
625 return (0,0) if $self-> {maxChunk} < 0;
626 return $x, $y unless $self-> {wordWrap};
627 my $maxY = $self-> {maxLine};
628 $y = $maxY if $y > $maxY || $y < 0;
629 $y = 0 if $y < 0;
630 my $l = length( $self-> {lines}-> [$y]);
631 $x = $l if $x < 0 || $x > $l;
632 $x = 0 if $x < 0;
633 my $cm = $self-> {chunkMap};
634 my $r;
635 ( $l, $r) = ( 0, $self-> {maxChunk} + 1);
636 my $i = int($r / 2);
637 my $kk = 0;
638 while (1) {
639 my $acd = $$cm[$i * 3 + 2];
640 last if $acd == $y;
641 $acd > $y ? $r : $l = $i;
642 $i = int(( $l + $r) / 2);
643 if ( $kk++ > 200) {
644 print "bcs dump to $y\n";
645 ( $l, $r) = ( 0, $self-> {maxChunk} + 1);
646 $i = int($r / 2);
647 for ( $kk = 0; $kk < 7; $kk++) {
648 my $acd = $$cm[$i * 3 + 2];
649 print "i:$i [$l $r] f() = $acd\n";
650 $acd > $y ? $r : $l = $i;
651 $i = int(( $l + $r) / 2);
652 }
653 die;
654 last;
655 }
656 }
657 $y = $i;
658 $i *= 3;
659 $i-= 3, $y-- while $$cm[ $i] != 0;
660 $i+= 3, $y++ while $x > $$cm[ $i] + $$cm[ $i + 1];
661 $x -= $$cm[ $i];
662 return $x, $y;
663 }
664 TEST
665
666 test(<<'TEST'); # CHM/PDL-2.015/Doc/Doc.pm
667 for (@funcs) {
668 $sym->{$1}->{Module} = $this->{NAME} if m/\s*([^\s(]+)\s*/;
669 $sym->{$1}->{Sig} = $2 if m/\s*([^\s(]+)\s*\(\s*(.+)\s*\)\s*$/;
670 }
671 TEST
672
673 test(<<'TEST'); # BIGJ/Lingua-DE-ASCII-0.11/ASCII.pm
674 {no warnings;
675 s/((?:${prefix}|en)s)?(([tT])�n(de?|\b))(?!chen|lein|lich)
676 /$1 ? "$1$2" : "$3uen$4"/xgeo;# Gro�tuende, but abst�nde, St�ndchen
677 }
678 s/($prefix s? t)�(r(ische?[mnrs]?|
679 i?[ns](nen)?)?\b)/$1ue$2/gx;
680 TEST
681
682 test(<<'TEST'); # KARASIK/Prima-1.39/Prima/FileDialog.pm
683 unless ( scalar @fs) {
684 $self-> path('.'), return unless $p =~ tr{/\\}{} > 1;
685 $self-> {path} =~ s{[/\\][^/\\]+[/\\]?$}{/};
686 $self-> path('.'), return if $p eq $self-> {path};
687 $self-> path($self-> {path});
688 return;
689 }
690 TEST
691
692 test(<<'TEST'); # CINDY/Plack-Middleware-Session-SerializedCookie-1.03/t/Common.pm
693 for( 0 .. int($#{$res->[1]}/2) ) {
694 if( $res->[1][$_*2] =~ /^Set-Cookie$/i ) {
695 $res->[1][$_*2+1] =~ /([^;]*)/;
696 $cookie .= "$1;";
697 }
698 }
699 TEST
700
701 test(<<'TEST'); # DUKKIE/FarmBalance-0.03/lib/FarmBalance.pm
702 sub arrange_array {
703 my ( $self, $arrayref) = @_;
704 my $sum = $self->array_val_sum($arrayref);
705 my $kei = $self->{'percent'} / $sum;
706 my @nums_new = map { $_ * $kei } @{$arrayref};
707 return \@nums_new;
708 }
709
710 #- return standard deviation
711 sub sd {
712 my ( $self, $arrayref ) = @_;
713 my $avg = $self->average($arrayref);
714 my $ret = 0;
715 for (@{$arrayref}) {
716 $ret += ($_ - $avg)**2;
717 }
718 return ( $ret/($#$arrayref + 1));
719 }
720 sub average {
721 my ( $self, $arrayref) = @_;
722 my $sum = $self->array_val_sum($arrayref);
723 return ( $sum / ( $#$arrayref + 1) );
724 }
725 TEST
726
727 test(<<'TEST'); # SJCARBON/go-db-perl-0.04/GO/Tango.pm
728 foreach my $k (@k) {
729 print STDERR " key=$k\n";
730 next if $domainh->{$k} < 2;
731 # bayes
732 # p = (p(ipr|t) * p(t)) / p(ipr)
733 my $prob =
734 (($domainh->{$k} / scalar(@$pl)) * (scalar(@$pl) / scalar(@allids))) /
735 ($dc{$k} / scalar(@allids));
736 printf "$neg [$prob] %s $k $got{$k} $domainh->{$k} / %d\n", $term->name, scalar @$pl;
737 if ($prob > 0.8 && $domainh->{$k} > 4) {
738 push(@rules, $term->acc." $k $prob $domainh->{$k}/".(scalar @$pl));
739 }
740 $probh{$k} = $prob;
741 }
742 TEST
743
744 test(<<'TEST'); # BURAK/Scalar-Util-Reftype-0.40/builder/Build.pm
745 printf $W q/BEGIN { $INC{$_} = 1 for qw(%s); }/, join(' ', @inc_files);
746 print $W "\n";
747
748 foreach my $name ( @packages ) {
749 print $W qq/package $name;\nsub ________monolith {}\n/;
750 }
751 TEST
752
753 test(<<'TEST'); # VLADO/AI-NaiveBayes1-2.006/NaiveBayes1.pm
754 foreach my $label (keys(%{$self->{stat_labels}}))
755 { $m->{labelprob}{$label} = $self->{stat_labels}{$label} /
756 $self->{numof_instances} }
757
758 $m->{condprob} = {};
759 $m->{condprobe} = {};
760 foreach my $att (keys(%{$self->{stat_attributes}})) {
761 next if $self->{attribute_type}{$att} eq 'real';
762 $m->{condprob}{$att} = {};
763 $m->{condprobe}{$att} = {};
764 foreach my $label (keys(%{$self->{stat_labels}})) {
765 my $total = 0; my @attvals = ();
766 foreach my $attval (keys(%{$self->{stat_attributes}{$att}})) {
767 next unless
768 exists($self->{stat_attributes}{$att}{$attval}{$label}) and
769 $self->{stat_attributes}{$att}{$attval}{$label} > 0;
770 push @attvals, $attval;
771 $m->{condprob}{$att}{$attval} = {} unless
772 exists( $m->{condprob}{$att}{$attval} );
773 $m->{condprob}{$att}{$attval}{$label} =
774 $self->{stat_attributes}{$att}{$attval}{$label};
775 $m->{condprobe}{$att}{$attval} = {} unless
776 exists( $m->{condprob}{$att}{$attval} );
777 $m->{condprobe}{$att}{$attval}{$label} =
778 $self->{stat_attributes}{$att}{$attval}{$label};
779 $total += $m->{condprob}{$att}{$attval}{$label};
780 }
781 if (exists($self->{smoothing}{$att}) and
782 $self->{smoothing}{$att} =~ /^unseen count=/) {
783 my $uc = $'; $uc = 0.5 if $uc <= 0;
784 if(! exists($m->{condprob}{$att}{'*'}) ) {
785 $m->{condprob}{$att}{'*'} = {};
786 $m->{condprobe}{$att}{'*'} = {};
787 }
788 $m->{condprob}{$att}{'*'}{$label} = $uc;
789 $total += $uc;
790 if (grep {$_ eq '*'} @attvals) { die }
791 push @attvals, '*';
792 }
793 foreach my $attval (@attvals) {
794 $m->{condprobe}{$att}{$attval}{$label} =
795 "(= $m->{condprob}{$att}{$attval}{$label} / $total)";
796 $m->{condprob}{$att}{$attval}{$label} /= $total;
797 }
798 }
799 }
800 TEST
801
802 test(<<'TEST'); # AKSTE/Data-ShowTable-4.6/ShowTable.pm
803 sub PlainText {
804 local($_) = shift if $#_ >= 0; # set local $_ if there's an argument
805 # skip unless there's a sequence
806 return $_ unless m=</?($HTML_Elements)=i; # HTML text?
807 s{</?(?:$HTML_Elements)# # match and remove any HTML token..
808 (?:\ \w+# # ..then PARAM or PARAM=VALUE
809 (?:\=(?:"(?:[^"]|\\")*"|# # ...."STRING" or..
810 [^"> ]+# # ....VALUE
811 )#
812 )?# # ..=VALUE is optional
813 )*# # zero or more PARAM or PARAM=VALUE
814 >}{}igx; # up to the closing '>'
815 $_; # return the result
816 }
817 TEST
818
819 test(<<'TEST'); # TEEJAY/Math-Curve-Hilbert-0.04/Hilbert.pm
820 if ($args{clockwise}) {
821 if ($args{max} == $this_level) {
822 $$y -= $step; push (@$coords,{X=>$$x,Y=>$$y});
823 $self->{curve}{"$$x:$$y"} = $#$coords;
824 $$x += $step; push (@$coords,{X=>$$x,Y=>$$y});
825 $self->{curve}{"$$x:$$y"} = $#$coords;
826 $$y += $step; push (@$coords,{X=>$$x,Y=>$$y});
827 $self->{curve}{"$$x:$$y"} = $#$coords;
828 } else {
829 foreach (@{$self->right(X=>$x,Y=>$y,level=>$this_level,max=>$args{max})}) {
830 push (@$coords,$_);
831 $self->{curve}{"$_->{X}:$_->{Y}"} = $#$coords;
832 }
833 $$y -= $step; push (@$coords,{X=>$$x,Y=>$$y});
834 $self->{curve}{"$$x:$$y"} = $#$coords;
835 foreach (@{$self->up(clockwise=>1,X=>$x,Y=>$y,level=>$this_level,max=>$args{max})}) {
836 push (@$coords,$_);
837 $self->{curve}{"$_->{X}:$_->{Y}"} = $#$coords;
838 }
839 $$x += $step; push (@$coords,{X=>$$x,Y=>$$y});
840 $self->{curve}{"$$x:$$y"} = $#$coords;
841 foreach (@{$self->up(clockwise=>1,X=>$x,Y=>$y,level=>$this_level,max=>$args{max})}) {
842 push (@$coords,$_);
843 $self->{curve}{"$_->{X}:$_->{Y}"} = $#$coords;
844 }
845 $$y += $step; push (@$coords,{X=>$$x,Y=>$$y});
846 $self->{curve}{"$$x:$$y"} = $#$coords;
847 foreach (@{$self->left(X=>$x,Y=>$y,level=>$this_level,max=>$args{max})}) {
848 push (@$coords,$_);
849 $self->{curve}{"$_->{X}:$_->{Y}"} = $#$coords;
850 }
851 }
852 }
853 TEST
854
855 test(<<'TEST'); # TONYC/Imager-1.004/Imager.pm
856 if (@$x < @$y) {
857 $x = [ @$x, ($x->[-1]) x (@$y - @$x) ];
858 }
859 elsif (@$y < @$x) {
860 $y = [ @$y, ($y->[-1]) x (@$x - @$y) ];
861 }
862 TEST
863
864 test(<<'TEST'); # TMTM/CDDB-File-1.05/lib/CDDB/File.pm
865 sub _highest_track_no {
866 my $self = shift;
867 $self->{_high} ||= pop @{[ map /^TTITLE(\d+)=/, $self->_data ]}
868 }
869
870 sub track_count { shift->_highest_track_no + 1 }
871
872 # ==================================================================== #
873
874 package CDDB::File::Track;
875
876 use overload
877 '""' => 'title';
878
879 sub cd { shift->{_cd} }
880 sub extd { shift->{_extd} }
881 sub length { shift->{_length}}
882 sub number { shift->{_number}}
883 sub offset { shift->{_offset}}
884
885 sub _split_title {
886 my $self = shift;
887 if ($self->cd->artist eq "Various") {
888 ($self->{_artist}, $self->{_title}) = split /\s+\/\s+/, $self->{_tline}, 2
889 } else {
890 $self->{_title} = $self->{_tline};
891 $self->{_artist} = $self->cd->artist;
892 }
893
894 unless ($self->{_title}) {
895 $self->{_title} = $self->{_artist};
896 $self->{_artist} = $self->cd->artist;
897 }
898 }
899 TEST
900
901 test(<<'TEST'); # MRDVT/Geo-Forward-0.14/lib/Geo/Forward.pm
902 # CU=1./DSQRT(TU*TU+1.)
903 my $CU=1./sqrt($TU*$TU+1.);
904 # SU=TU*CU
905 my $SU=$TU*$CU;
906 # SA=CU*SF
907 my $SA=$CU*$SF;
908 # C2A=-SA*SA+1.
909 my $C2A=-$SA*$SA+1.;
910 # X=DSQRT((1./R/R-1.)*C2A+1.)+1.
911 my $X=sqrt((1./$R/$R-1.)*$C2A+1.)+1.;
912 # X=(X-2.)/X
913 $X=($X-2.)/$X;
914 # C=1.-X
915 my $C=1.-$X;
916 TEST
917
918 test(<<'TEST'); # RBOW/Date-ICal-2.678/lib/Date/ICal.pm
919 my @temp = $str =~ m{
920 ([\+\-])? (?# Sign)
921 (P) (?# 'P' for period? This is our magic character)
922 (?:
923 (?:(\d+)Y)? (?# Years)
924 (?:(\d+)M)? (?# Months)
925 (?:(\d+)W)? (?# Weeks)
926 (?:(\d+)D)? (?# Days)
927 )?
928 (?:T (?# Time prefix)
929 (?:(\d+)H)? (?# Hours)
930 (?:(\d+)M)? (?# Minutes)
931 (?:(\d+)S)? (?# Seconds)
932 )?
933 }x;
934 TEST
935
936 test(<<'TEST'); # JMASON/Mail-SpamAssassin-2.64/t/SATest.pm
937 sub start_spamd {
938 my $sdargs = shift;
939
940 return if (defined($spamd_pid) && $spamd_pid > 0);
941
942 rmtree ("log/outputdir.tmp"); # some tests use this
943 mkdir ("log/outputdir.tmp", 0755);
944
945 if (defined $ENV{'SD_ARGS'}) {
946 $sdargs = $ENV{'SD_ARGS'} . " ". $sdargs;
947 }
948
949 my $spamdargs;
950 if($sdargs !~ /(?:-C\s*[^-]\S+)/) {
951 $sdargs = "$spamd_cf_args $spamd_localrules_args $sdargs";
952 }
953 if($sdargs !~ /(?:-p\s*[0-9]+|-o|--socketpath)/)
954 {
955 $spamdargs = "$spamd -D -p $spamdport $sdargs";
956 }
957 else
958 {
959 $spamdargs = "$spamd -D $sdargs";
960 }
961 $spamdargs =~ s!/!\\!g if ($^O =~ /^MS(DOS|Win)/i);
962
963 if ($set_test_prefs) {
964 warn "oops! SATest.pm: a test prefs file was created, but spamd isn't reading it\n";
965 }
966
967 print ("\t$spamdargs > log/$testname.spamd 2>&1 &\n");
968 system ("$spamdargs > log/$testname.spamd 2>&1 &");
969
970 # now find the PID
971 $spamd_pid = 0;
972 # note that the wait period increases the longer it takes,
973 # 20 retries works out to a total of 60 seconds
974 my $retries = 20;
975 my $wait = 0;
976 while ($spamd_pid <= 0) {
977 my $spamdlog = '';
978
979 if (open (IN, "<log/$testname.spamd")) {
980 while (<IN>) {
981 /Address already in use/ and $retries = 0;
982 /server pid: (\d+)/ and $spamd_pid = $1;
983 $spamdlog .= $_;
984 }
985 close IN;
986 last if ($spamd_pid);
987 }
988
989 sleep (int($wait++ / 4) + 1) if $retries > 0;
990 if ($retries-- <= 0) {
991 warn "spamd start failed: log: $spamdlog";
992 warn "\n\nMaybe you need to kill a running spamd process?\n\n";
993 return 0;
994 }
995 }
996
997 1;
998 }
999
1000 sub stop_spamd {
1001 return 0 if defined($spamd_never_started);
1002 return 0 if defined($spamd_already_killed);
1003
1004 $spamd_pid ||= 0;
1005 if ( $spamd_pid <= 1) {
1006 print ("Invalid spamd pid: $spamd_pid. Spamd not started/crashed?\n");
1007 return 0;
1008 } else {
1009 my $killed = kill (15, $spamd_pid);
1010 print ("Killed $killed spamd instances\n");
1011
1012 # wait for it to exit, before returning.
1013 for my $waitfor (0 .. 5) {
1014 if (kill (0, $spamd_pid) == 0) { last; }
1015 print ("Waiting for spamd at pid $spamd_pid to exit...\n");
1016 sleep 1;
1017 }
1018
1019 $spamd_pid = 0;
1020 undef $spamd_never_started;
1021 $spamd_already_killed = 1;
1022 return $killed;
1023 }
1024 }
1025 TEST
1026
1027 test(<<'TEST'); # JOSEF/Text-Glob-DWIW-0.01/lib/Text/Glob/DWIW.pm
1028 sub _dequ ($@) { my $o=shift; my $star=join '',map { $o&&$o->{star}=~/([$_])/ } qw'* ?';
1029 my ($xa)=map {('^'x/[a\^]/).('^'x/[z\$]/)} $o->{rewrite}?'':$o->{anchors};
1030 my $s=$star.($o->{minus}?'!':'').($o->{rewrite}?'':',{}').$xa;
1031 my $dequ=qr/(?<=^\\)[!]|[[\]$s-]/; # $o{star} (\\?)
1032 _map_r { s{$nobackslash\K\\($dequ)}{$1}gs;
1033 s/\\\\/\\/gs if $o->{last} } @_ }# \# &c. = done elsewhere
1034 TEST
1035
1036 test(<<'TEST'); # WINTRU/Carrot-1.1.309/lib/Carrot/Modularity/Package/Source_Code.pm
1037 {
1038 sub add_begin_block_after_warnings
1039 # /type method
1040 # /effect ""
1041 # //parameters
1042 # //returns
1043 {
1044 my ($this) = @ARGUMENTS;
1045
1046 unless ($$this =~ s
1047 # {use (warnings|strict)[^\015\012;]*;(?:\012|\015\012?)\K}
1048 {use warnings[^\015\012;]*;(?:\012|\015\012?)\K}
1049 {$begin_block}s)
1050 {
1051 die("Could not add a begin block.\n");
1052 }
1053 return;
1054 }
1055
1056 my $carrot_modularity_start = '#--8<-- carrot-modularity-start -->8--#';
1057 my $carrot_modularity_end = '#--8<-- carrot-modularity-end -->8--#';
1058 }
1059 TEST
1060
1061 test(<<'TEST'); # WINTRU/Carrot-1.1.309/lib/Carrot/Modularity/Package/Source_Code.pm
1062 sub add_modularity_markers
1063 # /type method
1064 # /effect ""
1065 # //parameters
1066 # //returns
1067 {
1068 my ($this) = @ARGUMENTS;
1069
1070 unless ($$this =~ s
1071 {((?:\012|\015\012?)\h+)my\h+\$expressiveness\h+=\h+Carrot::modularity(?:\(\))?;\K}
1072 {$1$carrot_modularity_start}saa)
1073 {
1074 die("Could not add carrot-modularity-start. $$this\n");
1075 }
1076 unless ($$this =~ s
1077 {(((?:\012|\015\012?)\h+)\} \#BEGIN)}
1078 {$1$carrot_modularity_end$2}saa)
1079 {
1080 die("Could not add carrot-modularity-end.\n");
1081 }
1082 return;
1083 }
1084 TEST
1085
1086 test(<<'TEST'); # MONS/AnyEvent-SMTP-0.10/lib/AnyEvent/SMTP/Client.pm
1087 m{# trying to cheat with cpants game ;)
1088 use strict;
1089 use warnings;
1090 }x;
1091 TEST
1092
1093 test(<<'TEST'); # CHILTS/SRS-EPP-Proxy-0.21/lib/SRS/EPP/Command.pm
1094 sub rebless_class {
1095 my $object = shift;
1096 our $map;
1097 if ( !$map ) {
1098 $map = {
1099 map {
1100 $_->can("match_class") ?
1101 ( $_->match_class => $_ )
1102 : ();
1103 }# map { print "rebless_class checking plugin $_\n"; $_ }
1104 grep m{${\(__PACKAGE__)}::[^:]*$},
1105 __PACKAGE__->plugins,
1106 };
1107 }
1108 $map->{ref $object};
1109 }
1110 TEST
1111
1112 test(<<'TEST'); # AKXLIX/Sisimai-4.1.25/lib/Sisimai/ARF.pm
1113 my $RxARF0 = {
1114 'content-type' => qr/report-type=["]?feedback-report["]?/,
1115 'begin' => qr{\A(?>
1116 [Tt]his[ ]is[ ].+[ ]email[ ]abuse[ ]report
1117 |[Tt]his[ ]is[ ](?:
1118 an[ ]autogenerated[ ]email[ ]abuse[ ]complaint
1119 |an?[ ].+[ ]report[ ]for
1120 |a[ ].+[ ]authentication[ -]failure[ ]report[ ]for
1121 )
1122 )
1123 }x,
1124 'rfc822' => qr!\AContent-Type: (:?message/rfc822|text/rfc822-headers)!,
1125 'endof' => qr/\A__END_OF_EMAIL_MESSAGE__\z/,
1126 };
1127 TEST
1128
1129 test(<<'TEST'); # LBENDAVID/Net-Telnet-Brcd-1.13/lib/Net/Brcd.pm
1130 if (m{
1131 ^\s* (\d+) : \s+ \w+ \s+ # Domain id + identifiant FC
1132 ${_brcd_wwn_re} \s+ # WWN switch
1133 (\d+\.\d+\.\d+\.\d+) \s+ # Adresse IP switch
1134 \d+\.\d+\.\d+\.\d+ \s+ # Adresse IP FC switch (FCIP)
1135 (>?)"([^"]+) # Master, nom du switch
1136 }msx) {
1137 my ($domain_id, $switch_ip, $switch_master, $switch_name) = ($1, $2, $3, $4);
1138 my $switch_host = gethostbyaddr(inet_aton($switch_ip), AF_INET);
1139 my @fields = qw(DOMAIN IP MASTER FABRIC NAME MASTER);
1140 foreach my $re ($domain_id, $switch_ip, $switch_master, $switch_host, $switch_name) {
1141 my $field = shift @fields;
1142 if ($re) {
1143 $domain{$domain_id}->{$field} = $re;
1144 $fabric{$switch_name}->{$field} = $re;
1145 }
1146 }
1147
1148 $fabric{$switch_host} = $switch_name if $switch_host;
1149 }
1150 TEST
1151
1152 test(<<'TEST'); # DCONWAY/Acme-Bleach-1.150/lib/Acme/DWIM.pm
1153 my @bits = split qr<(?!\s*\bx)($string|[\$\@%]\w+|[])}[({\w\s;/]+)>;
1154 TEST
1155
1156 test(<<'TEST'); # EVO/Text-MicroMason-1.99/MicroMason/Embperl.pm
1157 sub lex_token {
1158 # Blocks in [-/+/! ... -/+/!] tags.
1159 /\G \[ (\-|\+|\!) \s* (.*?) \s* \1 \] /gcxs ? ( $block_types{$1} => $2 ) :
1160
1161 # Blocks in [$ command ... $] tags.
1162 /\G \[ \$ \s* (\S+)\s*(.*?) \s* \$ \] /gcxs ? ( "ep_$1" => $2 ) :
1163
1164 # Things that don't match the above
1165 /\G ( (?: [^\[] | \[(?![\-\+\!\$]) )+ ) /gcxs ? ( 'text' => $1 ) :
1166
1167 ()
1168 }
1169 TEST
1170
1171 test(<<'TEST'); # DOMQ/Alien-Selenium-0.09/inc/Module/Load.pm
1172 sub _is_file {
1173 local $_ = shift;
1174 return /^\./ ? 1 :
1175 /[^\w:']/ ? 1 :
1176 undef
1177 #' silly bbedit..
1178 }
1179 TEST
1180
1181 test(<<'TEST'); # WOODY/Apache-Album-0.96/Album.pm
1182 my %params = split /=+/, $r->args;
1183 TEST
1184
1185 test(<<'TEST'); # JONG/Bioinf_V2.0/Bioinf.pm
1186 sub rand_word {
1187 my($length) = $_[0];
1188 my($word, $letter);
1189 srand(((time/$$)^($>*time))/(time/(time^$$)));
1190
1191 foreach (1..$length){
1192 $letter = pack("c", rand(128));
1193 redo unless $letter =~ /[a-zA-Z]/; # I just don't like \w, okay?
1194 $word .= $letter;
1195 }
1196 return(\$word);
1197 }
1198 TEST
1199
1200 test(<<'TEST'); # JOESUF/News-GnusFilter-0.55/GnusFilter.pm
1201 $count++ while
1202 /^\s*[^>#\%\$\@].{60,}\n[^>].{1,20}[^{}();|&]\n(?=[^>].{60})/gm;
1203 TEST
1204
1205 test(<<'TEST'); # NWIGER/HTML-ActiveLink-1.02/ActiveLink.pm
1206 if ($path eq '/') {
1207 return $ifmatches if ($test =~ m#^/[^/]*$#);
1208 return $default;
1209 }
1210 TEST
1211
1212 test(<<'TEST'); # CHORNY/Switch-2.17/Switch.pm
1213 elsif ($Perl5 && $source =~ m/\G\s*(([^\$\@{])[^\$\@{]*)(?=\s*{)/gc
1214 || $Perl6 && $source =~ m/\G\s*([^;{]*)()/gc) {
1215 my $code = filter_blocks($1,line(substr($source,0,pos $source),$line));
1216 $text .= ' \\' if $2 eq '%';
1217 $text .= " $code)";
1218 }
1219 TEST
1220
1221 test(<<'TEST'); # UGEN/IMAPGet.pm
1222 $self->{Opres} = "TIMEOUT";
1223 while ($line = _getsock($sock)) {
1224 print "< $line" if $self->{Dump};
1225 last if $line =~/$self->{Opid}\s(\w+)\s/ and $self->{Opres}=$1;
1226 }
1227 TEST
1228
1229 test(<<'TEST'); # NEILB/Text-Autoformat-1.74/lib/Text/Autoformat.pm
1230 $eos = $str !~ /^($gen_abbrev)[^a-z]*\s/i
1231 && $str =~ /[a-z][^a-z]*$term([^a-z]*)\s/
1232 && !($1=~/[])]/ && !$brsent);
1233 TEST
1234
1235 test(<<'TEST'); # JANPAZ/DBD-XBase-1.05/lib/XBase/Index.pm
1236 if ($key =~ tr!,+*)('&%$#"!0123456789!) { $key = '-' . $key; }
1237 TEST
1238
1239 test(<<'TEST'); # SPROUT/WWW-Scripter-0.031/lib/WWW/Scripter.pm
1240 sub request {
1241 for (my $foo) { # protect against tied $_
1242 my $self = shift;
1243 return unless defined(my $request = shift);
1244
1245 $request = $self->_modify_request( $request );
1246
1247 my $meth = $request->method;
1248 my $orig_uri = $request->uri;
1249 my $new_uri;
1250 if ((my $path = $orig_uri->path) =~ s-^(/*)/\.\./-$1||'/'-e) {
1251 0while $path =~ s\\$1||'/'\e;
1252 ($new_uri = $orig_uri->clone)->path($path)
1253 }
1254 my $skip_fetch;
1255 if(defined($orig_uri->fragment)) {
1256 ($new_uri ||= $orig_uri->clone)->fragment(undef);
1257
1258 # Skip fetching the URL if it is the same (and there is a fragment).
1259 # We don’t need to strip the fragment from $self->uri before compari-
1260 # son as that always contains the actual URL sent in the request.
1261 $meth eq "GET" and $new_uri->eq($self->uri) and ++$skip_fetch;
1262 }
1263 if ($new_uri) {
1264 $request->uri($new_uri);
1265 }
1266
1267 my $response;
1268
1269 if($skip_fetch) {
1270 $response = $self->response;
1271 }
1272 else {
1273 Scripter_REQUEST: {
1274 Scripter_ABORT: {
1275 $response = $self->_make_request( $request, @_ );
1276 last Scripter_REQUEST;
1277 }
1278 return 1
1279 }
1280 }
1281
1282 if ( $meth eq 'GET' || $meth eq 'POST' ) {
1283 $self->get_event_listeners('unload') and
1284 $self->trigger_event('unload'),
1285 $self->{page_stack}->_delete_res;
1286
1287 $self->{page_stack}->${\(
1288 $self->{Scripter_replace} ? '_replace' : '_add'
1289 )}($request, $response, $orig_uri);
1290 }
1291
1292 return $self->_update_page($request, $response);
1293 }
1294 }
1295 TEST
1296
1297 test(<<'TEST'); # DYLUNIO/Gwybodaeth-0.02/lib/Gwybodaeth/Parsers/N3.pm
1298 if ($token =~ m/\[ # matches [ /x) {
1299 if ($token =~ m/
1300 \[\] # matches []
1301 /x) {
1302 #logic specific to 'something' bracket operator
1303 next;
1304 }
1305 # logic
1306 while((my $tok=$self->_next_token($data,$indx)) =~ /
1307 # any character which is not
1308 # a right square brace
1309 [^\]]
1310 /x) {
1311 ++$indx;
1312 }
1313 $indx = $self->_parse_n3($data,$indx);
1314 next;
1315 }
1316 TEST
1317
1318 test(<<'TEST'); # BRICAS/Image-TextMode-0.25/lib/Image/TextMode/Writer/ADF.pm
1319 my $default_pal = [
1320 map {
1321 my @d = split( //s, sprintf( '%06b', $_ ) );
1322 {
1323 [ oct( "0b$d[ 3 ]$d[ 0 ]" ) * 63,
1324 oct( "0b$d[ 4 ]$d[ 1 ]" ) * 63,
1325 oct( "0b$d[ 5 ]$d[ 2 ]" ) * 63,
1326 ]
1327 }
1328 } 0 .. 63
1329 ];
1330 TEST
1331
1332 test(<<'TEST'); # AGENT/Test-Nginx-0.25/lib/Test/Nginx/Socket/Lua.pm
1333 unless ($config =~ s{(?<!\# )(?<!\# )(?<!\#)init_by_lua\s*(['"])((?:\\.|.)*)\1\s*;}{init_by_lua $1$escaped_code$2$1;}s) {
1334 unless ($config =~ s{(?<!\# )(?<!\# )(?<!\#)init_by_lua_block\s*\{}{init_by_lua_block \{ $code }s) {
1335 $config .= "init_by_lua '$escaped_code';";
1336 }
1337 }
1338 TEST
1339
1340 test(<<'TEST'); # JHTHORSEN/Mojolicious-Plugin-AssetPack-1.04/lib/Mojolicious/Plugin/AssetPack.pm
1341 sub _pipes {
1342 my ($self, $names) = @_;
1343
1344 $self->{pipes} = [
1345 map {
1346 my $class = load_module /::/ ? $_ : "Mojolicious::Plugin::AssetPack::Pipe::$_";
1347 diag 'Loading pipe "%s".', $class if DEBUG;
1348 die qq(Unable to load "$_": $@) unless $class;
1349 my $pipe = $class->new(assetpack => $self);
1350 Scalar::Util::weaken($pipe->{assetpack});
1351 $pipe;
1352 } @$names
1353 ];
1354 }
1355
1356 sub _process_from_def {
1357 my $self = shift;
1358 my $file = shift || 'assetpack.def';
1359 my $asset = $self->store->file($file);
1360 my $topic = '';
1361 my %process;
1362
1363 die qq(Unable to load "$file".) unless $asset;
1364 diag qq(Loading asset definitions from "$file".) if DEBUG;
1365
1366 for (split /\r?\n/, $asset->slurp) {
1367 s/\s*\#.*//;
1368 if (/^\<(\S*)\s+(.+)/) {
1369 my $asset = $self->store->asset($2);
1370 bless $asset, 'Mojolicious::Plugin::AssetPack::Asset::Null' if $1 eq '<';
1371 push @{$process{$topic}}, $asset;
1372 }
1373 elsif (/^\!\s*(.+)/) { $topic = $1; }
1374 }
1375
1376 $self->process($_ => @{$process{$_}}) for keys %process;
1377 $self;
1378 }
1379 TEST
1380
1381 test(<<'TEST'); # CASIANO/Parse-Eyapp-1.182/lib/Parse/Eyapp/Cleaner.pm
1382 $$input=~/\G%{/gc
1383 and do {
1384 my($code);
1385
1386 $$input=~/\G(.*?)%}/sgc
1387 or _SyntaxError(2,"Unmatched %{ opened line $lineno[0]",-1);
1388
1389 $code=$1;
1390 $lineno[1]+= $code=~tr/\n//;
1391 return('HEADCODE',[ $code, $lineno[0] ]);
1392 };
1393 TEST
1394
1395 test(<<'TEST'); # MSERGEANT/XML-Handler-AxPoint-1.5/lib/XML/Handler/AxPoint.pm
1396 $phi_r = $phi * PI / 180.0;
1397
1398 # Compute (x1, y1)
1399 $x1 = cos($phi_r) * $dx2 + sin($phi_r) * $dy2;
1400 $y1 = -sin($phi_r) * $dx2 + cos($phi_r) * $dy2;
1401
1402 # Make sure radii are large enough
1403 $rx = abs($rx); $ry = abs($ry);
1404 $rx_sq = $rx * $rx;
1405 $ry_sq = $ry * $ry;
1406 $x1_sq = $x1 * $x1;
1407 $y1_sq = $y1 * $y1;
1408
1409 my $radius_check = ($x1_sq / $rx_sq) + ($y1_sq / $ry_sq);
1410 TEST
1411
1412 test(<<'TEST'); # AGENT/Test-Nginx-0.25/lib/Test/Nginx/Socket/Lua.pm
1413 Test::Nginx::Socket::set_http_config_filter(sub {
1414 my $config = shift;
1415 if ($config =~ /init_by_lua_file/) {
1416 return $config;
1417 }
1418 unless ($config =~ s{(?<!\# )(?<!\# )(?<!\#)init_by_lua\s*(['"])((?:\\.|.)*)\1\s*;}{init_by_lua $1$escaped_code$2$1;}s) {
1419 unless ($config =~ s{(?<!\# )(?<!\# )(?<!\#)init_by_lua_block\s*\{}{init_by_lua_block \{ $code }s) {
1420 $config .= "init_by_lua '$escaped_code';";
1421 }
1422 }
1423 return $config;
1424 });
1425 TEST
1426
1427 test(<<'TEST'); # AWNCORP/Data-Object-0.05/lib/Data/Object/Role/String.pm
1428 sub words {
1429 my ($string) = @_;
1430 return [CORE::split /\s+/, $string];
1431 }
1432 TEST
1433
1434 test(<<'TEST'); # OPI/HTML-YaTmpl-1.8/lib/HTML/YaTmpl/_parse.pm
1435 $regexp=qr{
1436 # (?{
1437 # my $pos=pos;
1438 # my $prev=substr($str, $pos>=10?$pos-10:0, $pos>=10?10:$pos);
1439 # my $post=substr($str, $pos, 10);
1440 # print "start at position ",pos,": $prev^$post\n";
1441 # })
1442 <([=:\043]) # [=:#] goes to $1
1443 (\w*) # TAG to $2
1444 ($re_tparam) # tag params go to $3
1445 (?:
1446 (?> /> )
1447 |
1448 (?>
1449 >
1450 ( # the section content goes to $4
1451 (?: # we are looking for a character
1452 (?> [^<]+ ) # that is not the beginning of a TAG
1453 | # or
1454 (?>
1455 (??{$regexp}) # we are looking for something that is
1456 ) # described by $regexp
1457 | # or
1458 <(?! # is the beginning of a TAG but not followed
1459 (?> # by the rest of an opening or closing TAG
1460 \1\2 $re_tparam
1461 |
1462 /\1\2
1463 )> )
1464 )*? # and that many times
1465 )
1466 </\1\2> # the closing TAG
1467 ))
1468 # (?{
1469 # my $pos=pos;
1470 # my $prev=substr($str, $pos-10, 10);
1471 # my $post=substr($str, $pos, 10);
1472 # print "emitted at position ",pos,": $prev^$post\n";
1473 # })
1474 }xs;
1475 TEST
1476
1477 test(<<'TEST'); # OPI/HTML-YaTmpl-1.8/lib/HTML/YaTmpl/_parse.pm
1478 my $re_nostr=qr{
1479 (?: # between <: and /> can be written perl code
1480 [^\s\w/]> # but perl knows the -> operator. Originally
1481 | # this (?:...) was written simply as [^"<>]
1482 # and <:$p->{xxx}/> was matched as $1=':',
1483 # $2='', $3='$p-' and not as $3='$p->{xxx}'
1484 # as expected. Now a character other than \s,
1485 # \w or / acts like an escape character for a
1486 # subsequent >.
1487 /(?!>)
1488 |
1489 \\.
1490 |
1491 [^"<>/] # "]# kein string
1492 )*
1493 }xs;
1494 TEST
1495
1496 test(<<'TEST'); # DHARD/FAST-1.0/lib/FAST/Bio/SearchIO/Writer/HTMLResultWriter.pm
1497 if ($sec =~ s/((?:gi\|(\d+)\|)? # optional GI
1498 (\w+)\|([A-Z\d\.\_]+) # main
1499 (\|[A-Z\d\_]+)?) # optional secondary ID//xms) {
1500 my ($name, $gi, $db, $acc) = ($1, $2, $3, $4);
1501 #$acc ||= ($rest) ? $rest : $gi;
1502 $acc =~ s/^\s+(\S+)/$1/;
1503 $acc =~ s/(\S+)\s+$/$1/;
1504 $url =
1505 length($self->remote_database_url($type)) > 0 ?
1506 sprintf('<a href="%s">%s</a> %s',
1507 sprintf($self->remote_database_url($type),
1508 $gi || $acc || $db),
1509 $name, $sec) : $sec;
1510 } else {
1511 $url = $sec;
1512 }
1513 TEST
1514
1515 test(<<'TEST'); # REID/Games-Go-AGATourn-1.035/AGATourn.pm
1516 if ($line =~ s/\s*#\s*(.*?)\s*$//) {
1517 $comment = $1;
1518 }
1519 if ($line eq '') {
1520 return {
1521 comment => $comment,
1522 };
1523 }
1524
1525 if ($line =~ m/^\s*(\w+)(\d+)\s+(\w+)(\d+)\s+([bwBW\?])\s+(\d+)\s+(-?\d+)$/) {
1526 return {
1527 wcountry => uc($1),
1528 wagaNum => $2,
1529 bcountry => uc($3),
1530 bagaNum => $4,
1531 result => lc($5),
1532 handi => $6,
1533 komi => $7,
1534 comment => $comment,
1535 };
1536 }
1537 TEST
1538
1539 test(<<'TEST'); # PERLANCAR/PERLANCAR-JSON-Match-0.02/lib/PERLANCAR/JSON/Match.pm
1540 our $MATCH_JSON = qr{
1541
1542 (?&VALUE) (?{ $_ = $^R->[1] if 0 })
1543
1544 (?(DEFINE)
1545
1546 (?<OBJECT>
1547 #(?{ [$^R, {}] })
1548 \{\s*
1549 (?: (?&KV) # [[$^R, {}], $k, $v]
1550 # (?{ # warn Dumper { obj1 => $^R };
1551 # die "Duplicate key '$^R->[1]'" if exists $^R->[0][1]->{$^R->[1]};
1552 # [$^R->[0][0], {$^R->[1] => $^R->[2]}] })
1553 (?: \s*,\s* (?&KV) # [[$^R, {...}], $k, $v]
1554 # (?{ # warn Dumper { obj2 => $^R };
1555 # die "Duplicate key '$^R->[1]'" if exists $^R->[0][1]->{$^R->[1]};
1556 # [$^R->[0][0], {%{$^R->[0][1]}, $^R->[1] => $^R->[2]}] })
1557 )*
1558 )?
1559 \s*\}
1560 )
1561
1562 (?<KV>
1563 (?&STRING) # [$^R, "string"]
1564 \s*:\s* (?&VALUE) # [[$^R, "string"], $value]
1565 #(?{ # warn Dumper { kv => $^R };
1566 # [$^R->[0][0], $^R->[0][1], $^R->[1]] })
1567 )
1568
1569 (?<ARRAY>
1570 #(?{ [$^R, []] })
1571 \[\s*
1572 (?: (?&VALUE) #(?{ [$^R->[0][0], [$^R->[1]]] })
1573 (?: \s*,\s* (?&VALUE) #(?{ # warn Dumper { atwo => $^R };
1574 #[$^R->[0][0], [@{$^R->[0][1]}, $^R->[1]]] })
1575 )*
1576 )?
1577 \s*\]
1578 )
1579
1580 (?<VALUE>
1581 \s*
1582 (
1583 (?&STRING)
1584 |
1585 (?&NUMBER)
1586 |
1587 (?&OBJECT)
1588 |
1589 (?&ARRAY)
1590 |
1591 true #(?{ [$^R, 1] })
1592 |
1593 false #(?{ [$^R, 0] })
1594 |
1595 null #(?{ [$^R, undef] })
1596 )
1597 \s*
1598 )
1599
1600 (?<STRING>
1601 (
1602 "
1603 (?:
1604 [^\\"]+
1605 |
1606 \\ ["\\/bfnrt]
1607 # |
1608 # \\ u [0-9a-fA-f]{4}
1609 )*
1610 "
1611 )
1612
1613 #(?{ [$^R, eval $^N] })
1614 )
1615
1616 (?<NUMBER>
1617 (
1618 -?
1619 (?: 0 | [1-9]\d* )
1620 (?: \. \d+ )?
1621 (?: [eE] [-+]? \d+ )?
1622 )
1623
1624 #(?{ [$^R, eval $^N] })
1625 )
1626
1627 ) }xms;
1628 TEST
1629
1630 test(<<'TEST'); # MRDVT/List-NSect-0.06/lib/List/NSect.pm
1631 sub spart {
1632 my $parts = shift || 0;
1633 my @deck = ();
1634 #undef, 0 or empty array returns nothing as requested
1635 if ($parts > 0) {
1636 my $i = 0;
1637 @deck = part {int($i++ / $parts)} @_; #/#Each partition created is a reference to an array.
1638 }
1639 return wantarray ? @deck : \@deck;
1640 }
1641 TEST
1642
1643 test(<<'TEST'); # GEHIC/ConfigFile.pm
1644 while (<CONF>)
1645 {
1646 # process a comment or blank line
1647 if (/^\s*[#;]/ || /^\s*$/)
1648 { print TMP $_; next };
1649
1650 # Is this a section header?
1651 /^\s*\[\s*(.+)\s*\].*$/ && do
1652 {
1653 $sect = $1;
1654 print TMP $_;
1655 next;
1656 };
1657
1658 # process definition
1659 /^\s*(.+)\s*=\s*(.+)\s*$/ && do
1660 {
1661 print TMP "$1 = $self->{Config}->{$sect}->{$1}\n";
1662 delete $self->{Config}->{$sect}->{$1};
1663 };
1664 };
1665 TEST
1666
1667 test(<<'TEST'); # RHANDOM/Net-Server-2.008/lib/Net/Server/HTTP.pm
1668 $fmt =~ s{ % ([<>])? # 1
1669 (!? \d\d\d (?:,\d\d\d)* )? # 2
1670 (?: \{ ([^\}]+) \} )? # 3
1671 ([aABDfhHmpqrsTuUvVhblPtIOCeinoPtX%]) # 4
1672 }{
1673 $info = $orig if $1 && $orig && $1 eq '<';
1674 my $v = $2 && (substr($2,0,1) eq '!' ? index($2, $info->{'response_status'})!=-1 : index($2, $info->{'response_status'})==-1) ? '-'
1675 : $fmt_map{$4} ? $info->{$fmt_map{$4}}
1676 : $fmt_code{$4} ? do { my $m = $fmt_code{$4}; $self->$m($info, $3, $1, $4) }
1677 : $4 eq 'b' ? $info->{'response_size'} || '-' # B can be 0, b cannot
1678 : $4 eq 'I' ? $info->{'request_size'} + $info->{'request_header_size'}
1679 : $4 eq 'O' ? $info->{'response_size'} + $info->{'response_header_size'}
1680 : $4 eq 'T' ? sprintf('%d', $info->{'elapsed'})
1681 : $4 eq 'D' ? sprintf('%d', $info->{'elapsed'}/.000_001)
1682 : $4 eq '%' ? '%'
1683 : '-';
1684 $v = '-' if !defined($v) || !length($v);x
1685 $v =~ s/([^\ -\!\#-\[\]-\~])/$1 eq "\n" ? '\n' : $1 eq "\t" ? '\t' : sprintf('\x%02X', ord($1))/eg; # escape non-printable or " or \
1686 $v;
1687 }gxe;
1688 TEST
1689
1690 test(<<'TEST'); # MLEHMANN/AnyEvent-GDB-0.2/GDB.pm
1691 sub _parse_value {
1692 if (/\G"/gc) { # c-string
1693 &_parse_c_string
1694
1695 } elsif (/\G\{/gc) { # tuple
1696 my $r = &_parse_results;
1697
1698 /\G\}/gc
1699 or die "tuple does not end with '}'\n";
1700
1701 $r
1702
1703 } elsif (/\G\[/gc) { # list
1704 my @r;
1705
1706 until (/\G\]/gc) {
1707 # if GDB outputs "result" in lists, let me know and uncomment the following lines
1708 # # list might also contain key value pairs, but apparently
1709 # # those are supposed to be ordered, so we use an array in perl.
1710 # push @r, $1
1711 # if /\G([^=,\[\]\{\}]+)=/gc;
1712
1713 push @r, &_parse_value;
1714
1715 /\G,/gc
1716 or last;
1717 }
1718
1719 /\G\]/gc
1720 or die "list does not end with ']'\n";
1721
1722 \@r
1723
1724 } else {
1725 die "value expected\n";
1726 }
1727 }
1728 TEST
1729
1730 test(<<'TEST'); # DCONWAY/Dios-0.000007/lib/Dios.pm
1731 sub import {
1732 my (undef, $opt) = @_;
1733
1734 # What kind of accessors were requested in this scope???
1735 $^H{'Dios accessor_type'}
1736 = $opt->{accessor} // $opt->{accessors} // $opt->{acc} // q{standard};
1737
1738 # How should the invocants be named in this scope???
1739 my $invocant_name = $opt->{invocant} // $opt->{inv} // q{$self};
1740 if ($invocant_name =~ m{\A (\$?) ([^\W\d]\w*+) \Z}xms) {
1741 $^H{'Dios invocant_name'} = ($1||'$').$2;
1742 }
1743 else {
1744 _error "Invalid invocant specification: '$invocant_name'\nin 'use Dios' statement";
1745 }
1746
1747 # Class definitions are translated to encapsulated packages using OIO...
1748 keyword class (QualIdent $class_name, /is \s* (\w*)/x @bases?, Block $block) {{{
1749 { package <{$class_name}>;
1750 use Object::InsideOut <{ @bases ? qq{qw{@bases}} : q{} }>;
1751 <{ substr($block,1,-1) }>
1752 }
1753 }}}
1754
1755 # How to recognize a set of sub attributes...
1756 keytype Attrs { /(?x: \s* : \s* (?: [^\W\d]\w* (?: \( .*? \) )? \s* )* )+/ }
1757
1758 # Function definitions are translated to subroutines with extra argument-unpacking code...
1759 keyword func (QualIdent $sub_name = q{}, List $parameter_list?, Attrs $attrs = q{}, Block $block) {
1760 # Generate code that unpacks and tests arguments...
1761 $parameter_list = _translate_parameters($parameter_list, func => "$sub_name");
1762
1763 # Peel the curlies from the block (because we're interpolating its code)...
1764 $block = substr($block,1,-1);
1765
1766 # Assemble and return the method definition...
1767 qq{sub $sub_name $attrs { $parameter_list; $block } } =~ s/;/;\n/gr;
1768 }
1769
1770 # Method definitions are translated to subroutines with extra invocant-and-argument-unpacking code...
1771 keyword method (QualIdent $sub_name = q{}, List $parameter_list?, Attrs $attrs = q{}, Block $block) {
1772 # Which kind of aliasing do we need (to create local vars bound to the object's fields)???
1773 my $use_aliasing = $] < 5.022 ? q{use Data::Alias} : q{use experimental 'refaliasing'};
1774 my $attr_binding = $^H{'Dios attrs'} ? "$use_aliasing; $^H{'Dios attrs'}" : q{};
1775
1776 # Generate code that unpacks and tests arguments...
1777 $parameter_list = _translate_parameters($parameter_list, method => "$sub_name");
1778
1779 # Peel the curlies from the block (because we're interpolating its code)...
1780 $block = substr($block,1,-1);
1781
1782 # Assemble and return the method definition...
1783 qq{sub $sub_name $attrs { $attr_binding $parameter_list; $block } };
1784 }
1785
1786 # Submethod definitions are translated like methods, but with special re-routing...
1787 keyword submethod (QualIdent $sub_name = q{}, List $parameter_list?, Attrs $attrs = q{}, Block $block) {
1788 # Which kind of aliasing do we need (to create local vars bound to the object's fields)???
1789 my $use_aliasing = $] < 5.022 ? q{use Data::Alias} : q{use experimental 'refaliasing'};
1790 my $attr_binding = $^H{'Dios attrs'} ? "$use_aliasing; $^H{'Dios attrs'}" : q{};
1791
1792 # Handle any special submethod names...
1793 my $init_args = q{};
1794 if ($sub_name eq 'BUILD') {
1795 # Extract named args for :InitArgs hash (TODO: this should pull out type/required info too)...
1796 my @param_names = $parameter_list =~ m{ : [\$\@%]? (\w++) }gxms;
1797
1798 # Tell OIO about this constructor args...
1799 $init_args = qq{ BEGIN{ my %$sub_name :InitArgs = map { \$_ => '' } qw{@param_names}; } };
1800
1801 # Mark the sub as an initializer
1802 $attrs .= ' :Private :Init';
1803
1804 # Repack the arguments from ($self, {attr=>val, et=>cetera}) to ($self, attr=>val, et=>cetera)...
1805 $attr_binding = q{@_ = ($_[0], %{$_[1]});} . $attr_binding;
1806 }
1807 elsif ($sub_name eq 'DESTROY') {
1808 # Parameter list will never be satisfied (which breaks cleanup), so don't allow it at all...
1809 return q{die 'submethod DESTROY cannot have a parameter list';}
1810 if $parameter_list && $parameter_list !~ /^\(\s*+\)$/;
1811
1812 # Mark it as a destructor...
1813 $attrs .= ' :Private :Destroy';
1814
1815 # Rename it so as not to clash with OIO's DESTROY...
1816 $sub_name = '___DESTROY___';
1817 }
1818 else {
1819 $attr_binding = qq{
1820 if ((ref(\$_[0])||\$_[0]) ne __PACKAGE__) {
1821 return \$_[0]->SUPER::$sub_name(\@_[1..\$#_]);
1822 }
1823 } . $attr_binding;
1824 }
1825
1826 # Generate the code to unpack and test arguments...
1827 $parameter_list = _translate_parameters($parameter_list, method => "$sub_name");
1828
1829 # Peel the curlies from the block (because we're interpolating its code)...
1830 $block = substr($block,1,-1);
1831
1832 # Assemble and return the method definition...
1833 qq{$init_args sub $sub_name $attrs { $attr_binding $parameter_list; $block } };
1834 }
1835
1836 # What does an attribute variable look like???
1837 keytype HasVar { / .*? (?= [:;=] | \/\/= ) /x }
1838
1839 # An attribute definition is translated into an array with a :Field attribute...
1840 keyword has (HasVar $variable, Attrs $attrs = q{}, ...';' $init) {
1841 _compose_field("$variable $attrs", $init)
1842 }
1843
1844 # What does a shared attribute variable look like???
1845 keytype SharedVar { / .*? (?: is | (?= [;=] | \/\/= ) ) /x }
1846
1847 # An attribute definition is translated into an my var with extra code for accessors...
1848 keyword shared (SharedVar $variable, /r[wo]/ $access = q{}, ...';' $init) {
1849 _compose_shared("$variable $access", $init)
1850 }
1851
1852 # Subtypes are handled by Dios::Types...
1853 keyword subtype from Dios::Types;
1854 }
1855 TEST
1856
1857 test(<<'TEST'); # STRCMP/Batch-Interpreter-0.01/lib/Batch/Interpreter/TestSupport.pm
1858 sub quote_argument {
1859 $_ = shift;
1860 s/([\\\"])/\\$1/gi;
1861 return /[\s\\\"]/ ? "\"$_\"" : $_;
1862 }
1863 TEST
1864
1865 done_testing;