Debian Codegraph @

t/scan/sub.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'); # INGY/YAML-Full-0.0.1/lib/YAML/Full/Base.pm
8 no warnings;my$M=__PACKAGE__.'::';*{$M.Object::new}=sub{my$c=shift;my$s=bless{@_},$c;my%n=%{$c.::.':E'};map{$s->{$_}=$n{$_}->()if!exists$s->{$_}}keys%n;$s};*{$M.import}=sub{import warnings;$^H|=1538;my($P,%e,%o)=caller.'::';shift;eval"no Mo::$_",&{$M.$_.::e}($P,\%e,\%o,\@_)for@_;return if$e{M};%e=(extends,sub{eval"no $_[0]()";@{$P.ISA}=$_[0]},has,sub{my$n=shift;my$m=sub{$#_?$_[0]{$n}=$_[1]:$_[0]{$n}};@_=(default,@_)if!($#_%2);$m=$o{$_}->($m,$n,@_)for sort keys%o;*{$P.$n}=$m},%e,);*{$P.$_}=$e{$_}for keys%e;@{$P.ISA}=$M.Object};*{$M.'build::e'}=sub{my($P,$e)=@_;$e->{new}=sub{$c=shift;my$s=&{$M.Object::new}($c,@_);my@B;do{@B=($c.::BUILD,@B)}while($c)=@{$c.::ISA};exists&$_&&&$_($s)for@B;$s}};*{$M.'default::e'}=sub{my($P,$e,$o)=@_;$o->{default}=sub{my($m,$n,%a)=@_;exists$a{default}or return$m;my($d,$r)=$a{default};my$g='HASH'eq($r=ref$d)?sub{+{%$d}}:'ARRAY'eq$r?sub{[@$d]}:'CODE'eq$r?$d:sub{$d};my$i=exists$a{lazy}?$a{lazy}:!${$P.':N'};$i or ${$P.':E'}{$n}=$g and return$m;sub{$#_?$m->(@_):!exists$_[0]{$n}?$_[0]{$n}=$g->(@_):$m->(@_)}}};*{$M.'builder::e'}=sub{my($P,$e,$o)=@_;$o->{builder}=sub{my($m,$n,%a)=@_;my$b=$a{builder}or return$m;my$i=exists$a{lazy}?$a{lazy}:!${$P.':N'};$i or ${$P.':E'}{$n}=\&{$P.$b}and return$m;sub{$#_?$m->(@_):!exists$_[0]{$n}?$_[0]{$n}=$_[0]->$b:$m->(@_)}}};use constant XXX_skip=>1;my$dm='YAML::XS';*{$M.'xxx::e'}=sub{my($P,$e)=@_;$e->{WWW}=sub{require XXX;local$XXX::DumpModule=$dm;XXX::WWW(@_)};$e->{XXX}=sub{require XXX;local$XXX::DumpModule=$dm;XXX::XXX(@_)};$e->{YYY}=sub{require XXX;local$XXX::DumpModule=$dm;XXX::YYY(@_)};$e->{ZZZ}=sub{require XXX;local$XXX::DumpModule=$dm}};my$i=\&import;*{$M.import}=sub{(@_==2 and not$_[1])?pop@_:@_==1?push@_,grep!/import/,@f:();goto&$i};*{$M.'nonlazy::e'}=sub{${shift.':N'}=1};@f=qw[build default builder xxx import nonlazy];use strict;use warnings;
9 TEST
10
11 test(<<'TEST'); # TYEMQ/Acme-ESP-1.002007/ESP.pm
12 sub O'o { [ shift,oO( @_ ) ]->[!$[] }
13
14 package Acme::ESP::Scanner;
15
16 use overload(
17 '.' => \&scan,
18 nomethod => \&explode,
19 );
20 TEST
21
22 test(<<'TEST'); # YAPPO/Class-Component-0.17/t/MyClass/Plugin/ExtAttribute.pm
23 sub args_0 :Method Dump {}
24 sub args_1 :Method Dump('hoge') {}
25 sub args_1_2 :Method Dump("hoge") {}
26 sub args_2 :Method Dump('hoge1', 'hoge2') {}
27 sub args_2_2 :Method Dump('hoge1', "hoge2") {}
28 sub args_2_3 :Method Dump("hoge1", 'hoge2') {}
29 sub args_2_4 :Method Dump("hoge1", "hoge2") {}
30 sub args_2_5 :Method Dump(qw(hoge1 hoge2)) {}
31 sub args_2_6 :Method Dump(qw/hoge1 hoge2/) {}
32
33 sub ref_array_1 :Method Dump([1,2,3,4]) {}
34 sub ref_array_2 :Method Dump([qw/1 2 3 4/]) {}
35 sub ref_array_3 :Method Dump([qw(1 2 3 4)]) {}
36 sub ref_array_4 :Method Dump(["1",'2','3',"4"]) {}
37 sub ref_array_5 :Method Dump(['1', '2', '3', '4']) {}
38 sub ref_array_6 :Method Dump(["1", "2", "3", "4"]) {}
39
40 sub hash_1 :Method Dump(key=>'value') {}
41 sub ref_hash_1 :Method Dump({ key => 'value' }) {}
42 sub ref_hash_2 :Method Dump({ key => { key => 'value' } }) {}
43
44 sub ref_hash_array :Method Dump({ key => [qw/ foo bar baz /] }) {}
45
46 sub ref_array_hash_1 :Method Dump([ 'foo', { key => 'value' }, 'baz' ]);
47 sub ref_array_hash_2 :Method Dump('foo', { key => 'value' }, 'baz');
48
49 sub ref_code_1 :Method Dump(sub { return 'code' }->()) {}
50 sub ref_code_2 :Method Dump(sub { _code }->()) {}
51 sub ref_code_3 :Method Dump(sub { _code2 4, 5 }->()) {}
52
53 sub run_code_1 :Method DumpRun(sub { return 'code' }) {}
54 sub run_code_2 :Method DumpRun(sub { _code }) {}
55 sub run_code_3 :Method DumpRun(sub { _code2 4, 5 }) {}
56 TEST
57
58 test(<<'TEST'); # ZEFRAM/Debug-Show-0.000/lib/Debug/Show.pm
59 sub debug_hide { }
60
61 cv_set_call_checker(\&debug_hide, sub ($$$) {
62 my($entersubop, undef, undef) = @_;
63 # B::Generate doesn't offer a way to explicitly free ops.
64 # We ought to be able to implicitly free $entersubop via constant
65 # folding, by something like
66 #
67 # return B::LOGOP->new("and", 0,
68 # B::SVOP->new("const", 0, !1),
69 # $entersubop);
70 #
71 # but empirically that causes memory corruption and it's not
72 # clear why. For the time being, leak $entersubop.
73 return B::SVOP->new("const", 0, !1);
74 }, \!1);
75 TEST
76
77 test(<<'TEST'); # STEVEB/Devel-Trace-Subs-0.22/lib/Devel/Trace/Subs.pm
78 push @{$data->{stack}}, {
79 in => (caller(1))[3] || '-',
80 package => (caller(1))[0] || '-',
81 sub => (caller(2))[3] || '-',
82 filename => (caller(1))[1] || '-',
83 line => (caller(1))[2] || '-',
84 };
85 TEST
86
87 test(<<'TEST'); # JRED/CIPP-2.50/lib/CIPP.pm
88 sub Chunk_Out {
89 #
90 # INPUT: 1. Referenz auf Chunk
91 # 2. Befindet Parser sich in einem PRINT Statement
92 # 3. wie soll der Chunk ausgegeben werden:
93 # 1 als print Befehl
94 # 0 unver?ndert
95 # -1 mit Escaping von } Zeichen (f?r Variablenzuweisung)
96 # 4. Start-Zeilennummer des Chunks
97 # 5. Ende-Zeilennummer des Chunks
98 #
99 # OUTPUT: -
100 #
101 my $self = shift;
102 my ($chunk_ref, $in_print_statement, $gen_print,
103 $from_line) = @_;
104 my $output = $self->{output};
105
106 if ( $$chunk_ref ne '' && $$chunk_ref =~ /[^\r\n\s]/ ) {
107 # Chunk ist nicht leer
108 my $context = $self->{context_stack}->
109 [@{$self->{context_stack}}-1];
110
111 if ( $context eq 'html' or $context eq 'force_html' ) {
112 if ( ($gen_print and $context eq 'html') or
113 $context eq 'force_html' ) {
114 # HTML-Context: es wird ein print qq[] Befehl
115 # generiert
116 # ggf. Debugging-Code erzeugen
117 $output->Write (
118 "\n\n\n\n# cippline $from_line ".'"'.
119 $self->{call_path}.'"'."\n" );
120
121 # Chunk muss via print ausgegeben werden
122 $output->Write ("print qq[");
123 $$chunk_ref =~ s/\[/\\\[/g;
124 $$chunk_ref =~ s/\]/\\\]/g;
125 $output->Write ($$chunk_ref);
126 $output->Write ("];\n");
127 }
128 } elsif ( $context eq 'perl' ) {
129 # <?PERL>Context
130 # Chunk wird unveraendert uebernommen
131 $output->Write ($$chunk_ref);
132 } elsif ( $context eq 'var' ) {
133 # <?VAR> Context
134 # Chunk wird mit escapten } uebernommen
135 $$chunk_ref =~ s/\}/\\\}/g;
136 $output->Write ($$chunk_ref);
137 } elsif ( $context eq 'comment' ) {
138 # Hier machen wir nix.
139 } else {
140 die "Unknown context '$context'";
141 }
142 }
143 }
144 TEST
145
146 test(<<'TEST'); # JWALT/Apache-AxKit-Plugin-Session-1/lib/AxKit/XSP/Auth.pm
147 sub check_permission : XSP_attribOrChild(target,reason) XSP_childStruct($text(lang))
148 {
149 return 'if (do {'.has_permission(@_).'}) { '.deny_permission(@_).' }';
150 }
151 TEST
152
153 test(<<'TEST'); # AWWAIID/Continuity-1.6/lib/Continuity.pm
154 my $self = bless {
155 docroot => '.', # default docroot
156 mapper => undef,
157 adapter => undef,
158 debug_level => 1,
159 debug_callback => sub { print STDERR "@_\n" },
160 reload => 1, # XXX
161 callback => (exists &{caller()."::main"} ? \&{caller()."::main"} : undef),
162 staticp => sub { $_[0]->url =~ m/\.(jpg|jpeg|gif|png|css|ico|js)$/ },
163 no_content_type => 0,
164 reap_after => undef,
165 allowed_methods => ['GET', 'POST'],
166 @_,
167 }, $class;
168 TEST
169
170 test(<<'TEST'); # TODDR/Net-Ident-1.24/Ident.pm
171 print STDDBG "Net::Ident::newFromInAddr localaddr=", sub { inet_ntoa( $_[1] ) . ":$_[0]" }
172 ->( sockaddr_in($localaddr) ), ", remoteaddr=", sub { inet_ntoa( $_[1] ) . ":$_[0]" }
173 ->( sockaddr_in($remoteaddr) ), ", timeout=", defined $timeout ? $timeout : "<undef>", "\n"
174 if $DEBUG > 1;
175 TEST
176
177 test(<<'TEST'); # MIK/CryptX-0.028/lib/Crypt/PRNG.pm
178 {
179 ### stolen from Bytes::Random::Secure
180 #
181 # Instantiate our random number generator(s) inside of a lexical closure,
182 # limiting the scope of the RNG object so it can't be tampered with.
183 my $RNG_object = undef;
184 my $fetch_RNG = sub { # Lazily, instantiate the RNG object, but only once.
185 $RNG_object = Crypt::PRNG->new unless defined $RNG_object && ref($RNG_object) ne 'SCALAR';
186 return $RNG_object;
187 };
188 sub rand(;$) { return $fetch_RNG->()->double(@_) }
189 sub irand() { return $fetch_RNG->()->int32() }
190 sub random_bytes($) { return $fetch_RNG->()->bytes(@_) }
191 sub random_bytes_hex($) { return $fetch_RNG->()->bytes_hex(@_) }
192 sub random_bytes_b64($) { return $fetch_RNG->()->bytes_b64(@_) }
193 sub random_bytes_b64u($) { return $fetch_RNG->()->bytes_b64u(@_) }
194 sub random_string_from($;$) { return $fetch_RNG->()->string_from(@_) }
195 sub random_string(;$) { return $fetch_RNG->()->string(@_) }
196 }
197 TEST
198
199 test(<<'END'); # MIKER/Net-DNS-Dig-0.12/Dig.pm
200 sub for($$$) {
201 ...
202 }
203 END
204
205 done_testing;