Debian Codegraph @

t/scan/utf8.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'); # LAWALSH/P-1.1.34/lib/P.pm
8 { package P;
9 use warnings; use strict;use mem;
10 our $VERSION='1.1.34';
11
12 # RCS $Revision: 1.45 $ - $Date: 2015-12-14 12:09:03-08 $
13 # 1.1.34 - Compensating for odd Strawberry Perl var-values...
14 # 1.1.33 - Trying to Compensate for Strawberry Perl bugs...
15 # 1.1.32 - Change FAILS in 1.1.31 for bad env's to "skips"
16 # 1.1.31 - More pruning of bad test environments
17 # 1.1.30 - Attempt to prune unsupported OS's (WinXP)
18 # 1.1.29 - sprintf broken: include zero-width string spec to workaround
19 # 1.1.28 - testsuite fix - unknown failure case in sprintf:
20 # "Redundant argument in sprintf "... for "return sprintf $fmt, $v";
21 # Trying parens around sprintf($fmt, $v);
22 # (shot in dark for strawberry win32 perl on win10...)
23 # 1.1.27 - test fix -- Makefile.PL improperly specified "test", rather
24 # rather than using t/*.*t as pattern
25 # 1.1.26 - add code to allow changing defaults for literals and run-time
26 # constants previously only accessible through the OO method
27 # - Allow setting defaults globally as well as per-package
28 # - fix for bug in testcase 5 in "P.t" in some later versions
29 # of Strawberry Perl (5.22, 5.20?). Where the perlvar '$^X'
30 # contained a win32-backslash-separated path to perl. In double
31 # quotes, the backslashes are removed as literalizing the next
32 # character. Changing the path usage to not have double-quotes
33 # around the path should prevent the backslash-removal and pass
34 # the literal string to the perl 'system' call.
35 # 1.1.25 - put initial POD w/VERSION @ top to keep version #'s together
36 # - remove BEGIN that was needed for running/passing tests
37 # and instead use 'mem'
38 # - move changelog to column one and use vim markers to hide
39 # older changes
40 # - add dflts hash to allow 'use' time change of defaults (W.I.P.)
41 # - split local define+assignment ~#283 due to side effects
42 # 1.1.24 - respin for another Makefile change
43 # 1.1.23 - respin for a Makefile change
44 # 1.1.22 - respin to use alt version format
45 # 1.1.21 - respin to have BUID_REQ include more modern Ext:MM
46 # 1.1.20 - respin to have Makefile rely on Xporter 1.0.6
47 # 1.1.19 - Prereqs not being loaded in Cpantesters; attempt fix
48 # 1.1.18 - Unreported bugfix:
49 # the words HASH & ARRAY were sometimes printed in ref notation
50 # - remove included 'Types' code to use Types::Core (now published)
51 # 1.1.17 - Documentation refinements/fixes; Found possible culprit as to
52 # why Windows native tests could fail -- my source files in
53 # lib have pointed back to my real lib dir via a symlink.
54 # Windows wouldn't like those. Why any other platform did is
55 # likely some fluke of directory organization during test
56 # 1.1.16 - Different shot in dark to see if a change in P.env can make
57 # things work on Win-native
58 # 1.1.15 - Shot in dark to get 5.8.x to work(5.10 and newer seem to
59 # be working!
60 # 1.1.14 - and write out buffer from editor! (arg!)
61 # 1.1.13 - get perl w/ ^X rather than config
62 # 1.1.12 - Found another potential problem in the test prog.
63 # 1.1.11 - May have found another test bug.... trying fix for some fails
64 # 1.1.10 - Another internal format error bug (unreported), but caught
65 # in testing.
66 # 1.1.9 - Try to fix paths for test
67 # 1.1.8 - use ptar to generate Archive::tar compat archives
68 # 1.1.7 - Fix Makefile.PL
69 # 1.1.6 - Use t/P.env for premodifying ENV
70 # Document effect of printing to a FH & recording return val;
71 # 1.1.5 - Distribution change: use --format=v7 on tar to produce tarball
72 # (rt#90165)
73 # - Use shell script to preset env for test since
74 # Test::More doesn't set ENV
75 # 1.1.4 - Quick patch to enable use of state w/CORE::state
76 # 1.1.3 - [#$@%&!!!]
77 # 1.1.2 - Second try for test in P.t to get prereq's right
78 # 1.1.1 - Fix rest of (rt#89050)
79 # 1.1.0 - Fixed Internal bug#001, below & embedded \n@end of int. str
80 # (rt#89064)
81 # Version history continued... #{{{
82 # 1.0.32 - Fix double nest test case @{[\*STDERR, ["fmt:%s", "string"]]}
83 # (rt#89056)
84 # only use sprintf's numeric formats (e.g. %d, %f...) on
85 # numbers supported by sprintf (for now only arabic numerals).
86 # Otherwise print as string. (rt#89063)
87 # its numeric formats (ex "%d", "%f"...)
88 # 1.0.31 - Fix check for previously printed items to apply only to
89 # - the current output statement;
90 # 1.0.30 - Fix LF suppression -- instead of suppressing EOL, suppressed
91 # all output in the case where no FD was specified (code was
92 # confused in deciding whether or not to suppress output and
93 # return it as a string. (rt#89058)
94 # - Add missing quote in Synopsis (rt#89047)
95 # - Change NAME section to reference module following CPAN
96 # standard to re-list name of module instead of functions
97 # (rt#89046)
98 # - Fix L<> in POD that referenced "module" P::P instead of name, "P"
99 # (forms bad link in HTML) (rt#89051)
100 # - Since ($;@) prototypes cause more problems than (@), clean p
101 # proto's to use '@'; impliciation->remove array variations
102 # (rt@89052, #89055) (rt#89058)
103 # - fix outdated and inconsistent doc examples regarding old protos
104 # (rt#89056)(rt#89058)
105 # Had broken P's object oriented flag passing in adding
106 # the 'seen' function (to prevent recursive outptut. Fixed this
107 # while testing that main::DATA is properly closed (rt#89057,#89067)
108 # - Internal Bug #001
109 # #our @a = ("Hello %s", "World");
110 # #P(\*STDERR, \@a);
111 # # prints-> ARRAY(0x1003b40)
112 # 1.0.29 - Convert to using 'There does not exist' sign (∄), U+2204
113 # instead of (undef); use '🔁 ' for recursion/repeat;
114 # U+1F500
115 # 1.0.28 - When doing explicit out (FH specified), be sure to end
116 # with newln.
117 # 1.0.27 - DEFAULT change - don't do implicit IO reads (change via
118 # impicit_io option)
119 # - not usually needed in debugging or most output;
120 # could cause problems
121 # reading data from a file and causing desychronization problems;
122 # 1.0.26 - detect recursive data structs and don't expand them
123 # 1.0.25 - Add expansion for 'REF';
124 # - WIP: Trying to incorporate enumeration of duplicate adjacent
125 # data: Work In Progress: status: disabled
126 # 1.0.24 - limit default max string expanded to 140 chars (maybe want to
127 # do this only in brace expansions?) Method to change in OOO
128 # not documented at this time. NOTE: limiting output by default
129 # is not a great idea.
130 # 1.0.23 - When printing contents of a hash, print non-refs before
131 # refs, and print each subset in alpha sorted order
132 # 1.0.22 - Switch to {…} instead of HASH(0x12356892) or
133 # […] for arrays
134 # 1.0.21 - Doc change: added example of use in "die".
135 # 1.0.20 - Rewrite of testcase 5 in self-execution; no external progs
136 # anymore: use fork and print from P in perl child, then
137 # print from FH in parent, including uses of \x83 to
138 # inhibit extra LF's;
139 # 1.0.19 - Regretting fancy thru 'rev' P direct from FH test case (a bit)
140 # **seems** like some people don't have "." in path for test
141 # cases, so running "t/prog" doesn't work, trying "./t/prog"
142 # (1 fail on a Win32 base on a x64 system...so tempted
143 # to just ignore it...) >;^); guess will up this for now
144 # and think about that test case some more...
145 # I'm so gonna rewrite that case! (see xtodox below)
146 # 1.0.18 - convert top format-case statement to load-time compile
147 # and see if that helps BSD errors;
148 # - change test case w/array to use P & not old Pa-form
149 # - change test case to print to STDERR to use Pe
150 # - fix bug in decrement of $lvl in conditional (decrement must
151 # be in first part of conditional)
152 # - xtodox fix adaptation of 'rev' test case to work w/o
153 # separate file(done)
154 # 1.0.17 - another try at fixing pod decoding on metacpan
155 # 1.0.16 - pod '=encoding' move to before '=head'
156 # (ref:https://github.com/CPAN-API/metacpan-web/issues/800 )
157 # 1.0.15 - remove 'my $_' usage; old perl compat probs; use local
158 # in once instance were needed local copy of $_
159 # 1.0.14 - arg! misspelled Win nul: devname(fixed)
160 # 1.0.13 - test case change only to better test print to STDERR
161 # 1.0.12 - test case change: change of OBJ->print to print OBJ to
162 # try to get around problem on BSD5.12 in P.pm (worked!)
163 # - change embedded test case to not use util 'rev', but
164 # included perl script 'rev' in 't' directory...(for native win)
165 # 1.0.11 - revert printing decimals using %d: dropped significant leading
166 # zero's; Of NOTE: floating point output in objects is
167 # not default: we use ".2f"
168 # - left off space after comma in arrays(fixed)
169 # - rewrite of sections using given/when/default to not use
170 # them; try for 5.8 compat
171 # - call perl for invoking test vs. relying on #! invokation
172 # - pod updates mentioning 'ops'/depth
173 # 1.0.10 - remove Carp::Always from test (wasn't needed and caused it
174 # to fail on most test systems)
175 # add OO-oriented way to set internal P ops (to be documented)
176 # - fixed bug in logic trimming recursion depth on objects
177 # 1.0.9 - Add Px - recursive object print in squished form;
178 # Default to using Px for normal print
179 # 1.0.8 - fix when ref to IO -- wasn't dereferenced properly
180 # - upgrade of self-test/demo to allow specifying which test
181 # to run from cmd line; test numbers are taken from
182 # the displayed examples when run w/no arguments
183 # B:still doesn't run cleanly under test harness may need to
184 # change cases for that (Fixed)
185 # - POD update to current code
186 # 1.0.7 - (2013-1-9) add support for printing blessed objects
187 # - pod corrections
188 # - strip added LF from 'rev' example with tr (looks wrong)
189 # 1.0.6 - add manual check for LF at end (chomp doesn't always work)
190 # 1.0.5 - if don't recognize ref type, print var
191 # 1.0.4 - added support for printing contents of arrays and hashes.
192 # (tnx 2 MidLifeXis@prlmnks 4 brain reset)
193 # 1.0.3 - add Pea
194 # 1.0.2 - found 0x83 = "no break here" -- use that for NL suppress
195 # - added support for easy inclusion in other files
196 # (not just as lib);
197 # - add ISA and EXPORT to 'mem' so they are available @ BEGIN time
198 #
199 # 1.0.1 - add 0xa0 (non breaking space) to suppress NL
200 # #}}}
201
202 use utf8;
203 our (@ISA, @EXPORT);
204 # no sense to support iohandle w/Pe, as Pe is tied to stderr
205 { no warnings "once"; *IO::Handle::P = \&P::P }
206
207 use Types::Core;
208
209 use mem(@EXPORT=qw(P Pe));
210 use Xporter;
211
212 my $ignore=<<'IGN' #{{{
213 BEGIN {
214 use constant EXPERIMENTAL=>0;
215
216 if (EXPERIMENTAL) {
217 sub rm_adjacent {
218 my $c = 1;
219 ($a, $c) = @$a if ref $a;
220 $b //= "∄";
221 if ($a ne $b) { $c > 1 ? "$a × $c" : $a , $b }
222 else { (undef, [$a, ++$c]) }
223 }
224 sub reduce(&@) {
225 my (@final, $i) =((), 0);
226 my ($f, $ar)=@_;
227 for (my $i=0; $i < $#$ar; ++$i ) {
228 ($a, $b) = ($ar->[$i], $ar->[$i+1]);
229 my @r = &$f;
230 push @final, $r[0] if $r[0];
231 $ar->[$i+1] = $r[1];
232 }
233 @final;
234 }
235 }
236 }
237 IGN
238 ||undef; #}}}
239
240
241
242 use constant NoBrHr => 0x83; # Unicode codepoint="No Break Here"
243 our %_dflts;
244 our ($dflts, %mod_dflts, %types);
245 BEGIN {
246 %_dflts=(
247 implicit_io => 0,
248 depth => 3,
249 ellipsis => '…',
250 noquote => 1,
251 maxstring => undef,
252 seen => '🔁',
253 undef => '∄',
254 );
255
256 my $bool = sub { $_[0] ? 1 : 0 };
257 my $intnum = sub { $_[0] =~ m{^([0-9]+)$} ? 0 + $1 : 0 };
258 my $string = sub { length($_[0]) ? $_[0] : '' };
259 my $true = sub { 1 };
260
261 %types=(
262 default => $true,
263 depth => $intnum,
264 ellipsis => $string,
265 implicit_io => $bool,
266 maxstring => $intnum,
267 seen => $string,
268 undef => $string,
269 );
270
271
272 #global default copy
273 $mod_dflts{""} = \%_dflts;
274 $dflts = $mod_dflts{""};
275
276 }
277
278 sub sw(*);
279
280 sub Px { my ($p, $v) = (shift, shift);
281 local (*sw); *sw = sub (*) {$dflts->{$_[0]}};
282 if (ref $v) {
283 if ($p->{__P_seen}{$v}) { return "*". sw(seen) . ":" . $v . "*" }
284 else {$p->{__P_seen}{$v} = 1}
285 }
286 my $lvl = scalar @_ ? $_[0] : 2;
287 my $ro = scalar @_>1 ? $_[1]:0;
288 return sw('undef') unless defined $v;
289 my $ref = ref $v;
290 if (1 > $lvl-- || !$ref) {
291 my $fmt; # prototypes are documentary (rt#89053)
292 my $given = [ sub ($$) { $_[0] =~ /^[-+]?[0-9]+\.?\z/ && q{%s} },
293 sub ($$) { $_[1] && qq{%s}},
294 sub ($$) { 1 == length($_[0]) && q{'%s'}},
295 sub ($$) { $_[0] =~ m{^(?:[+-]?(?:\.[0-9]+)
296 | (?:[0-9]+\.[0-9]+))\z}x && q{%.2f}},
297 sub ($$) { substr($_[0],0,5) eq 'HASH(' &&
298 '{'.sw(ellipsis).'}'.q{%.0s} },
299 sub ($$) { substr($_[0],0,6) eq 'ARRAY(' &&
300 '['.sw(ellipsis).']'.q{%.0s} },
301 # sub ($$) { $mxstr && length ($_[0])>$mxstr
302 # && qq("%.${mxstr}s")},
303 sub ($$) { 1 && q{"%s"}} ];
304
305 do { $fmt = $_->($v, $ro) and last } for @$given;
306 return sprintf($fmt, $v);
307 } else {
308 my $pkg = '';
309 ($pkg, $ref) = ($1, $2) if 0 <= (index $v,'=') && $v=~m{([\w:]+)=(\w+)};
310 local * nonrefs_b4_refs ;
311 * nonrefs_b4_refs = sub {
312 ref $v->{$a} cmp ref $v->{$b} || $a cmp $b
313 };
314
315 local (*IO_glob, *NIO_glob, *IO_io, *NIO_io);
316 (*IO_glob, *NIO_glob, *IO_io, *NIO_io) = (
317 sub(){'<*'.<$v>.'>'}, sub(){'<*='.$p->Px($v, $lvl-1).'>'},
318 sub(){'<='.<$v>.'>'}, sub(){'<|'.$p->Px($v, $lvl-1).'|>'},
319 );
320 no strict 'refs';
321 my %actions = (
322 GLOB => ($p->{implicit_io}? *IO_glob: *NIO_glob),
323 IO => ($p->{implicit_io}? *IO_io : *NIO_io),
324 REF => sub(){ "\\" . $p->Px($$_, $lvl-1) . ' '},
325 SCALAR=> sub(){ $pkg.'\\' . $p->Px($$_, $lvl).' ' },
326 ARRAY => sub(){ $pkg."[".
327 (join ', ',
328 # not working: why? #reduce \&rm_adjacent, (commented out)
329 map{ $p->Px($_, $lvl) } @$v ) ."]" },
330 HASH => sub(){ $pkg.'{' . ( join ', ', @{[
331 map {$p->Px($_, $lvl, 1) . '=>'. $p->Px($v->{$_}, $lvl,0)}
332 sort nonrefs_b4_refs keys %$v]} ) . '}' },);
333 if (my $act=$actions{$ref}) { &$act }
334 else { return "$v" }
335 }
336 }
337
338 sub get_dflts($) {
339 my $p = shift; my $caller = $_[0];
340 return $p->{dflts} if exists $p->{dflts};
341 return exists $mod_dflts{$caller} ? $mod_dflts{$caller} : $mod_dflts{""};
342 }
343
344
345
346 sub P(@) { # 'safen' to string or FH or STDOUT
347 local *sw = sub (*) {$dflts->{$_[0]}};
348 my $p = ref $_[0] eq 'P' ? shift: bless {};
349 $p->{__P_seen}={} unless ref $p->{__P_seen};
350
351 local * unsee_ret = sub ($) {
352 delete $p->{__P_seen} if exists $p->{__P_seen};
353 $_[0] };
354
355 my $v = $_[0];
356 my $rv = ref $v;
357 $dflts = $p->get_dflts((caller)[0]);
358 my ($depth, $noquote) = (sw(depth), sw(noquote));
359 if (HASH eq $rv) {
360 my $params = $v; $v = shift; $rv = ref $v;
361 $depth = $params->{depth} if exists $params->{depth};
362 }
363 if (ARRAY eq $rv ) { $v = shift;
364 @_=(@$v, @_); $v=$_[0]; $rv = ref $v }
365
366 my ($fh, $f, $explicit_out);
367 if ($rv eq GLOB || $rv eq IO) {
368 ($fh, $explicit_out) = (shift, 1);
369 $v = $_[0]; $rv = ref $v;
370 } else { $fh =\*STDOUT }
371
372 if (ARRAY eq $rv ) { $v = shift;
373 @_=(@$v, @_); $v=$_[0]; $rv = ref $v }
374
375 my ($fc, $fmt, @flds, $res)=(1, $_[0]);
376 if ($fc) { $f = shift; no warnings;
377 $res = sprintf $f, map {local $_ = $p->Px($_,$depth,$noquote) } @_ }
378 else { $res = $p->Px(@_)}
379
380 chomp $res;
381
382 my ($nl, $ctx) = ("\n", defined wantarray ? 1 : 0);
383
384 ($res, $nl, $ctx) = (substr($res, 0, -1 + length $res), "", 2) if
385 ord(substr $res,-1) == NoBrHr; #"NO_BREAK_HERE"
386
387 if (!$fh && !$ctx) { #internal consistancy check
388 ($fh = \*STDERR) and
389 P $fh "Invalid File Handle presented for output, using STDERR";
390 ($explicit_out, $nl) = (1, "\n") }
391
392 else { return unsee_ret($res) if (!$explicit_out and $ctx==1) }
393
394 no warnings 'utf8';
395 print $fh ($res . (!$ctx && (!$\ || $\ ne "\n") ? "\n" : "") );
396 unsee_ret($res);
397 };
398
399 sub Pe(@) {
400 my $p = shift if ref $_[0];
401 return '' unless @_;
402 unshift @_, \*STDERR;
403 unshift @_, $p if ref $p;
404 goto &P
405 }
406
407
408 #Pe "_dflts=%s", \%_dflts;
409 #Pe "mod_dflts{}=%s", $mod_dflts{""};
410 #Pe "mod_dflts=%s", \%mod_dflts;
411
412 sub import {
413 my ($modname, @args) = @_;
414 if (@args) {
415 my @others;
416 my $caller = (caller)[0];
417 if (exists $mod_dflts{$caller}) {
418 $dflts = $mod_dflts{$caller};
419 } else {
420 $dflts = undef; # indicate no customization to dflts
421 }
422 my $default = 0;
423 my @tags = grep { if (m{^:(.*)$}) {
424 if ($1 eq 'default') { $default = 1; $_ = undef }
425 else { $_ = $1 }
426 } else { push @others, $_; undef }
427 } @args;
428 if (@tags) {
429 if ($default) {
430 # change global defaults (don't use copy)
431 $dflts = $mod_dflts{""};
432 } else {
433 # if dflts was undef start w/copy of glbl-dflts
434 %{$mod_dflts{$caller}} = %{$mod_dflts{""}} unless exists
435 $mod_dflts{$caller};
436 $dflts=$mod_dflts{$caller}
437 }
438 for (@tags) {
439 my ($tag, $value) = m{^(\w+)(?:=(.+))?$} or
440 die "Tag-format: missing :TAG=VALUE for tag '" . $_ . "'";
441
442 my $chk;
443 {no warnings; no strict; $chk = eval $types{$tag}->($value) };
444 $dflts->{$tag} = $chk;
445 }
446 }
447 $dflts = $mod_dflts{""} unless $dflts; # set to global if not set
448 @_=($modname, @others);
449 }
450 goto &Xporter::import;
451 }
452
453
454
455
456 sub ops($) {
457 my $p = shift; my $c=ref $p || $p;
458 bless $p = {}, $c unless ref $p;
459 my $args = $_[0];
460 my $ldflts = $p->get_dflts((caller)[0]);
461 %{$p->{dflts}} = %$dflts unless ref $p->{dflts};
462 die "ops takes a hash to pass arguments" unless HASH $args;
463 $ldflts = $p->{dflts};
464 foreach (sort keys %$args) {
465 if (exists $ldflts->{$_}) { $ldflts->{$_} = $args->{$_} }
466 else {
467 warn "Unknown key \"$_\" passed to ops";}
468 }
469 $p }
470 1;} #value 1 placed at as w/most of my end-of-packages (rt#89054)
471 TEST
472
473 test(<<'TEST'); # MCHE/Mojolicious-Che-0.031/lib/Mojolicious/Che.pm
474 package Mojolicious::Che;
475 use Mojo::Base::Che 'Mojolicious';
476 use Mojo::Log::Che;
477 use Mojo::Loader qw(load_class);
478
479 ...
480
481 sub хазы { # Хазы из конфига
482 my $app = shift;
483 my $conf = $app->config;
484 my $h = $conf->{'mojo_has'} || $conf->{'mojo'}{'has'} || $conf->{'хазы'};
485 map {
486 $app->log->debug("Make the app->has('$_')");
487 has $_ => $h->{$_};
488 } keys %$h;
489 }
490 TEST
491
492 test(<<'TEST'); # MCHE/Mojolicious-Plugin-RoutesAuthDBI-0.785/lib/Mojolicious/Plugin/RoutesAuthDBI/OAuth2.pm
493 package Mojolicious::Plugin::RoutesAuthDBI::OAuth2;
494 use Mojo::Base 'Mojolicious::Controller';
495 use Mojolicious::Plugin::RoutesAuthDBI::Util qw(json_enc load_class);
496 ...
497
498 sub отсоединить {
499 my $c = shift;
500 my $site_name = $c->stash('site');
501
502 my $site = $c->oauth2->providers->{$site_name}
503 or die "No such oauth provider [$site_name]" ;
504
505 my $curr_profile = $c->curr_profile;
506
507 my $r = $c->_model->detach($site->{id}, $curr_profile->{id},);
508 #~ $c->app->log->debug("Убрал авторизацию сайта [$site_name] профиля [$curr_profile->{id}]", $c->dumper($r));
509
510 $Init->plugin->model->{Refs}->del($r->{ref_id}, undef, undef);
511
512 $c->redirect_to($c->param('redirect') || 'profile');
513 }
514 TEST
515
516 done_testing;