codekingpro commited on
Commit
f4e8662
·
verified ·
1 Parent(s): f339cf1

Add files using upload-large-folder tool

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. git/usr/share/perl5/core_perl/IO/Compress/Base.pm +1057 -0
  2. git/usr/share/perl5/core_perl/IO/Compress/Bzip2.pm +884 -0
  3. git/usr/share/perl5/core_perl/IO/Compress/Deflate.pm +958 -0
  4. git/usr/share/perl5/core_perl/IO/Compress/Gzip.pm +1333 -0
  5. git/usr/share/perl5/core_perl/IO/Compress/RawDeflate.pm +1076 -0
  6. git/usr/share/perl5/core_perl/JSON/PP/Boolean.pm +43 -0
  7. git/usr/share/perl5/core_perl/Math/BigFloat/Trace.pm +76 -0
  8. git/usr/share/perl5/core_perl/Math/BigInt/Calc.pm +2613 -0
  9. git/usr/share/perl5/core_perl/Math/BigInt/Lib.pm +2773 -0
  10. git/usr/share/perl5/core_perl/Math/BigInt/Trace.pm +76 -0
  11. git/usr/share/perl5/core_perl/Math/BigRat/Trace.pm +76 -0
  12. git/usr/share/perl5/core_perl/Module/CoreList/Utils.pm +2388 -0
  13. git/usr/share/perl5/core_perl/Module/Load/Conditional.pm +624 -0
  14. git/usr/share/perl5/core_perl/Net/FTP/A.pm +115 -0
  15. git/usr/share/perl5/core_perl/Net/FTP/E.pm +13 -0
  16. git/usr/share/perl5/core_perl/Net/FTP/I.pm +84 -0
  17. git/usr/share/perl5/core_perl/Net/FTP/L.pm +13 -0
  18. git/usr/share/perl5/core_perl/Net/FTP/dataconn.pm +237 -0
  19. git/usr/share/perl5/core_perl/Parse/CPAN/Meta.pm +370 -0
  20. git/usr/share/perl5/core_perl/PerlIO/via/QuotedPrint.pm +176 -0
  21. git/usr/share/perl5/core_perl/Term/Table/Cell.pm +147 -0
  22. git/usr/share/perl5/core_perl/Term/Table/CellStack.pm +130 -0
  23. git/usr/share/perl5/core_perl/Term/Table/HashBase.pm +473 -0
  24. git/usr/share/perl5/core_perl/Term/Table/LineBreak.pm +144 -0
  25. git/usr/share/perl5/core_perl/Term/Table/Spacer.pm +15 -0
  26. git/usr/share/perl5/core_perl/Term/Table/Util.pm +200 -0
  27. git/usr/share/perl5/core_perl/Test/Builder/Formatter.pm +107 -0
  28. git/usr/share/perl5/core_perl/Test/Builder/Module.pm +182 -0
  29. git/usr/share/perl5/core_perl/Test/Builder/Tester.pm +675 -0
  30. git/usr/share/perl5/core_perl/Test/Builder/Tester/Color.pm +51 -0
  31. git/usr/share/perl5/core_perl/Test/Builder/TodoDiag.pm +68 -0
  32. git/usr/share/perl5/core_perl/Test/Tester/Capture.pm +240 -0
  33. git/usr/share/perl5/core_perl/Test/Tester/CaptureRunner.pm +79 -0
  34. git/usr/share/perl5/core_perl/Test/Tester/Delegate.pm +43 -0
  35. git/usr/share/perl5/core_perl/Test/use/ok.pm +64 -0
  36. git/usr/share/perl5/core_perl/Test2/API/Breakage.pm +180 -0
  37. git/usr/share/perl5/core_perl/Test2/API/Context.pm +1036 -0
  38. git/usr/share/perl5/core_perl/Test2/API/Instance.pm +830 -0
  39. git/usr/share/perl5/core_perl/Test2/API/InterceptResult.pm +634 -0
  40. git/usr/share/perl5/core_perl/Test2/API/InterceptResult/Event.pm +1088 -0
  41. git/usr/share/perl5/core_perl/Test2/API/InterceptResult/Facet.pm +25 -0
  42. git/usr/share/perl5/core_perl/Test2/API/InterceptResult/Hub.pm +66 -0
  43. git/usr/share/perl5/core_perl/Test2/API/InterceptResult/Squasher.pm +196 -0
  44. git/usr/share/perl5/core_perl/Test2/API/Stack.pm +226 -0
  45. git/usr/share/perl5/core_perl/Test2/AsyncSubtest/Event/Attach.pm +90 -0
  46. git/usr/share/perl5/core_perl/Test2/AsyncSubtest/Event/Detach.pm +90 -0
  47. git/usr/share/perl5/core_perl/Test2/AsyncSubtest/Formatter.pm +9 -0
  48. git/usr/share/perl5/core_perl/Test2/AsyncSubtest/Hub.pm +119 -0
  49. git/usr/share/perl5/core_perl/Test2/Bundle/Extended.pm +487 -0
  50. git/usr/share/perl5/core_perl/Test2/Bundle/More.pm +241 -0
git/usr/share/perl5/core_perl/IO/Compress/Base.pm ADDED
@@ -0,0 +1,1057 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ package IO::Compress::Base ;
3
+
4
+ require 5.006 ;
5
+
6
+ use strict ;
7
+ use warnings;
8
+
9
+ use IO::Compress::Base::Common 2.213 ;
10
+
11
+ use IO::File (); ;
12
+ use Scalar::Util ();
13
+
14
+ #use File::Glob;
15
+ #require Exporter ;
16
+ use Carp() ;
17
+ use Symbol();
18
+ #use bytes;
19
+
20
+ our (@ISA, $VERSION);
21
+ @ISA = qw(IO::File Exporter);
22
+
23
+ $VERSION = '2.213';
24
+
25
+ #Can't locate object method "SWASHNEW" via package "utf8" (perhaps you forgot to load "utf8"?) at .../ext/Compress-Zlib/Gzip/blib/lib/Compress/Zlib/Common.pm line 16.
26
+
27
+ sub saveStatus
28
+ {
29
+ my $self = shift ;
30
+ ${ *$self->{ErrorNo} } = shift() + 0 ;
31
+ ${ *$self->{Error} } = '' ;
32
+
33
+ return ${ *$self->{ErrorNo} } ;
34
+ }
35
+
36
+
37
+ sub saveErrorString
38
+ {
39
+ my $self = shift ;
40
+ my $retval = shift ;
41
+ ${ *$self->{Error} } = shift ;
42
+ ${ *$self->{ErrorNo} } = shift() + 0 if @_ ;
43
+
44
+ return $retval;
45
+ }
46
+
47
+ sub croakError
48
+ {
49
+ my $self = shift ;
50
+ $self->saveErrorString(0, $_[0]);
51
+ Carp::croak $_[0];
52
+ }
53
+
54
+ sub closeError
55
+ {
56
+ my $self = shift ;
57
+ my $retval = shift ;
58
+
59
+ my $errno = *$self->{ErrorNo};
60
+ my $error = ${ *$self->{Error} };
61
+
62
+ $self->close();
63
+
64
+ *$self->{ErrorNo} = $errno ;
65
+ ${ *$self->{Error} } = $error ;
66
+
67
+ return $retval;
68
+ }
69
+
70
+
71
+
72
+ sub error
73
+ {
74
+ my $self = shift ;
75
+ return ${ *$self->{Error} } ;
76
+ }
77
+
78
+ sub errorNo
79
+ {
80
+ my $self = shift ;
81
+ return ${ *$self->{ErrorNo} } ;
82
+ }
83
+
84
+
85
+ sub writeAt
86
+ {
87
+ my $self = shift ;
88
+ my $offset = shift;
89
+ my $data = shift;
90
+
91
+ if (defined *$self->{FH}) {
92
+ my $here = tell(*$self->{FH});
93
+ return $self->saveErrorString(undef, "Cannot seek to end of output filehandle: $!", $!)
94
+ if $here < 0 ;
95
+ seek(*$self->{FH}, $offset, IO::Handle::SEEK_SET)
96
+ or return $self->saveErrorString(undef, "Cannot seek to end of output filehandle: $!", $!) ;
97
+ defined *$self->{FH}->write($data, length $data)
98
+ or return $self->saveErrorString(undef, $!, $!) ;
99
+ seek(*$self->{FH}, $here, IO::Handle::SEEK_SET)
100
+ or return $self->saveErrorString(undef, "Cannot seek to end of output filehandle: $!", $!) ;
101
+ }
102
+ else {
103
+ substr(${ *$self->{Buffer} }, $offset, length($data)) = $data ;
104
+ }
105
+
106
+ return 1;
107
+ }
108
+
109
+ sub outputPayload
110
+ {
111
+
112
+ my $self = shift ;
113
+ return $self->output(@_);
114
+ }
115
+
116
+
117
+ sub output
118
+ {
119
+ my $self = shift ;
120
+ my $data = shift ;
121
+ my $last = shift ;
122
+
123
+ return 1
124
+ if length $data == 0 && ! $last ;
125
+
126
+ if ( *$self->{FilterContainer} ) {
127
+ *_ = \$data;
128
+ &{ *$self->{FilterContainer} }();
129
+ }
130
+
131
+ if (length $data) {
132
+ if ( defined *$self->{FH} ) {
133
+ defined *$self->{FH}->write( $data, length $data )
134
+ or return $self->saveErrorString(0, $!, $!);
135
+ }
136
+ else {
137
+ ${ *$self->{Buffer} } .= $data ;
138
+ }
139
+ }
140
+
141
+ return 1;
142
+ }
143
+
144
+ sub getOneShotParams
145
+ {
146
+ return ( 'multistream' => [IO::Compress::Base::Common::Parse_boolean, 1],
147
+ );
148
+ }
149
+
150
+ our %PARAMS = (
151
+ # Generic Parameters
152
+ 'autoclose' => [IO::Compress::Base::Common::Parse_boolean, 0],
153
+ 'encode' => [IO::Compress::Base::Common::Parse_any, undef],
154
+ 'strict' => [IO::Compress::Base::Common::Parse_boolean, 1],
155
+ 'append' => [IO::Compress::Base::Common::Parse_boolean, 0],
156
+ 'binmodein' => [IO::Compress::Base::Common::Parse_boolean, 0],
157
+
158
+ 'filtercontainer' => [IO::Compress::Base::Common::Parse_code, undef],
159
+ );
160
+
161
+ sub checkParams
162
+ {
163
+ my $self = shift ;
164
+ my $class = shift ;
165
+
166
+ my $got = shift || IO::Compress::Base::Parameters::new();
167
+
168
+ $got->parse(
169
+ {
170
+ %PARAMS,
171
+
172
+
173
+ $self->getExtraParams(),
174
+ *$self->{OneShot} ? $self->getOneShotParams()
175
+ : (),
176
+ },
177
+ @_) or $self->croakError("${class}: " . $got->getError()) ;
178
+
179
+ return $got ;
180
+ }
181
+
182
+ sub _create
183
+ {
184
+ my $obj = shift;
185
+ my $got = shift;
186
+
187
+ *$obj->{Closed} = 1 ;
188
+
189
+ my $class = ref $obj;
190
+ $obj->croakError("$class: Missing Output parameter")
191
+ if ! @_ && ! $got ;
192
+
193
+ my $outValue = shift ;
194
+ my $oneShot = 1 ;
195
+
196
+ if (! $got)
197
+ {
198
+ $oneShot = 0 ;
199
+ $got = $obj->checkParams($class, undef, @_)
200
+ or return undef ;
201
+ }
202
+
203
+ my $lax = ! $got->getValue('strict') ;
204
+
205
+ my $outType = IO::Compress::Base::Common::whatIsOutput($outValue);
206
+
207
+ $obj->ckOutputParam($class, $outValue)
208
+ or return undef ;
209
+
210
+ if ($outType eq 'buffer') {
211
+ *$obj->{Buffer} = $outValue;
212
+ }
213
+ else {
214
+ my $buff = "" ;
215
+ *$obj->{Buffer} = \$buff ;
216
+ }
217
+
218
+ # Merge implies Append
219
+ my $merge = $got->getValue('merge') ;
220
+ my $appendOutput = $got->getValue('append') || $merge ;
221
+ *$obj->{Append} = $appendOutput;
222
+ *$obj->{FilterContainer} = $got->getValue('filtercontainer') ;
223
+
224
+ if ($merge)
225
+ {
226
+ # Switch off Merge mode if output file/buffer is empty/doesn't exist
227
+ if (($outType eq 'buffer' && length $$outValue == 0 ) ||
228
+ ($outType ne 'buffer' && (! -e $outValue || (-w _ && -z _))) )
229
+ { $merge = 0 }
230
+ }
231
+
232
+ # If output is a file, check that it is writable
233
+ #no warnings;
234
+ #if ($outType eq 'filename' && -e $outValue && ! -w _)
235
+ # { return $obj->saveErrorString(undef, "Output file '$outValue' is not writable" ) }
236
+
237
+ $obj->ckParams($got)
238
+ or $obj->croakError("${class}: " . $obj->error());
239
+
240
+ if ($got->getValue('encode')) {
241
+ my $want_encoding = $got->getValue('encode');
242
+ *$obj->{Encoding} = IO::Compress::Base::Common::getEncoding($obj, $class, $want_encoding);
243
+ my $x = *$obj->{Encoding};
244
+ }
245
+ else {
246
+ *$obj->{Encoding} = undef;
247
+ }
248
+
249
+ $obj->saveStatus(STATUS_OK) ;
250
+
251
+ my $status ;
252
+ if (! $merge)
253
+ {
254
+ *$obj->{Compress} = $obj->mkComp($got)
255
+ or return undef;
256
+
257
+ *$obj->{UnCompSize} = U64->new;
258
+ *$obj->{CompSize} = U64->new;
259
+
260
+ if ( $outType eq 'buffer') {
261
+ ${ *$obj->{Buffer} } = ''
262
+ unless $appendOutput ;
263
+ }
264
+ else {
265
+ if ($outType eq 'handle') {
266
+ *$obj->{FH} = $outValue ;
267
+ setBinModeOutput(*$obj->{FH}) ;
268
+ #$outValue->flush() ;
269
+ *$obj->{Handle} = 1 ;
270
+ if ($appendOutput)
271
+ {
272
+ seek(*$obj->{FH}, 0, IO::Handle::SEEK_END)
273
+ or return $obj->saveErrorString(undef, "Cannot seek to end of output filehandle: $!", $!) ;
274
+
275
+ }
276
+ }
277
+ elsif ($outType eq 'filename') {
278
+ no warnings;
279
+ my $mode = '>' ;
280
+ $mode = '>>'
281
+ if $appendOutput;
282
+ *$obj->{FH} = IO::File->new( "$mode $outValue" )
283
+ or return $obj->saveErrorString(undef, "cannot open file '$outValue': $!", $!) ;
284
+ *$obj->{StdIO} = ($outValue eq '-');
285
+ setBinModeOutput(*$obj->{FH}) ;
286
+ }
287
+ }
288
+
289
+ *$obj->{Header} = $obj->mkHeader($got) ;
290
+ $obj->output( *$obj->{Header} )
291
+ or return undef;
292
+ $obj->beforePayload();
293
+ }
294
+ else
295
+ {
296
+ *$obj->{Compress} = $obj->createMerge($outValue, $outType)
297
+ or return undef;
298
+ }
299
+
300
+ *$obj->{Closed} = 0 ;
301
+ *$obj->{AutoClose} = $got->getValue('autoclose') ;
302
+ *$obj->{Output} = $outValue;
303
+ *$obj->{ClassName} = $class;
304
+ *$obj->{Got} = $got;
305
+ *$obj->{OneShot} = 0 ;
306
+
307
+ return $obj ;
308
+ }
309
+
310
+ sub ckOutputParam
311
+ {
312
+ my $self = shift ;
313
+ my $from = shift ;
314
+ my $outType = IO::Compress::Base::Common::whatIsOutput($_[0]);
315
+
316
+ $self->croakError("$from: output parameter not a filename, filehandle or scalar ref")
317
+ if ! $outType ;
318
+
319
+ #$self->croakError("$from: output filename is undef or null string")
320
+ #if $outType eq 'filename' && (! defined $_[0] || $_[0] eq '') ;
321
+
322
+ $self->croakError("$from: output buffer is read-only")
323
+ if $outType eq 'buffer' && Scalar::Util::readonly(${ $_[0] });
324
+
325
+ return 1;
326
+ }
327
+
328
+
329
+ sub _def
330
+ {
331
+ my $obj = shift ;
332
+
333
+ my $class= (caller)[0] ;
334
+ my $name = (caller(1))[3] ;
335
+
336
+ $obj->croakError("$name: expected at least 1 parameters\n")
337
+ unless @_ >= 1 ;
338
+
339
+ my $input = shift ;
340
+ my $haveOut = @_ ;
341
+ my $output = shift ;
342
+
343
+ my $x = IO::Compress::Base::Validator->new($class, *$obj->{Error}, $name, $input, $output)
344
+ or return undef ;
345
+
346
+ push @_, $output if $haveOut && $x->{Hash};
347
+
348
+ *$obj->{OneShot} = 1 ;
349
+
350
+ my $got = $obj->checkParams($name, undef, @_)
351
+ or return undef ;
352
+
353
+ $x->{Got} = $got ;
354
+
355
+ # if ($x->{Hash})
356
+ # {
357
+ # while (my($k, $v) = each %$input)
358
+ # {
359
+ # $v = \$input->{$k}
360
+ # unless defined $v ;
361
+ #
362
+ # $obj->_singleTarget($x, 1, $k, $v, @_)
363
+ # or return undef ;
364
+ # }
365
+ #
366
+ # return keys %$input ;
367
+ # }
368
+
369
+ if ($x->{GlobMap})
370
+ {
371
+ $x->{oneInput} = 1 ;
372
+ foreach my $pair (@{ $x->{Pairs} })
373
+ {
374
+ my ($from, $to) = @$pair ;
375
+ $obj->_singleTarget($x, 1, $from, $to, @_)
376
+ or return undef ;
377
+ }
378
+
379
+ return scalar @{ $x->{Pairs} } ;
380
+ }
381
+
382
+ if (! $x->{oneOutput} )
383
+ {
384
+ my $inFile = ($x->{inType} eq 'filenames'
385
+ || $x->{inType} eq 'filename');
386
+
387
+ $x->{inType} = $inFile ? 'filename' : 'buffer';
388
+
389
+ foreach my $in ($x->{oneInput} ? $input : @$input)
390
+ {
391
+ my $out ;
392
+ $x->{oneInput} = 1 ;
393
+
394
+ $obj->_singleTarget($x, $inFile, $in, \$out, @_)
395
+ or return undef ;
396
+
397
+ push @$output, \$out ;
398
+ #if ($x->{outType} eq 'array')
399
+ # { push @$output, \$out }
400
+ #else
401
+ # { $output->{$in} = \$out }
402
+ }
403
+
404
+ return 1 ;
405
+ }
406
+
407
+ # finally the 1 to 1 and n to 1
408
+ return $obj->_singleTarget($x, 1, $input, $output, @_);
409
+
410
+ Carp::croak "should not be here" ;
411
+ }
412
+
413
+ sub _singleTarget
414
+ {
415
+ my $obj = shift ;
416
+ my $x = shift ;
417
+ my $inputIsFilename = shift;
418
+ my $input = shift;
419
+
420
+ if ($x->{oneInput})
421
+ {
422
+ $obj->getFileInfo($x->{Got}, $input)
423
+ if isaScalar($input) || (isaFilename($input) and $inputIsFilename) ;
424
+
425
+ my $z = $obj->_create($x->{Got}, @_)
426
+ or return undef ;
427
+
428
+
429
+ defined $z->_wr2($input, $inputIsFilename)
430
+ or return $z->closeError(undef) ;
431
+
432
+ return $z->close() ;
433
+ }
434
+ else
435
+ {
436
+ my $afterFirst = 0 ;
437
+ my $inputIsFilename = ($x->{inType} ne 'array');
438
+ my $keep = $x->{Got}->clone();
439
+
440
+ #for my $element ( ($x->{inType} eq 'hash') ? keys %$input : @$input)
441
+ for my $element ( @$input)
442
+ {
443
+ my $isFilename = isaFilename($element);
444
+
445
+ if ( $afterFirst ++ )
446
+ {
447
+ defined addInterStream($obj, $element, $isFilename)
448
+ or return $obj->closeError(undef) ;
449
+ }
450
+ else
451
+ {
452
+ $obj->getFileInfo($x->{Got}, $element)
453
+ if isaScalar($element) || $isFilename;
454
+
455
+ $obj->_create($x->{Got}, @_)
456
+ or return undef ;
457
+ }
458
+
459
+ defined $obj->_wr2($element, $isFilename)
460
+ or return $obj->closeError(undef) ;
461
+
462
+ *$obj->{Got} = $keep->clone();
463
+ }
464
+ return $obj->close() ;
465
+ }
466
+
467
+ }
468
+
469
+ sub _wr2
470
+ {
471
+ my $self = shift ;
472
+
473
+ my $source = shift ;
474
+ my $inputIsFilename = shift;
475
+
476
+ my $input = $source ;
477
+ if (! $inputIsFilename)
478
+ {
479
+ $input = \$source
480
+ if ! ref $source;
481
+ }
482
+
483
+ if ( ref $input && ref $input eq 'SCALAR' )
484
+ {
485
+ return $self->syswrite($input, @_) ;
486
+ }
487
+
488
+ if ( ! ref $input || isaFilehandle($input))
489
+ {
490
+ my $isFilehandle = isaFilehandle($input) ;
491
+
492
+ my $fh = $input ;
493
+
494
+ if ( ! $isFilehandle )
495
+ {
496
+ $fh = IO::File->new( "<$input" )
497
+ or return $self->saveErrorString(undef, "cannot open file '$input': $!", $!) ;
498
+ }
499
+ binmode $fh ;
500
+
501
+ my $status ;
502
+ my $buff ;
503
+ my $count = 0 ;
504
+ while ($status = read($fh, $buff, 16 * 1024)) {
505
+ $count += length $buff;
506
+ defined $self->syswrite($buff, @_)
507
+ or return undef ;
508
+ }
509
+
510
+ return $self->saveErrorString(undef, $!, $!)
511
+ if ! defined $status ;
512
+
513
+ if ( (!$isFilehandle || *$self->{AutoClose}) && $input ne '-')
514
+ {
515
+ $fh->close()
516
+ or return undef ;
517
+ }
518
+
519
+ return $count ;
520
+ }
521
+
522
+ Carp::croak "Should not be here";
523
+ return undef;
524
+ }
525
+
526
+ sub addInterStream
527
+ {
528
+ my $self = shift ;
529
+ my $input = shift ;
530
+ my $inputIsFilename = shift ;
531
+
532
+ if (*$self->{Got}->getValue('multistream'))
533
+ {
534
+ $self->getFileInfo(*$self->{Got}, $input)
535
+ #if isaFilename($input) and $inputIsFilename ;
536
+ if isaScalar($input) || isaFilename($input) ;
537
+
538
+ # TODO -- newStream needs to allow gzip/zip header to be modified
539
+ return $self->newStream();
540
+ }
541
+ elsif (*$self->{Got}->getValue('autoflush'))
542
+ {
543
+ #return $self->flush(Z_FULL_FLUSH);
544
+ }
545
+
546
+ return 1 ;
547
+ }
548
+
549
+ sub getFileInfo
550
+ {
551
+ }
552
+
553
+ sub TIEHANDLE
554
+ {
555
+ return $_[0] if ref($_[0]);
556
+ die "OOPS\n" ;
557
+ }
558
+
559
+ sub UNTIE
560
+ {
561
+ my $self = shift ;
562
+ }
563
+
564
+ sub DESTROY
565
+ {
566
+ my $self = shift ;
567
+ local ($., $@, $!, $^E, $?);
568
+
569
+ $self->close() ;
570
+
571
+ # TODO - memory leak with 5.8.0 - this isn't called until
572
+ # global destruction
573
+ #
574
+ %{ *$self } = () ;
575
+ undef $self ;
576
+ }
577
+
578
+
579
+
580
+ sub filterUncompressed
581
+ {
582
+ }
583
+
584
+ sub syswrite
585
+ {
586
+ my $self = shift ;
587
+
588
+ my $buffer ;
589
+ if (ref $_[0] ) {
590
+ $self->croakError( *$self->{ClassName} . "::write: not a scalar reference" )
591
+ unless ref $_[0] eq 'SCALAR' ;
592
+ $buffer = $_[0] ;
593
+ }
594
+ else {
595
+ $buffer = \$_[0] ;
596
+ }
597
+
598
+ if (@_ > 1) {
599
+ my $slen = defined $$buffer ? length($$buffer) : 0;
600
+ my $len = $slen;
601
+ my $offset = 0;
602
+ $len = $_[1] if $_[1] < $len;
603
+
604
+ if (@_ > 2) {
605
+ $offset = $_[2] || 0;
606
+ $self->croakError(*$self->{ClassName} . "::write: offset outside string")
607
+ if $offset > $slen;
608
+ if ($offset < 0) {
609
+ $offset += $slen;
610
+ $self->croakError( *$self->{ClassName} . "::write: offset outside string") if $offset < 0;
611
+ }
612
+ my $rem = $slen - $offset;
613
+ $len = $rem if $rem < $len;
614
+ }
615
+
616
+ $buffer = \substr($$buffer, $offset, $len) ;
617
+ }
618
+
619
+ return 0 if (! defined $$buffer || length $$buffer == 0) && ! *$self->{FlushPending};
620
+
621
+ # *$self->{Pending} .= $$buffer ;
622
+ #
623
+ # return length $$buffer
624
+ # if (length *$self->{Pending} < 1024 * 16 && ! *$self->{FlushPending}) ;
625
+ #
626
+ # $$buffer = *$self->{Pending} ;
627
+ # *$self->{Pending} = '';
628
+
629
+ if (*$self->{Encoding}) {
630
+ $$buffer = *$self->{Encoding}->encode($$buffer);
631
+ }
632
+ else {
633
+ $] >= 5.008 and ( utf8::downgrade($$buffer, 1)
634
+ or Carp::croak "Wide character in " . *$self->{ClassName} . "::write:");
635
+ }
636
+
637
+ $self->filterUncompressed($buffer);
638
+
639
+ my $buffer_length = defined $$buffer ? length($$buffer) : 0 ;
640
+ *$self->{UnCompSize}->add($buffer_length) ;
641
+
642
+ my $outBuffer='';
643
+ my $status = *$self->{Compress}->compr($buffer, $outBuffer) ;
644
+
645
+ return $self->saveErrorString(undef, *$self->{Compress}{Error},
646
+ *$self->{Compress}{ErrorNo})
647
+ if $status == STATUS_ERROR;
648
+
649
+ *$self->{CompSize}->add(length $outBuffer) ;
650
+
651
+ $self->outputPayload($outBuffer)
652
+ or return undef;
653
+
654
+ return $buffer_length;
655
+ }
656
+
657
+ sub print
658
+ {
659
+ my $self = shift;
660
+
661
+ #if (ref $self) {
662
+ # $self = *$self{GLOB} ;
663
+ #}
664
+
665
+ if (defined $\) {
666
+ if (defined $,) {
667
+ defined $self->syswrite(join($,, @_) . $\);
668
+ } else {
669
+ defined $self->syswrite(join("", @_) . $\);
670
+ }
671
+ } else {
672
+ if (defined $,) {
673
+ defined $self->syswrite(join($,, @_));
674
+ } else {
675
+ defined $self->syswrite(join("", @_));
676
+ }
677
+ }
678
+ }
679
+
680
+ sub printf
681
+ {
682
+ my $self = shift;
683
+ my $fmt = shift;
684
+ defined $self->syswrite(sprintf($fmt, @_));
685
+ }
686
+
687
+ sub _flushCompressed
688
+ {
689
+ my $self = shift ;
690
+
691
+ my $outBuffer='';
692
+ my $status = *$self->{Compress}->flush($outBuffer, @_) ;
693
+ return $self->saveErrorString(0, *$self->{Compress}{Error},
694
+ *$self->{Compress}{ErrorNo})
695
+ if $status == STATUS_ERROR;
696
+
697
+ if ( defined *$self->{FH} ) {
698
+ *$self->{FH}->clearerr();
699
+ }
700
+
701
+ *$self->{CompSize}->add(length $outBuffer) ;
702
+
703
+ $self->outputPayload($outBuffer)
704
+ or return 0;
705
+ return 1;
706
+ }
707
+
708
+ sub flush
709
+ {
710
+ my $self = shift ;
711
+
712
+ $self->_flushCompressed(@_)
713
+ or return 0;
714
+
715
+ if ( defined *$self->{FH} ) {
716
+ defined *$self->{FH}->flush()
717
+ or return $self->saveErrorString(0, $!, $!);
718
+ }
719
+
720
+ return 1;
721
+ }
722
+
723
+ sub beforePayload
724
+ {
725
+ }
726
+
727
+ sub _newStream
728
+ {
729
+ my $self = shift ;
730
+ my $got = shift;
731
+
732
+ my $class = ref $self;
733
+
734
+ $self->_writeTrailer()
735
+ or return 0 ;
736
+
737
+ $self->ckParams($got)
738
+ or $self->croakError("newStream: $self->{Error}");
739
+
740
+ if ($got->getValue('encode')) {
741
+ my $want_encoding = $got->getValue('encode');
742
+ *$self->{Encoding} = IO::Compress::Base::Common::getEncoding($self, $class, $want_encoding);
743
+ }
744
+ else {
745
+ *$self->{Encoding} = undef;
746
+ }
747
+
748
+ *$self->{Compress} = $self->mkComp($got)
749
+ or return 0;
750
+
751
+ *$self->{Header} = $self->mkHeader($got) ;
752
+ $self->output(*$self->{Header} )
753
+ or return 0;
754
+
755
+ *$self->{UnCompSize}->reset();
756
+ *$self->{CompSize}->reset();
757
+
758
+ $self->beforePayload();
759
+
760
+ return 1 ;
761
+ }
762
+
763
+ sub newStream
764
+ {
765
+ my $self = shift ;
766
+
767
+ my $got = $self->checkParams('newStream', *$self->{Got}, @_)
768
+ or return 0 ;
769
+
770
+ $self->_newStream($got);
771
+
772
+ # *$self->{Compress} = $self->mkComp($got)
773
+ # or return 0;
774
+ #
775
+ # *$self->{Header} = $self->mkHeader($got) ;
776
+ # $self->output(*$self->{Header} )
777
+ # or return 0;
778
+ #
779
+ # *$self->{UnCompSize}->reset();
780
+ # *$self->{CompSize}->reset();
781
+ #
782
+ # $self->beforePayload();
783
+ #
784
+ # return 1 ;
785
+ }
786
+
787
+ sub reset
788
+ {
789
+ my $self = shift ;
790
+ return *$self->{Compress}->reset() ;
791
+ }
792
+
793
+ sub _writeTrailer
794
+ {
795
+ my $self = shift ;
796
+
797
+ my $trailer = '';
798
+
799
+ my $status = *$self->{Compress}->close($trailer) ;
800
+
801
+ return $self->saveErrorString(0, *$self->{Compress}{Error}, *$self->{Compress}{ErrorNo})
802
+ if $status == STATUS_ERROR;
803
+
804
+ *$self->{CompSize}->add(length $trailer) ;
805
+
806
+ $trailer .= $self->mkTrailer();
807
+ defined $trailer
808
+ or return 0;
809
+ return $self->output($trailer);
810
+ }
811
+
812
+ sub _writeFinalTrailer
813
+ {
814
+ my $self = shift ;
815
+
816
+ return $self->output($self->mkFinalTrailer());
817
+ }
818
+
819
+ sub close
820
+ {
821
+ my $self = shift ;
822
+ return 1 if *$self->{Closed} || ! *$self->{Compress} ;
823
+ *$self->{Closed} = 1 ;
824
+
825
+ untie *$self
826
+ if $] >= 5.008 ;
827
+
828
+ *$self->{FlushPending} = 1 ;
829
+ $self->_writeTrailer()
830
+ or return 0 ;
831
+
832
+ $self->_writeFinalTrailer()
833
+ or return 0 ;
834
+
835
+ $self->output( "", 1 )
836
+ or return 0;
837
+
838
+ if (defined *$self->{FH}) {
839
+
840
+ if ((! *$self->{Handle} || *$self->{AutoClose}) && ! *$self->{StdIO}) {
841
+ $! = 0 ;
842
+ *$self->{FH}->close()
843
+ or return $self->saveErrorString(0, $!, $!);
844
+ }
845
+ delete *$self->{FH} ;
846
+ # This delete can set $! in older Perls, so reset the errno
847
+ $! = 0 ;
848
+ }
849
+
850
+ return 1;
851
+ }
852
+
853
+
854
+ #sub total_in
855
+ #sub total_out
856
+ #sub msg
857
+ #
858
+ #sub crc
859
+ #{
860
+ # my $self = shift ;
861
+ # return *$self->{Compress}->crc32() ;
862
+ #}
863
+ #
864
+ #sub msg
865
+ #{
866
+ # my $self = shift ;
867
+ # return *$self->{Compress}->msg() ;
868
+ #}
869
+ #
870
+ #sub dict_adler
871
+ #{
872
+ # my $self = shift ;
873
+ # return *$self->{Compress}->dict_adler() ;
874
+ #}
875
+ #
876
+ #sub get_Level
877
+ #{
878
+ # my $self = shift ;
879
+ # return *$self->{Compress}->get_Level() ;
880
+ #}
881
+ #
882
+ #sub get_Strategy
883
+ #{
884
+ # my $self = shift ;
885
+ # return *$self->{Compress}->get_Strategy() ;
886
+ #}
887
+
888
+
889
+ sub tell
890
+ {
891
+ my $self = shift ;
892
+
893
+ return *$self->{UnCompSize}->get32bit() ;
894
+ }
895
+
896
+ sub eof
897
+ {
898
+ my $self = shift ;
899
+
900
+ return *$self->{Closed} ;
901
+ }
902
+
903
+
904
+ sub seek
905
+ {
906
+ my $self = shift ;
907
+ my $position = shift;
908
+ my $whence = shift ;
909
+
910
+ my $here = $self->tell() ;
911
+ my $target = 0 ;
912
+
913
+ #use IO::Handle qw(SEEK_SET SEEK_CUR SEEK_END);
914
+ use IO::Handle ;
915
+
916
+ if ($whence == IO::Handle::SEEK_SET) {
917
+ $target = $position ;
918
+ }
919
+ elsif ($whence == IO::Handle::SEEK_CUR || $whence == IO::Handle::SEEK_END) {
920
+ $target = $here + $position ;
921
+ }
922
+ else {
923
+ $self->croakError(*$self->{ClassName} . "::seek: unknown value, $whence, for whence parameter");
924
+ }
925
+
926
+ # short circuit if seeking to current offset
927
+ return 1 if $target == $here ;
928
+
929
+ # Outlaw any attempt to seek backwards
930
+ $self->croakError(*$self->{ClassName} . "::seek: cannot seek backwards")
931
+ if $target < $here ;
932
+
933
+ # Walk the file to the new offset
934
+ my $offset = $target - $here ;
935
+
936
+ my $buffer ;
937
+ defined $self->syswrite("\x00" x $offset)
938
+ or return 0;
939
+
940
+ return 1 ;
941
+ }
942
+
943
+ sub binmode
944
+ {
945
+ 1;
946
+ # my $self = shift ;
947
+ # return defined *$self->{FH}
948
+ # ? binmode *$self->{FH}
949
+ # : 1 ;
950
+ }
951
+
952
+ sub fileno
953
+ {
954
+ my $self = shift ;
955
+ return defined *$self->{FH}
956
+ ? *$self->{FH}->fileno()
957
+ : undef ;
958
+ }
959
+
960
+ sub opened
961
+ {
962
+ my $self = shift ;
963
+ return ! *$self->{Closed} ;
964
+ }
965
+
966
+ sub autoflush
967
+ {
968
+ my $self = shift ;
969
+ return defined *$self->{FH}
970
+ ? *$self->{FH}->autoflush(@_)
971
+ : undef ;
972
+ }
973
+
974
+ sub input_line_number
975
+ {
976
+ return undef ;
977
+ }
978
+
979
+
980
+ sub _notAvailable
981
+ {
982
+ my $name = shift ;
983
+ return sub { Carp::croak "$name Not Available: File opened only for output" ; } ;
984
+ }
985
+
986
+ {
987
+ no warnings 'once';
988
+
989
+ *read = _notAvailable('read');
990
+ *READ = _notAvailable('read');
991
+ *readline = _notAvailable('readline');
992
+ *READLINE = _notAvailable('readline');
993
+ *getc = _notAvailable('getc');
994
+ *GETC = _notAvailable('getc');
995
+
996
+ *FILENO = \&fileno;
997
+ *PRINT = \&print;
998
+ *PRINTF = \&printf;
999
+ *WRITE = \&syswrite;
1000
+ *write = \&syswrite;
1001
+ *SEEK = \&seek;
1002
+ *TELL = \&tell;
1003
+ *EOF = \&eof;
1004
+ *CLOSE = \&close;
1005
+ *BINMODE = \&binmode;
1006
+ }
1007
+
1008
+ #*sysread = \&_notAvailable;
1009
+ #*syswrite = \&_write;
1010
+
1011
+ 1;
1012
+
1013
+ __END__
1014
+
1015
+ =head1 NAME
1016
+
1017
+ IO::Compress::Base - Base Class for IO::Compress modules
1018
+
1019
+ =head1 SYNOPSIS
1020
+
1021
+ use IO::Compress::Base ;
1022
+
1023
+ =head1 DESCRIPTION
1024
+
1025
+ This module is not intended for direct use in application code. Its sole
1026
+ purpose is to be sub-classed by IO::Compress modules.
1027
+
1028
+ =head1 SUPPORT
1029
+
1030
+ General feedback/questions/bug reports should be sent to
1031
+ L<https://github.com/pmqs/IO-Compress/issues> (preferred) or
1032
+ L<https://rt.cpan.org/Public/Dist/Display.html?Name=IO-Compress>.
1033
+
1034
+ =head1 SEE ALSO
1035
+
1036
+ L<Compress::Zlib>, L<IO::Compress::Gzip>, L<IO::Uncompress::Gunzip>, L<IO::Compress::Deflate>, L<IO::Uncompress::Inflate>, L<IO::Compress::RawDeflate>, L<IO::Uncompress::RawInflate>, L<IO::Compress::Bzip2>, L<IO::Uncompress::Bunzip2>, L<IO::Compress::Lzma>, L<IO::Uncompress::UnLzma>, L<IO::Compress::Xz>, L<IO::Uncompress::UnXz>, L<IO::Compress::Lzip>, L<IO::Uncompress::UnLzip>, L<IO::Compress::Lzop>, L<IO::Uncompress::UnLzop>, L<IO::Compress::Lzf>, L<IO::Uncompress::UnLzf>, L<IO::Compress::Zstd>, L<IO::Uncompress::UnZstd>, L<IO::Uncompress::AnyInflate>, L<IO::Uncompress::AnyUncompress>
1037
+
1038
+ L<IO::Compress::FAQ|IO::Compress::FAQ>
1039
+
1040
+ L<File::GlobMapper|File::GlobMapper>, L<Archive::Zip|Archive::Zip>,
1041
+ L<Archive::Tar|Archive::Tar>,
1042
+ L<IO::Zlib|IO::Zlib>
1043
+
1044
+ =head1 AUTHOR
1045
+
1046
+ This module was written by Paul Marquess, C<pmqs@cpan.org>.
1047
+
1048
+ =head1 MODIFICATION HISTORY
1049
+
1050
+ See the Changes file.
1051
+
1052
+ =head1 COPYRIGHT AND LICENSE
1053
+
1054
+ Copyright (c) 2005-2024 Paul Marquess. All rights reserved.
1055
+
1056
+ This program is free software; you can redistribute it and/or
1057
+ modify it under the same terms as Perl itself.
git/usr/share/perl5/core_perl/IO/Compress/Bzip2.pm ADDED
@@ -0,0 +1,884 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package IO::Compress::Bzip2 ;
2
+
3
+ use strict ;
4
+ use warnings;
5
+ use bytes;
6
+ require Exporter ;
7
+
8
+ use IO::Compress::Base 2.213 ;
9
+
10
+ use IO::Compress::Base::Common 2.213 qw();
11
+ use IO::Compress::Adapter::Bzip2 2.213 ;
12
+
13
+
14
+
15
+ our ($VERSION, @ISA, @EXPORT_OK, %EXPORT_TAGS, $Bzip2Error);
16
+
17
+ $VERSION = '2.213';
18
+ $Bzip2Error = '';
19
+
20
+ @ISA = qw(IO::Compress::Base Exporter);
21
+ @EXPORT_OK = qw( $Bzip2Error bzip2 ) ;
22
+ %EXPORT_TAGS = %IO::Compress::Base::EXPORT_TAGS ;
23
+ push @{ $EXPORT_TAGS{all} }, @EXPORT_OK ;
24
+ Exporter::export_ok_tags('all');
25
+
26
+
27
+
28
+ sub new
29
+ {
30
+ my $class = shift ;
31
+
32
+ my $obj = IO::Compress::Base::Common::createSelfTiedObject($class, \$Bzip2Error);
33
+ return $obj->_create(undef, @_);
34
+ }
35
+
36
+ sub bzip2
37
+ {
38
+ my $obj = IO::Compress::Base::Common::createSelfTiedObject(undef, \$Bzip2Error);
39
+ $obj->_def(@_);
40
+ }
41
+
42
+
43
+ sub mkHeader
44
+ {
45
+ my $self = shift ;
46
+ return '';
47
+
48
+ }
49
+
50
+ sub getExtraParams
51
+ {
52
+ my $self = shift ;
53
+
54
+ use IO::Compress::Base::Common 2.213 qw(:Parse);
55
+
56
+ return (
57
+ 'blocksize100k' => [IO::Compress::Base::Common::Parse_unsigned, 1],
58
+ 'workfactor' => [IO::Compress::Base::Common::Parse_unsigned, 0],
59
+ 'verbosity' => [IO::Compress::Base::Common::Parse_boolean, 0],
60
+ );
61
+ }
62
+
63
+
64
+
65
+ sub ckParams
66
+ {
67
+ my $self = shift ;
68
+ my $got = shift;
69
+
70
+ # check that BlockSize100K is a number between 1 & 9
71
+ if ($got->parsed('blocksize100k')) {
72
+ my $value = $got->getValue('blocksize100k');
73
+ return $self->saveErrorString(undef, "Parameter 'BlockSize100K' not between 1 and 9, got $value")
74
+ unless defined $value && $value >= 1 && $value <= 9;
75
+
76
+ }
77
+
78
+ # check that WorkFactor between 0 & 250
79
+ if ($got->parsed('workfactor')) {
80
+ my $value = $got->getValue('workfactor');
81
+ return $self->saveErrorString(undef, "Parameter 'WorkFactor' not between 0 and 250, got $value")
82
+ unless $value >= 0 && $value <= 250;
83
+ }
84
+
85
+ return 1 ;
86
+ }
87
+
88
+
89
+ sub mkComp
90
+ {
91
+ my $self = shift ;
92
+ my $got = shift ;
93
+
94
+ my $BlockSize100K = $got->getValue('blocksize100k');
95
+ my $WorkFactor = $got->getValue('workfactor');
96
+ my $Verbosity = $got->getValue('verbosity');
97
+
98
+ my ($obj, $errstr, $errno) = IO::Compress::Adapter::Bzip2::mkCompObject(
99
+ $BlockSize100K, $WorkFactor,
100
+ $Verbosity);
101
+
102
+ return $self->saveErrorString(undef, $errstr, $errno)
103
+ if ! defined $obj;
104
+
105
+ return $obj;
106
+ }
107
+
108
+
109
+ sub mkTrailer
110
+ {
111
+ my $self = shift ;
112
+ return '';
113
+ }
114
+
115
+ sub mkFinalTrailer
116
+ {
117
+ return '';
118
+ }
119
+
120
+ #sub newHeader
121
+ #{
122
+ # my $self = shift ;
123
+ # return '';
124
+ #}
125
+
126
+ sub getInverseClass
127
+ {
128
+ return ('IO::Uncompress::Bunzip2');
129
+ }
130
+
131
+ sub getFileInfo
132
+ {
133
+ my $self = shift ;
134
+ my $params = shift;
135
+ my $file = shift ;
136
+
137
+ }
138
+
139
+ 1;
140
+
141
+ __END__
142
+
143
+ =head1 NAME
144
+
145
+ IO::Compress::Bzip2 - Write bzip2 files/buffers
146
+
147
+ =head1 SYNOPSIS
148
+
149
+ use IO::Compress::Bzip2 qw(bzip2 $Bzip2Error) ;
150
+
151
+ my $status = bzip2 $input => $output [,OPTS]
152
+ or die "bzip2 failed: $Bzip2Error\n";
153
+
154
+ my $z = IO::Compress::Bzip2->new( $output [,OPTS] )
155
+ or die "bzip2 failed: $Bzip2Error\n";
156
+
157
+ $z->print($string);
158
+ $z->printf($format, $string);
159
+ $z->write($string);
160
+ $z->syswrite($string [, $length, $offset]);
161
+ $z->flush();
162
+ $z->tell();
163
+ $z->eof();
164
+ $z->seek($position, $whence);
165
+ $z->binmode();
166
+ $z->fileno();
167
+ $z->opened();
168
+ $z->autoflush();
169
+ $z->input_line_number();
170
+ $z->newStream( [OPTS] );
171
+
172
+ $z->close() ;
173
+
174
+ $Bzip2Error ;
175
+
176
+ # IO::File mode
177
+
178
+ print $z $string;
179
+ printf $z $format, $string;
180
+ tell $z
181
+ eof $z
182
+ seek $z, $position, $whence
183
+ binmode $z
184
+ fileno $z
185
+ close $z ;
186
+
187
+ =head1 DESCRIPTION
188
+
189
+ This module provides a Perl interface that allows writing bzip2
190
+ compressed data to files or buffer.
191
+
192
+ For reading bzip2 files/buffers, see the companion module
193
+ L<IO::Uncompress::Bunzip2|IO::Uncompress::Bunzip2>.
194
+
195
+ =head1 Functional Interface
196
+
197
+ A top-level function, C<bzip2>, is provided to carry out
198
+ "one-shot" compression between buffers and/or files. For finer
199
+ control over the compression process, see the L</"OO Interface">
200
+ section.
201
+
202
+ use IO::Compress::Bzip2 qw(bzip2 $Bzip2Error) ;
203
+
204
+ bzip2 $input_filename_or_reference => $output_filename_or_reference [,OPTS]
205
+ or die "bzip2 failed: $Bzip2Error\n";
206
+
207
+ The functional interface needs Perl5.005 or better.
208
+
209
+ =head2 bzip2 $input_filename_or_reference => $output_filename_or_reference [, OPTS]
210
+
211
+ C<bzip2> expects at least two parameters,
212
+ C<$input_filename_or_reference> and C<$output_filename_or_reference>
213
+ and zero or more optional parameters (see L</Optional Parameters>)
214
+
215
+ =head3 The C<$input_filename_or_reference> parameter
216
+
217
+ The parameter, C<$input_filename_or_reference>, is used to define the
218
+ source of the uncompressed data.
219
+
220
+ It can take one of the following forms:
221
+
222
+ =over 5
223
+
224
+ =item A filename
225
+
226
+ If the C<$input_filename_or_reference> parameter is a simple scalar, it is
227
+ assumed to be a filename. This file will be opened for reading and the
228
+ input data will be read from it.
229
+
230
+ =item A filehandle
231
+
232
+ If the C<$input_filename_or_reference> parameter is a filehandle, the input
233
+ data will be read from it. The string '-' can be used as an alias for
234
+ standard input.
235
+
236
+ =item A scalar reference
237
+
238
+ If C<$input_filename_or_reference> is a scalar reference, the input data
239
+ will be read from C<$$input_filename_or_reference>.
240
+
241
+ =item An array reference
242
+
243
+ If C<$input_filename_or_reference> is an array reference, each element in
244
+ the array must be a filename.
245
+
246
+ The input data will be read from each file in turn.
247
+
248
+ The complete array will be walked to ensure that it only
249
+ contains valid filenames before any data is compressed.
250
+
251
+ =item An Input FileGlob string
252
+
253
+ If C<$input_filename_or_reference> is a string that is delimited by the
254
+ characters "<" and ">" C<bzip2> will assume that it is an
255
+ I<input fileglob string>. The input is the list of files that match the
256
+ fileglob.
257
+
258
+ See L<File::GlobMapper|File::GlobMapper> for more details.
259
+
260
+ =back
261
+
262
+ If the C<$input_filename_or_reference> parameter is any other type,
263
+ C<undef> will be returned.
264
+
265
+ =head3 The C<$output_filename_or_reference> parameter
266
+
267
+ The parameter C<$output_filename_or_reference> is used to control the
268
+ destination of the compressed data. This parameter can take one of
269
+ these forms.
270
+
271
+ =over 5
272
+
273
+ =item A filename
274
+
275
+ If the C<$output_filename_or_reference> parameter is a simple scalar, it is
276
+ assumed to be a filename. This file will be opened for writing and the
277
+ compressed data will be written to it.
278
+
279
+ =item A filehandle
280
+
281
+ If the C<$output_filename_or_reference> parameter is a filehandle, the
282
+ compressed data will be written to it. The string '-' can be used as
283
+ an alias for standard output.
284
+
285
+ =item A scalar reference
286
+
287
+ If C<$output_filename_or_reference> is a scalar reference, the
288
+ compressed data will be stored in C<$$output_filename_or_reference>.
289
+
290
+ =item An Array Reference
291
+
292
+ If C<$output_filename_or_reference> is an array reference,
293
+ the compressed data will be pushed onto the array.
294
+
295
+ =item An Output FileGlob
296
+
297
+ If C<$output_filename_or_reference> is a string that is delimited by the
298
+ characters "<" and ">" C<bzip2> will assume that it is an
299
+ I<output fileglob string>. The output is the list of files that match the
300
+ fileglob.
301
+
302
+ When C<$output_filename_or_reference> is an fileglob string,
303
+ C<$input_filename_or_reference> must also be a fileglob string. Anything
304
+ else is an error.
305
+
306
+ See L<File::GlobMapper|File::GlobMapper> for more details.
307
+
308
+ =back
309
+
310
+ If the C<$output_filename_or_reference> parameter is any other type,
311
+ C<undef> will be returned.
312
+
313
+ =head2 Notes
314
+
315
+ When C<$input_filename_or_reference> maps to multiple files/buffers and
316
+ C<$output_filename_or_reference> is a single
317
+ file/buffer the input files/buffers will be stored
318
+ in C<$output_filename_or_reference> as a concatenated series of compressed data streams.
319
+
320
+ =head2 Optional Parameters
321
+
322
+ The optional parameters for the one-shot function C<bzip2>
323
+ are (for the most part) identical to those used with the OO interface defined in the
324
+ L</"Constructor Options"> section. The exceptions are listed below
325
+
326
+ =over 5
327
+
328
+ =item C<< AutoClose => 0|1 >>
329
+
330
+ This option applies to any input or output data streams to
331
+ C<bzip2> that are filehandles.
332
+
333
+ If C<AutoClose> is specified, and the value is true, it will result in all
334
+ input and/or output filehandles being closed once C<bzip2> has
335
+ completed.
336
+
337
+ This parameter defaults to 0.
338
+
339
+ =item C<< BinModeIn => 0|1 >>
340
+
341
+ This option is now a no-op. All files will be read in binmode.
342
+
343
+ =item C<< Append => 0|1 >>
344
+
345
+ The behaviour of this option is dependent on the type of output data
346
+ stream.
347
+
348
+ =over 5
349
+
350
+ =item * A Buffer
351
+
352
+ If C<Append> is enabled, all compressed data will be append to the end of
353
+ the output buffer. Otherwise the output buffer will be cleared before any
354
+ compressed data is written to it.
355
+
356
+ =item * A Filename
357
+
358
+ If C<Append> is enabled, the file will be opened in append mode. Otherwise
359
+ the contents of the file, if any, will be truncated before any compressed
360
+ data is written to it.
361
+
362
+ =item * A Filehandle
363
+
364
+ If C<Append> is enabled, the filehandle will be positioned to the end of
365
+ the file via a call to C<seek> before any compressed data is
366
+ written to it. Otherwise the file pointer will not be moved.
367
+
368
+ =back
369
+
370
+ When C<Append> is specified, and set to true, it will I<append> all compressed
371
+ data to the output data stream.
372
+
373
+ So when the output is a filehandle it will carry out a seek to the eof
374
+ before writing any compressed data. If the output is a filename, it will be opened for
375
+ appending. If the output is a buffer, all compressed data will be
376
+ appended to the existing buffer.
377
+
378
+ Conversely when C<Append> is not specified, or it is present and is set to
379
+ false, it will operate as follows.
380
+
381
+ When the output is a filename, it will truncate the contents of the file
382
+ before writing any compressed data. If the output is a filehandle
383
+ its position will not be changed. If the output is a buffer, it will be
384
+ wiped before any compressed data is output.
385
+
386
+ Defaults to 0.
387
+
388
+ =back
389
+
390
+ =head2 Oneshot Examples
391
+
392
+ Here are a few example that show the capabilities of the module.
393
+
394
+ =head3 Streaming
395
+
396
+ This very simple command line example demonstrates the streaming capabilities of the module.
397
+ The code reads data from STDIN, compresses it, and writes the compressed data to STDOUT.
398
+
399
+ $ echo hello world | perl -MIO::Compress::Bzip2=bzip2 -e 'bzip2 \*STDIN => \*STDOUT' >output.bz2
400
+
401
+ The special filename "-" can be used as a standin for both C<\*STDIN> and C<\*STDOUT>,
402
+ so the above can be rewritten as
403
+
404
+ $ echo hello world | perl -MIO::Compress::Bzip2=bzip2 -e 'bzip2 "-" => "-"' >output.bz2
405
+
406
+ =head3 Compressing a file from the filesystem
407
+
408
+ To read the contents of the file C<file1.txt> and write the compressed
409
+ data to the file C<file1.txt.bz2>.
410
+
411
+ use strict ;
412
+ use warnings ;
413
+ use IO::Compress::Bzip2 qw(bzip2 $Bzip2Error) ;
414
+
415
+ my $input = "file1.txt";
416
+ bzip2 $input => "$input.bz2"
417
+ or die "bzip2 failed: $Bzip2Error\n";
418
+
419
+ =head3 Reading from a Filehandle and writing to an in-memory buffer
420
+
421
+ To read from an existing Perl filehandle, C<$input>, and write the
422
+ compressed data to a buffer, C<$buffer>.
423
+
424
+ use strict ;
425
+ use warnings ;
426
+ use IO::Compress::Bzip2 qw(bzip2 $Bzip2Error) ;
427
+ use IO::File ;
428
+
429
+ my $input = IO::File->new( "<file1.txt" )
430
+ or die "Cannot open 'file1.txt': $!\n" ;
431
+ my $buffer ;
432
+ bzip2 $input => \$buffer
433
+ or die "bzip2 failed: $Bzip2Error\n";
434
+
435
+ =head3 Compressing multiple files
436
+
437
+ To compress all files in the directory "/my/home" that match "*.txt"
438
+ and store the compressed data in the same directory
439
+
440
+ use strict ;
441
+ use warnings ;
442
+ use IO::Compress::Bzip2 qw(bzip2 $Bzip2Error) ;
443
+
444
+ bzip2 '</my/home/*.txt>' => '<*.bz2>'
445
+ or die "bzip2 failed: $Bzip2Error\n";
446
+
447
+ and if you want to compress each file one at a time, this will do the trick
448
+
449
+ use strict ;
450
+ use warnings ;
451
+ use IO::Compress::Bzip2 qw(bzip2 $Bzip2Error) ;
452
+
453
+ for my $input ( glob "/my/home/*.txt" )
454
+ {
455
+ my $output = "$input.bz2" ;
456
+ bzip2 $input => $output
457
+ or die "Error compressing '$input': $Bzip2Error\n";
458
+ }
459
+
460
+ =head1 OO Interface
461
+
462
+ =head2 Constructor
463
+
464
+ The format of the constructor for C<IO::Compress::Bzip2> is shown below
465
+
466
+ my $z = IO::Compress::Bzip2->new( $output [,OPTS] )
467
+ or die "IO::Compress::Bzip2 failed: $Bzip2Error\n";
468
+
469
+ The constructor takes one mandatory parameter, C<$output>, defined below and
470
+ zero or more C<OPTS>, defined in L<Constructor Options>.
471
+
472
+ It returns an C<IO::Compress::Bzip2> object on success and C<undef> on failure.
473
+ The variable C<$Bzip2Error> will contain an error message on failure.
474
+
475
+ If you are running Perl 5.005 or better the object, C<$z>, returned from
476
+ IO::Compress::Bzip2 can be used exactly like an L<IO::File|IO::File> filehandle.
477
+ This means that all normal output file operations can be carried out
478
+ with C<$z>.
479
+ For example, to write to a compressed file/buffer you can use either of
480
+ these forms
481
+
482
+ $z->print("hello world\n");
483
+ print $z "hello world\n";
484
+
485
+ Below is a simple exaple of using the OO interface to create an output file
486
+ C<myfile.bz2> and write some data to it.
487
+
488
+ my $filename = "myfile.bz2";
489
+ my $z = IO::Compress::Bzip2->new($filename)
490
+ or die "IO::Compress::Bzip2 failed: $Bzip2Error\n";
491
+
492
+ $z->print("abcde");
493
+ $z->close();
494
+
495
+ See the L</Examples> for more.
496
+
497
+ The mandatory parameter C<$output> is used to control the destination
498
+ of the compressed data. This parameter can take one of these forms.
499
+
500
+ =over 5
501
+
502
+ =item A filename
503
+
504
+ If the C<$output> parameter is a simple scalar, it is assumed to be a
505
+ filename. This file will be opened for writing and the compressed data
506
+ will be written to it.
507
+
508
+ =item A filehandle
509
+
510
+ If the C<$output> parameter is a filehandle, the compressed data will be
511
+ written to it.
512
+ The string '-' can be used as an alias for standard output.
513
+
514
+ =item A scalar reference
515
+
516
+ If C<$output> is a scalar reference, the compressed data will be stored
517
+ in C<$$output>.
518
+
519
+ =back
520
+
521
+ If the C<$output> parameter is any other type, C<IO::Compress::Bzip2>::new will
522
+ return undef.
523
+
524
+ =head2 Constructor Options
525
+
526
+ C<OPTS> is any combination of zero or more the following options:
527
+
528
+ =over 5
529
+
530
+ =item C<< AutoClose => 0|1 >>
531
+
532
+ This option is only valid when the C<$output> parameter is a filehandle. If
533
+ specified, and the value is true, it will result in the C<$output> being
534
+ closed once either the C<close> method is called or the C<IO::Compress::Bzip2>
535
+ object is destroyed.
536
+
537
+ This parameter defaults to 0.
538
+
539
+ =item C<< Append => 0|1 >>
540
+
541
+ Opens C<$output> in append mode.
542
+
543
+ The behaviour of this option is dependent on the type of C<$output>.
544
+
545
+ =over 5
546
+
547
+ =item * A Buffer
548
+
549
+ If C<$output> is a buffer and C<Append> is enabled, all compressed data
550
+ will be append to the end of C<$output>. Otherwise C<$output> will be
551
+ cleared before any data is written to it.
552
+
553
+ =item * A Filename
554
+
555
+ If C<$output> is a filename and C<Append> is enabled, the file will be
556
+ opened in append mode. Otherwise the contents of the file, if any, will be
557
+ truncated before any compressed data is written to it.
558
+
559
+ =item * A Filehandle
560
+
561
+ If C<$output> is a filehandle, the file pointer will be positioned to the
562
+ end of the file via a call to C<seek> before any compressed data is written
563
+ to it. Otherwise the file pointer will not be moved.
564
+
565
+ =back
566
+
567
+ This parameter defaults to 0.
568
+
569
+ =item C<< BlockSize100K => number >>
570
+
571
+ Specify the number of 100K blocks bzip2 uses during compression.
572
+
573
+ Valid values are from 1 to 9, where 9 is best compression.
574
+
575
+ The default is 1.
576
+
577
+ =item C<< WorkFactor => number >>
578
+
579
+ Specifies how much effort bzip2 should take before resorting to a slower
580
+ fallback compression algorithm.
581
+
582
+ Valid values range from 0 to 250, where 0 means use the default value 30.
583
+
584
+ The default is 0.
585
+
586
+ =item C<< Strict => 0|1 >>
587
+
588
+ This is a placeholder option.
589
+
590
+ =back
591
+
592
+ =head2 Examples
593
+
594
+ =head3 Streaming
595
+
596
+ This very simple command line example demonstrates the streaming capabilities
597
+ of the module. The code reads data from STDIN or all the files given on the
598
+ commandline, compresses it, and writes the compressed data to STDOUT.
599
+
600
+ use strict ;
601
+ use warnings ;
602
+ use IO::Compress::Bzip2 qw(bzip2 $Bzip2Error) ;
603
+
604
+ my $z = IO::Compress::Bzip2->new("-", Stream => 1)
605
+ or die "IO::Compress::Bzip2 failed: $Bzip2Error\n";
606
+
607
+ while (<>) {
608
+ $z->print("abcde");
609
+ }
610
+ $z->close();
611
+
612
+ Note the use of C<"-"> to means C<STDOUT>. Alternatively you can use C<\*STDOUT>.
613
+
614
+ =head3 Compressing a file from the filesystem
615
+
616
+ To read the contents of the file C<file1.txt> and write the compressed
617
+ data to the file C<file1.txt.bz2> there are a few options
618
+
619
+ Start by creating the compression object and opening the input file
620
+
621
+ use strict ;
622
+ use warnings ;
623
+ use IO::Compress::Bzip2 qw(bzip2 $Bzip2Error) ;
624
+
625
+ my $input = "file1.txt";
626
+ my $z = IO::Compress::Bzip2->new("file1.txt.bz2")
627
+ or die "IO::Compress::Bzip2 failed: $Bzip2Error\n";
628
+
629
+ # open the input file
630
+ open my $fh, "<", "file1.txt"
631
+ or die "Cannot open file1.txt: $!\n";
632
+
633
+ # loop through the input file & write to the compressed file
634
+ while (<$fh>) {
635
+ $z->print($_);
636
+ }
637
+
638
+ # not forgetting to close the compressed file
639
+ $z->close();
640
+
641
+ =head1 Methods
642
+
643
+ =head2 print
644
+
645
+ Usage is
646
+
647
+ $z->print($data)
648
+ print $z $data
649
+
650
+ Compresses and outputs the contents of the C<$data> parameter. This
651
+ has the same behaviour as the C<print> built-in.
652
+
653
+ Returns true if successful.
654
+
655
+ =head2 printf
656
+
657
+ Usage is
658
+
659
+ $z->printf($format, $data)
660
+ printf $z $format, $data
661
+
662
+ Compresses and outputs the contents of the C<$data> parameter.
663
+
664
+ Returns true if successful.
665
+
666
+ =head2 syswrite
667
+
668
+ Usage is
669
+
670
+ $z->syswrite $data
671
+ $z->syswrite $data, $length
672
+ $z->syswrite $data, $length, $offset
673
+
674
+ Compresses and outputs the contents of the C<$data> parameter.
675
+
676
+ Returns the number of uncompressed bytes written, or C<undef> if
677
+ unsuccessful.
678
+
679
+ =head2 write
680
+
681
+ Usage is
682
+
683
+ $z->write $data
684
+ $z->write $data, $length
685
+ $z->write $data, $length, $offset
686
+
687
+ Compresses and outputs the contents of the C<$data> parameter.
688
+
689
+ Returns the number of uncompressed bytes written, or C<undef> if
690
+ unsuccessful.
691
+
692
+ =head2 flush
693
+
694
+ Usage is
695
+
696
+ $z->flush;
697
+
698
+ Flushes any pending compressed data to the output file/buffer.
699
+
700
+ TODO
701
+
702
+ Returns true on success.
703
+
704
+ =head2 tell
705
+
706
+ Usage is
707
+
708
+ $z->tell()
709
+ tell $z
710
+
711
+ Returns the uncompressed file offset.
712
+
713
+ =head2 eof
714
+
715
+ Usage is
716
+
717
+ $z->eof();
718
+ eof($z);
719
+
720
+ Returns true if the C<close> method has been called.
721
+
722
+ =head2 seek
723
+
724
+ $z->seek($position, $whence);
725
+ seek($z, $position, $whence);
726
+
727
+ Provides a sub-set of the C<seek> functionality, with the restriction
728
+ that it is only legal to seek forward in the output file/buffer.
729
+ It is a fatal error to attempt to seek backward.
730
+
731
+ Empty parts of the file/buffer will have NULL (0x00) bytes written to them.
732
+
733
+ The C<$whence> parameter takes one the usual values, namely SEEK_SET,
734
+ SEEK_CUR or SEEK_END.
735
+
736
+ Returns 1 on success, 0 on failure.
737
+
738
+ =head2 binmode
739
+
740
+ Usage is
741
+
742
+ $z->binmode
743
+ binmode $z ;
744
+
745
+ This is a noop provided for completeness.
746
+
747
+ =head2 opened
748
+
749
+ $z->opened()
750
+
751
+ Returns true if the object currently refers to a opened file/buffer.
752
+
753
+ =head2 autoflush
754
+
755
+ my $prev = $z->autoflush()
756
+ my $prev = $z->autoflush(EXPR)
757
+
758
+ If the C<$z> object is associated with a file or a filehandle, this method
759
+ returns the current autoflush setting for the underlying filehandle. If
760
+ C<EXPR> is present, and is non-zero, it will enable flushing after every
761
+ write/print operation.
762
+
763
+ If C<$z> is associated with a buffer, this method has no effect and always
764
+ returns C<undef>.
765
+
766
+ B<Note> that the special variable C<$|> B<cannot> be used to set or
767
+ retrieve the autoflush setting.
768
+
769
+ =head2 input_line_number
770
+
771
+ $z->input_line_number()
772
+ $z->input_line_number(EXPR)
773
+
774
+ This method always returns C<undef> when compressing.
775
+
776
+ =head2 fileno
777
+
778
+ $z->fileno()
779
+ fileno($z)
780
+
781
+ If the C<$z> object is associated with a file or a filehandle, C<fileno>
782
+ will return the underlying file descriptor. Once the C<close> method is
783
+ called C<fileno> will return C<undef>.
784
+
785
+ If the C<$z> object is associated with a buffer, this method will return
786
+ C<undef>.
787
+
788
+ =head2 close
789
+
790
+ $z->close() ;
791
+ close $z ;
792
+
793
+ Flushes any pending compressed data and then closes the output file/buffer.
794
+
795
+ For most versions of Perl this method will be automatically invoked if
796
+ the IO::Compress::Bzip2 object is destroyed (either explicitly or by the
797
+ variable with the reference to the object going out of scope). The
798
+ exceptions are Perl versions 5.005 through 5.00504 and 5.8.0. In
799
+ these cases, the C<close> method will be called automatically, but
800
+ not until global destruction of all live objects when the program is
801
+ terminating.
802
+
803
+ Therefore, if you want your scripts to be able to run on all versions
804
+ of Perl, you should call C<close> explicitly and not rely on automatic
805
+ closing.
806
+
807
+ Returns true on success, otherwise 0.
808
+
809
+ If the C<AutoClose> option has been enabled when the IO::Compress::Bzip2
810
+ object was created, and the object is associated with a file, the
811
+ underlying file will also be closed.
812
+
813
+ =head2 newStream([OPTS])
814
+
815
+ Usage is
816
+
817
+ $z->newStream( [OPTS] )
818
+
819
+ Closes the current compressed data stream and starts a new one.
820
+
821
+ OPTS consists of any of the options that are available when creating
822
+ the C<$z> object.
823
+
824
+ See the L</"Constructor Options"> section for more details.
825
+
826
+ =head1 Importing
827
+
828
+ No symbolic constants are required by IO::Compress::Bzip2 at present.
829
+
830
+ =over 5
831
+
832
+ =item :all
833
+
834
+ Imports C<bzip2> and C<$Bzip2Error>.
835
+ Same as doing this
836
+
837
+ use IO::Compress::Bzip2 qw(bzip2 $Bzip2Error) ;
838
+
839
+ =back
840
+
841
+ =head1 EXAMPLES
842
+
843
+ =head2 Apache::GZip Revisited
844
+
845
+ See L<IO::Compress::FAQ|IO::Compress::FAQ/"Apache::GZip Revisited">
846
+
847
+ =head2 Working with Net::FTP
848
+
849
+ See L<IO::Compress::FAQ|IO::Compress::FAQ/"Compressed files and Net::FTP">
850
+
851
+ =head1 SUPPORT
852
+
853
+ General feedback/questions/bug reports should be sent to
854
+ L<https://github.com/pmqs/IO-Compress/issues> (preferred) or
855
+ L<https://rt.cpan.org/Public/Dist/Display.html?Name=IO-Compress>.
856
+
857
+ =head1 SEE ALSO
858
+
859
+ L<Compress::Zlib>, L<IO::Compress::Gzip>, L<IO::Uncompress::Gunzip>, L<IO::Compress::Deflate>, L<IO::Uncompress::Inflate>, L<IO::Compress::RawDeflate>, L<IO::Uncompress::RawInflate>, L<IO::Uncompress::Bunzip2>, L<IO::Compress::Lzma>, L<IO::Uncompress::UnLzma>, L<IO::Compress::Xz>, L<IO::Uncompress::UnXz>, L<IO::Compress::Lzip>, L<IO::Uncompress::UnLzip>, L<IO::Compress::Lzop>, L<IO::Uncompress::UnLzop>, L<IO::Compress::Lzf>, L<IO::Uncompress::UnLzf>, L<IO::Compress::Zstd>, L<IO::Uncompress::UnZstd>, L<IO::Uncompress::AnyInflate>, L<IO::Uncompress::AnyUncompress>
860
+
861
+ L<IO::Compress::FAQ|IO::Compress::FAQ>
862
+
863
+ L<File::GlobMapper|File::GlobMapper>, L<Archive::Zip|Archive::Zip>,
864
+ L<Archive::Tar|Archive::Tar>,
865
+ L<IO::Zlib|IO::Zlib>
866
+
867
+ The primary site for the bzip2 program is L<https://sourceware.org/bzip2/>.
868
+
869
+ See the module L<Compress::Bzip2|Compress::Bzip2>
870
+
871
+ =head1 AUTHOR
872
+
873
+ This module was written by Paul Marquess, C<pmqs@cpan.org>.
874
+
875
+ =head1 MODIFICATION HISTORY
876
+
877
+ See the Changes file.
878
+
879
+ =head1 COPYRIGHT AND LICENSE
880
+
881
+ Copyright (c) 2005-2024 Paul Marquess. All rights reserved.
882
+
883
+ This program is free software; you can redistribute it and/or
884
+ modify it under the same terms as Perl itself.
git/usr/share/perl5/core_perl/IO/Compress/Deflate.pm ADDED
@@ -0,0 +1,958 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package IO::Compress::Deflate ;
2
+
3
+ require 5.006 ;
4
+
5
+ use strict ;
6
+ use warnings;
7
+ use bytes;
8
+
9
+ require Exporter ;
10
+
11
+ use IO::Compress::RawDeflate 2.213 ();
12
+ use IO::Compress::Adapter::Deflate 2.213 ;
13
+
14
+ use IO::Compress::Zlib::Constants 2.213 ;
15
+ use IO::Compress::Base::Common 2.213 qw();
16
+
17
+
18
+ our ($VERSION, @ISA, @EXPORT_OK, %EXPORT_TAGS, %DEFLATE_CONSTANTS, $DeflateError);
19
+
20
+ $VERSION = '2.213';
21
+ $DeflateError = '';
22
+
23
+ @ISA = qw(IO::Compress::RawDeflate Exporter);
24
+ @EXPORT_OK = qw( $DeflateError deflate ) ;
25
+ %EXPORT_TAGS = %IO::Compress::RawDeflate::DEFLATE_CONSTANTS ;
26
+
27
+ push @{ $EXPORT_TAGS{all} }, @EXPORT_OK ;
28
+ Exporter::export_ok_tags('all');
29
+
30
+
31
+ sub new
32
+ {
33
+ my $class = shift ;
34
+
35
+ my $obj = IO::Compress::Base::Common::createSelfTiedObject($class, \$DeflateError);
36
+ return $obj->_create(undef, @_);
37
+ }
38
+
39
+ sub deflate
40
+ {
41
+ my $obj = IO::Compress::Base::Common::createSelfTiedObject(undef, \$DeflateError);
42
+ return $obj->_def(@_);
43
+ }
44
+
45
+ sub mkComp
46
+ {
47
+ my $self = shift ;
48
+ my $got = shift ;
49
+
50
+ my ($obj, $errstr, $errno) = IO::Compress::Adapter::Deflate::mkCompObject1(
51
+ $got->getValue('crc32'),
52
+ $got->getValue('adler32'),
53
+ $got->getValue('level'),
54
+ $got->getValue('strategy')
55
+ );
56
+
57
+ return $self->saveErrorString(undef, $errstr, $errno)
58
+ if ! defined $obj;
59
+
60
+ return $obj;
61
+ }
62
+
63
+
64
+ sub mkHeader
65
+ {
66
+ my $self = shift ;
67
+ return '';
68
+ }
69
+
70
+ sub mkTrailer
71
+ {
72
+ my $self = shift ;
73
+ return '';
74
+ }
75
+
76
+ sub mkFinalTrailer
77
+ {
78
+ return '';
79
+ }
80
+
81
+ sub getExtraParams
82
+ {
83
+ my $self = shift ;
84
+ return $self->getZlibParams(),
85
+ }
86
+
87
+ sub getInverseClass
88
+ {
89
+ no warnings 'once';
90
+ return ('IO::Uncompress::Inflate',
91
+ \$IO::Uncompress::Inflate::InflateError);
92
+ }
93
+
94
+ sub getFileInfo
95
+ {
96
+ my $self = shift ;
97
+ my $params = shift;
98
+ my $file = shift ;
99
+
100
+ }
101
+
102
+
103
+
104
+ 1;
105
+
106
+ __END__
107
+
108
+ =head1 NAME
109
+
110
+ IO::Compress::Deflate - Write RFC 1950 files/buffers
111
+
112
+ =head1 SYNOPSIS
113
+
114
+ use IO::Compress::Deflate qw(deflate $DeflateError) ;
115
+
116
+ my $status = deflate $input => $output [,OPTS]
117
+ or die "deflate failed: $DeflateError\n";
118
+
119
+ my $z = IO::Compress::Deflate->new( $output [,OPTS] )
120
+ or die "deflate failed: $DeflateError\n";
121
+
122
+ $z->print($string);
123
+ $z->printf($format, $string);
124
+ $z->write($string);
125
+ $z->syswrite($string [, $length, $offset]);
126
+ $z->flush();
127
+ $z->tell();
128
+ $z->eof();
129
+ $z->seek($position, $whence);
130
+ $z->binmode();
131
+ $z->fileno();
132
+ $z->opened();
133
+ $z->autoflush();
134
+ $z->input_line_number();
135
+ $z->newStream( [OPTS] );
136
+
137
+ $z->deflateParams();
138
+
139
+ $z->close() ;
140
+
141
+ $DeflateError ;
142
+
143
+ # IO::File mode
144
+
145
+ print $z $string;
146
+ printf $z $format, $string;
147
+ tell $z
148
+ eof $z
149
+ seek $z, $position, $whence
150
+ binmode $z
151
+ fileno $z
152
+ close $z ;
153
+
154
+ =head1 DESCRIPTION
155
+
156
+ This module provides a Perl interface that allows writing compressed
157
+ data to files or buffer as defined in RFC 1950.
158
+
159
+ For reading RFC 1950 files/buffers, see the companion module
160
+ L<IO::Uncompress::Inflate|IO::Uncompress::Inflate>.
161
+
162
+ =head1 Functional Interface
163
+
164
+ A top-level function, C<deflate>, is provided to carry out
165
+ "one-shot" compression between buffers and/or files. For finer
166
+ control over the compression process, see the L</"OO Interface">
167
+ section.
168
+
169
+ use IO::Compress::Deflate qw(deflate $DeflateError) ;
170
+
171
+ deflate $input_filename_or_reference => $output_filename_or_reference [,OPTS]
172
+ or die "deflate failed: $DeflateError\n";
173
+
174
+ The functional interface needs Perl5.005 or better.
175
+
176
+ =head2 deflate $input_filename_or_reference => $output_filename_or_reference [, OPTS]
177
+
178
+ C<deflate> expects at least two parameters,
179
+ C<$input_filename_or_reference> and C<$output_filename_or_reference>
180
+ and zero or more optional parameters (see L</Optional Parameters>)
181
+
182
+ =head3 The C<$input_filename_or_reference> parameter
183
+
184
+ The parameter, C<$input_filename_or_reference>, is used to define the
185
+ source of the uncompressed data.
186
+
187
+ It can take one of the following forms:
188
+
189
+ =over 5
190
+
191
+ =item A filename
192
+
193
+ If the C<$input_filename_or_reference> parameter is a simple scalar, it is
194
+ assumed to be a filename. This file will be opened for reading and the
195
+ input data will be read from it.
196
+
197
+ =item A filehandle
198
+
199
+ If the C<$input_filename_or_reference> parameter is a filehandle, the input
200
+ data will be read from it. The string '-' can be used as an alias for
201
+ standard input.
202
+
203
+ =item A scalar reference
204
+
205
+ If C<$input_filename_or_reference> is a scalar reference, the input data
206
+ will be read from C<$$input_filename_or_reference>.
207
+
208
+ =item An array reference
209
+
210
+ If C<$input_filename_or_reference> is an array reference, each element in
211
+ the array must be a filename.
212
+
213
+ The input data will be read from each file in turn.
214
+
215
+ The complete array will be walked to ensure that it only
216
+ contains valid filenames before any data is compressed.
217
+
218
+ =item An Input FileGlob string
219
+
220
+ If C<$input_filename_or_reference> is a string that is delimited by the
221
+ characters "<" and ">" C<deflate> will assume that it is an
222
+ I<input fileglob string>. The input is the list of files that match the
223
+ fileglob.
224
+
225
+ See L<File::GlobMapper|File::GlobMapper> for more details.
226
+
227
+ =back
228
+
229
+ If the C<$input_filename_or_reference> parameter is any other type,
230
+ C<undef> will be returned.
231
+
232
+ =head3 The C<$output_filename_or_reference> parameter
233
+
234
+ The parameter C<$output_filename_or_reference> is used to control the
235
+ destination of the compressed data. This parameter can take one of
236
+ these forms.
237
+
238
+ =over 5
239
+
240
+ =item A filename
241
+
242
+ If the C<$output_filename_or_reference> parameter is a simple scalar, it is
243
+ assumed to be a filename. This file will be opened for writing and the
244
+ compressed data will be written to it.
245
+
246
+ =item A filehandle
247
+
248
+ If the C<$output_filename_or_reference> parameter is a filehandle, the
249
+ compressed data will be written to it. The string '-' can be used as
250
+ an alias for standard output.
251
+
252
+ =item A scalar reference
253
+
254
+ If C<$output_filename_or_reference> is a scalar reference, the
255
+ compressed data will be stored in C<$$output_filename_or_reference>.
256
+
257
+ =item An Array Reference
258
+
259
+ If C<$output_filename_or_reference> is an array reference,
260
+ the compressed data will be pushed onto the array.
261
+
262
+ =item An Output FileGlob
263
+
264
+ If C<$output_filename_or_reference> is a string that is delimited by the
265
+ characters "<" and ">" C<deflate> will assume that it is an
266
+ I<output fileglob string>. The output is the list of files that match the
267
+ fileglob.
268
+
269
+ When C<$output_filename_or_reference> is an fileglob string,
270
+ C<$input_filename_or_reference> must also be a fileglob string. Anything
271
+ else is an error.
272
+
273
+ See L<File::GlobMapper|File::GlobMapper> for more details.
274
+
275
+ =back
276
+
277
+ If the C<$output_filename_or_reference> parameter is any other type,
278
+ C<undef> will be returned.
279
+
280
+ =head2 Notes
281
+
282
+ When C<$input_filename_or_reference> maps to multiple files/buffers and
283
+ C<$output_filename_or_reference> is a single
284
+ file/buffer the input files/buffers will be stored
285
+ in C<$output_filename_or_reference> as a concatenated series of compressed data streams.
286
+
287
+ =head2 Optional Parameters
288
+
289
+ The optional parameters for the one-shot function C<deflate>
290
+ are (for the most part) identical to those used with the OO interface defined in the
291
+ L</"Constructor Options"> section. The exceptions are listed below
292
+
293
+ =over 5
294
+
295
+ =item C<< AutoClose => 0|1 >>
296
+
297
+ This option applies to any input or output data streams to
298
+ C<deflate> that are filehandles.
299
+
300
+ If C<AutoClose> is specified, and the value is true, it will result in all
301
+ input and/or output filehandles being closed once C<deflate> has
302
+ completed.
303
+
304
+ This parameter defaults to 0.
305
+
306
+ =item C<< BinModeIn => 0|1 >>
307
+
308
+ This option is now a no-op. All files will be read in binmode.
309
+
310
+ =item C<< Append => 0|1 >>
311
+
312
+ The behaviour of this option is dependent on the type of output data
313
+ stream.
314
+
315
+ =over 5
316
+
317
+ =item * A Buffer
318
+
319
+ If C<Append> is enabled, all compressed data will be append to the end of
320
+ the output buffer. Otherwise the output buffer will be cleared before any
321
+ compressed data is written to it.
322
+
323
+ =item * A Filename
324
+
325
+ If C<Append> is enabled, the file will be opened in append mode. Otherwise
326
+ the contents of the file, if any, will be truncated before any compressed
327
+ data is written to it.
328
+
329
+ =item * A Filehandle
330
+
331
+ If C<Append> is enabled, the filehandle will be positioned to the end of
332
+ the file via a call to C<seek> before any compressed data is
333
+ written to it. Otherwise the file pointer will not be moved.
334
+
335
+ =back
336
+
337
+ When C<Append> is specified, and set to true, it will I<append> all compressed
338
+ data to the output data stream.
339
+
340
+ So when the output is a filehandle it will carry out a seek to the eof
341
+ before writing any compressed data. If the output is a filename, it will be opened for
342
+ appending. If the output is a buffer, all compressed data will be
343
+ appended to the existing buffer.
344
+
345
+ Conversely when C<Append> is not specified, or it is present and is set to
346
+ false, it will operate as follows.
347
+
348
+ When the output is a filename, it will truncate the contents of the file
349
+ before writing any compressed data. If the output is a filehandle
350
+ its position will not be changed. If the output is a buffer, it will be
351
+ wiped before any compressed data is output.
352
+
353
+ Defaults to 0.
354
+
355
+ =back
356
+
357
+ =head2 Oneshot Examples
358
+
359
+ Here are a few example that show the capabilities of the module.
360
+
361
+ =head3 Streaming
362
+
363
+ This very simple command line example demonstrates the streaming capabilities of the module.
364
+ The code reads data from STDIN, compresses it, and writes the compressed data to STDOUT.
365
+
366
+ $ echo hello world | perl -MIO::Compress::Deflate=deflate -e 'deflate \*STDIN => \*STDOUT' >output.1950
367
+
368
+ The special filename "-" can be used as a standin for both C<\*STDIN> and C<\*STDOUT>,
369
+ so the above can be rewritten as
370
+
371
+ $ echo hello world | perl -MIO::Compress::Deflate=deflate -e 'deflate "-" => "-"' >output.1950
372
+
373
+ =head3 Compressing a file from the filesystem
374
+
375
+ To read the contents of the file C<file1.txt> and write the compressed
376
+ data to the file C<file1.txt.1950>.
377
+
378
+ use strict ;
379
+ use warnings ;
380
+ use IO::Compress::Deflate qw(deflate $DeflateError) ;
381
+
382
+ my $input = "file1.txt";
383
+ deflate $input => "$input.1950"
384
+ or die "deflate failed: $DeflateError\n";
385
+
386
+ =head3 Reading from a Filehandle and writing to an in-memory buffer
387
+
388
+ To read from an existing Perl filehandle, C<$input>, and write the
389
+ compressed data to a buffer, C<$buffer>.
390
+
391
+ use strict ;
392
+ use warnings ;
393
+ use IO::Compress::Deflate qw(deflate $DeflateError) ;
394
+ use IO::File ;
395
+
396
+ my $input = IO::File->new( "<file1.txt" )
397
+ or die "Cannot open 'file1.txt': $!\n" ;
398
+ my $buffer ;
399
+ deflate $input => \$buffer
400
+ or die "deflate failed: $DeflateError\n";
401
+
402
+ =head3 Compressing multiple files
403
+
404
+ To compress all files in the directory "/my/home" that match "*.txt"
405
+ and store the compressed data in the same directory
406
+
407
+ use strict ;
408
+ use warnings ;
409
+ use IO::Compress::Deflate qw(deflate $DeflateError) ;
410
+
411
+ deflate '</my/home/*.txt>' => '<*.1950>'
412
+ or die "deflate failed: $DeflateError\n";
413
+
414
+ and if you want to compress each file one at a time, this will do the trick
415
+
416
+ use strict ;
417
+ use warnings ;
418
+ use IO::Compress::Deflate qw(deflate $DeflateError) ;
419
+
420
+ for my $input ( glob "/my/home/*.txt" )
421
+ {
422
+ my $output = "$input.1950" ;
423
+ deflate $input => $output
424
+ or die "Error compressing '$input': $DeflateError\n";
425
+ }
426
+
427
+ =head1 OO Interface
428
+
429
+ =head2 Constructor
430
+
431
+ The format of the constructor for C<IO::Compress::Deflate> is shown below
432
+
433
+ my $z = IO::Compress::Deflate->new( $output [,OPTS] )
434
+ or die "IO::Compress::Deflate failed: $DeflateError\n";
435
+
436
+ The constructor takes one mandatory parameter, C<$output>, defined below and
437
+ zero or more C<OPTS>, defined in L<Constructor Options>.
438
+
439
+ It returns an C<IO::Compress::Deflate> object on success and C<undef> on failure.
440
+ The variable C<$DeflateError> will contain an error message on failure.
441
+
442
+ If you are running Perl 5.005 or better the object, C<$z>, returned from
443
+ IO::Compress::Deflate can be used exactly like an L<IO::File|IO::File> filehandle.
444
+ This means that all normal output file operations can be carried out
445
+ with C<$z>.
446
+ For example, to write to a compressed file/buffer you can use either of
447
+ these forms
448
+
449
+ $z->print("hello world\n");
450
+ print $z "hello world\n";
451
+
452
+ Below is a simple exaple of using the OO interface to create an output file
453
+ C<myfile.1950> and write some data to it.
454
+
455
+ my $filename = "myfile.1950";
456
+ my $z = IO::Compress::Deflate->new($filename)
457
+ or die "IO::Compress::Deflate failed: $DeflateError\n";
458
+
459
+ $z->print("abcde");
460
+ $z->close();
461
+
462
+ See the L</Examples> for more.
463
+
464
+ The mandatory parameter C<$output> is used to control the destination
465
+ of the compressed data. This parameter can take one of these forms.
466
+
467
+ =over 5
468
+
469
+ =item A filename
470
+
471
+ If the C<$output> parameter is a simple scalar, it is assumed to be a
472
+ filename. This file will be opened for writing and the compressed data
473
+ will be written to it.
474
+
475
+ =item A filehandle
476
+
477
+ If the C<$output> parameter is a filehandle, the compressed data will be
478
+ written to it.
479
+ The string '-' can be used as an alias for standard output.
480
+
481
+ =item A scalar reference
482
+
483
+ If C<$output> is a scalar reference, the compressed data will be stored
484
+ in C<$$output>.
485
+
486
+ =back
487
+
488
+ If the C<$output> parameter is any other type, C<IO::Compress::Deflate>::new will
489
+ return undef.
490
+
491
+ =head2 Constructor Options
492
+
493
+ C<OPTS> is any combination of zero or more the following options:
494
+
495
+ =over 5
496
+
497
+ =item C<< AutoClose => 0|1 >>
498
+
499
+ This option is only valid when the C<$output> parameter is a filehandle. If
500
+ specified, and the value is true, it will result in the C<$output> being
501
+ closed once either the C<close> method is called or the C<IO::Compress::Deflate>
502
+ object is destroyed.
503
+
504
+ This parameter defaults to 0.
505
+
506
+ =item C<< Append => 0|1 >>
507
+
508
+ Opens C<$output> in append mode.
509
+
510
+ The behaviour of this option is dependent on the type of C<$output>.
511
+
512
+ =over 5
513
+
514
+ =item * A Buffer
515
+
516
+ If C<$output> is a buffer and C<Append> is enabled, all compressed data
517
+ will be append to the end of C<$output>. Otherwise C<$output> will be
518
+ cleared before any data is written to it.
519
+
520
+ =item * A Filename
521
+
522
+ If C<$output> is a filename and C<Append> is enabled, the file will be
523
+ opened in append mode. Otherwise the contents of the file, if any, will be
524
+ truncated before any compressed data is written to it.
525
+
526
+ =item * A Filehandle
527
+
528
+ If C<$output> is a filehandle, the file pointer will be positioned to the
529
+ end of the file via a call to C<seek> before any compressed data is written
530
+ to it. Otherwise the file pointer will not be moved.
531
+
532
+ =back
533
+
534
+ This parameter defaults to 0.
535
+
536
+ =item C<< Merge => 0|1 >>
537
+
538
+ This option is used to compress input data and append it to an existing
539
+ compressed data stream in C<$output>. The end result is a single compressed
540
+ data stream stored in C<$output>.
541
+
542
+ It is a fatal error to attempt to use this option when C<$output> is not an
543
+ RFC 1950 data stream.
544
+
545
+ There are a number of other limitations with the C<Merge> option:
546
+
547
+ =over 5
548
+
549
+ =item 1
550
+
551
+ This module needs to have been built with zlib 1.2.1 or better to work. A
552
+ fatal error will be thrown if C<Merge> is used with an older version of
553
+ zlib.
554
+
555
+ =item 2
556
+
557
+ If C<$output> is a file or a filehandle, it must be seekable.
558
+
559
+ =back
560
+
561
+ This parameter defaults to 0.
562
+
563
+ =item -Level
564
+
565
+ Defines the compression level used by zlib. The value should either be
566
+ a number between 0 and 9 (0 means no compression and 9 is maximum
567
+ compression), or one of the symbolic constants defined below.
568
+
569
+ Z_NO_COMPRESSION
570
+ Z_BEST_SPEED
571
+ Z_BEST_COMPRESSION
572
+ Z_DEFAULT_COMPRESSION
573
+
574
+ The default is Z_DEFAULT_COMPRESSION.
575
+
576
+ Note, these constants are not imported by C<IO::Compress::Deflate> by default.
577
+
578
+ use IO::Compress::Deflate qw(:strategy);
579
+ use IO::Compress::Deflate qw(:constants);
580
+ use IO::Compress::Deflate qw(:all);
581
+
582
+ =item -Strategy
583
+
584
+ Defines the strategy used to tune the compression. Use one of the symbolic
585
+ constants defined below.
586
+
587
+ Z_FILTERED
588
+ Z_HUFFMAN_ONLY
589
+ Z_RLE
590
+ Z_FIXED
591
+ Z_DEFAULT_STRATEGY
592
+
593
+ The default is Z_DEFAULT_STRATEGY.
594
+
595
+ =item C<< Strict => 0|1 >>
596
+
597
+ This is a placeholder option.
598
+
599
+ =back
600
+
601
+ =head2 Examples
602
+
603
+ =head3 Streaming
604
+
605
+ This very simple command line example demonstrates the streaming capabilities
606
+ of the module. The code reads data from STDIN or all the files given on the
607
+ commandline, compresses it, and writes the compressed data to STDOUT.
608
+
609
+ use strict ;
610
+ use warnings ;
611
+ use IO::Compress::Deflate qw(deflate $DeflateError) ;
612
+
613
+ my $z = IO::Compress::Deflate->new("-", Stream => 1)
614
+ or die "IO::Compress::Deflate failed: $DeflateError\n";
615
+
616
+ while (<>) {
617
+ $z->print("abcde");
618
+ }
619
+ $z->close();
620
+
621
+ Note the use of C<"-"> to means C<STDOUT>. Alternatively you can use C<\*STDOUT>.
622
+
623
+ =head3 Compressing a file from the filesystem
624
+
625
+ To read the contents of the file C<file1.txt> and write the compressed
626
+ data to the file C<file1.txt.1950> there are a few options
627
+
628
+ Start by creating the compression object and opening the input file
629
+
630
+ use strict ;
631
+ use warnings ;
632
+ use IO::Compress::Deflate qw(deflate $DeflateError) ;
633
+
634
+ my $input = "file1.txt";
635
+ my $z = IO::Compress::Deflate->new("file1.txt.1950")
636
+ or die "IO::Compress::Deflate failed: $DeflateError\n";
637
+
638
+ # open the input file
639
+ open my $fh, "<", "file1.txt"
640
+ or die "Cannot open file1.txt: $!\n";
641
+
642
+ # loop through the input file & write to the compressed file
643
+ while (<$fh>) {
644
+ $z->print($_);
645
+ }
646
+
647
+ # not forgetting to close the compressed file
648
+ $z->close();
649
+
650
+ =head1 Methods
651
+
652
+ =head2 print
653
+
654
+ Usage is
655
+
656
+ $z->print($data)
657
+ print $z $data
658
+
659
+ Compresses and outputs the contents of the C<$data> parameter. This
660
+ has the same behaviour as the C<print> built-in.
661
+
662
+ Returns true if successful.
663
+
664
+ =head2 printf
665
+
666
+ Usage is
667
+
668
+ $z->printf($format, $data)
669
+ printf $z $format, $data
670
+
671
+ Compresses and outputs the contents of the C<$data> parameter.
672
+
673
+ Returns true if successful.
674
+
675
+ =head2 syswrite
676
+
677
+ Usage is
678
+
679
+ $z->syswrite $data
680
+ $z->syswrite $data, $length
681
+ $z->syswrite $data, $length, $offset
682
+
683
+ Compresses and outputs the contents of the C<$data> parameter.
684
+
685
+ Returns the number of uncompressed bytes written, or C<undef> if
686
+ unsuccessful.
687
+
688
+ =head2 write
689
+
690
+ Usage is
691
+
692
+ $z->write $data
693
+ $z->write $data, $length
694
+ $z->write $data, $length, $offset
695
+
696
+ Compresses and outputs the contents of the C<$data> parameter.
697
+
698
+ Returns the number of uncompressed bytes written, or C<undef> if
699
+ unsuccessful.
700
+
701
+ =head2 flush
702
+
703
+ Usage is
704
+
705
+ $z->flush;
706
+ $z->flush($flush_type);
707
+
708
+ Flushes any pending compressed data to the output file/buffer.
709
+
710
+ This method takes an optional parameter, C<$flush_type>, that controls
711
+ how the flushing will be carried out. By default the C<$flush_type>
712
+ used is C<Z_FINISH>. Other valid values for C<$flush_type> are
713
+ C<Z_NO_FLUSH>, C<Z_SYNC_FLUSH>, C<Z_FULL_FLUSH> and C<Z_BLOCK>. It is
714
+ strongly recommended that you only set the C<flush_type> parameter if
715
+ you fully understand the implications of what it does - overuse of C<flush>
716
+ can seriously degrade the level of compression achieved. See the C<zlib>
717
+ documentation for details.
718
+
719
+ Returns true on success.
720
+
721
+ =head2 tell
722
+
723
+ Usage is
724
+
725
+ $z->tell()
726
+ tell $z
727
+
728
+ Returns the uncompressed file offset.
729
+
730
+ =head2 eof
731
+
732
+ Usage is
733
+
734
+ $z->eof();
735
+ eof($z);
736
+
737
+ Returns true if the C<close> method has been called.
738
+
739
+ =head2 seek
740
+
741
+ $z->seek($position, $whence);
742
+ seek($z, $position, $whence);
743
+
744
+ Provides a sub-set of the C<seek> functionality, with the restriction
745
+ that it is only legal to seek forward in the output file/buffer.
746
+ It is a fatal error to attempt to seek backward.
747
+
748
+ Empty parts of the file/buffer will have NULL (0x00) bytes written to them.
749
+
750
+ The C<$whence> parameter takes one the usual values, namely SEEK_SET,
751
+ SEEK_CUR or SEEK_END.
752
+
753
+ Returns 1 on success, 0 on failure.
754
+
755
+ =head2 binmode
756
+
757
+ Usage is
758
+
759
+ $z->binmode
760
+ binmode $z ;
761
+
762
+ This is a noop provided for completeness.
763
+
764
+ =head2 opened
765
+
766
+ $z->opened()
767
+
768
+ Returns true if the object currently refers to a opened file/buffer.
769
+
770
+ =head2 autoflush
771
+
772
+ my $prev = $z->autoflush()
773
+ my $prev = $z->autoflush(EXPR)
774
+
775
+ If the C<$z> object is associated with a file or a filehandle, this method
776
+ returns the current autoflush setting for the underlying filehandle. If
777
+ C<EXPR> is present, and is non-zero, it will enable flushing after every
778
+ write/print operation.
779
+
780
+ If C<$z> is associated with a buffer, this method has no effect and always
781
+ returns C<undef>.
782
+
783
+ B<Note> that the special variable C<$|> B<cannot> be used to set or
784
+ retrieve the autoflush setting.
785
+
786
+ =head2 input_line_number
787
+
788
+ $z->input_line_number()
789
+ $z->input_line_number(EXPR)
790
+
791
+ This method always returns C<undef> when compressing.
792
+
793
+ =head2 fileno
794
+
795
+ $z->fileno()
796
+ fileno($z)
797
+
798
+ If the C<$z> object is associated with a file or a filehandle, C<fileno>
799
+ will return the underlying file descriptor. Once the C<close> method is
800
+ called C<fileno> will return C<undef>.
801
+
802
+ If the C<$z> object is associated with a buffer, this method will return
803
+ C<undef>.
804
+
805
+ =head2 close
806
+
807
+ $z->close() ;
808
+ close $z ;
809
+
810
+ Flushes any pending compressed data and then closes the output file/buffer.
811
+
812
+ For most versions of Perl this method will be automatically invoked if
813
+ the IO::Compress::Deflate object is destroyed (either explicitly or by the
814
+ variable with the reference to the object going out of scope). The
815
+ exceptions are Perl versions 5.005 through 5.00504 and 5.8.0. In
816
+ these cases, the C<close> method will be called automatically, but
817
+ not until global destruction of all live objects when the program is
818
+ terminating.
819
+
820
+ Therefore, if you want your scripts to be able to run on all versions
821
+ of Perl, you should call C<close> explicitly and not rely on automatic
822
+ closing.
823
+
824
+ Returns true on success, otherwise 0.
825
+
826
+ If the C<AutoClose> option has been enabled when the IO::Compress::Deflate
827
+ object was created, and the object is associated with a file, the
828
+ underlying file will also be closed.
829
+
830
+ =head2 newStream([OPTS])
831
+
832
+ Usage is
833
+
834
+ $z->newStream( [OPTS] )
835
+
836
+ Closes the current compressed data stream and starts a new one.
837
+
838
+ OPTS consists of any of the options that are available when creating
839
+ the C<$z> object.
840
+
841
+ See the L</"Constructor Options"> section for more details.
842
+
843
+ =head2 deflateParams
844
+
845
+ Usage is
846
+
847
+ $z->deflateParams
848
+
849
+ TODO
850
+
851
+ =head1 Importing
852
+
853
+ A number of symbolic constants are required by some methods in
854
+ C<IO::Compress::Deflate>. None are imported by default.
855
+
856
+ =over 5
857
+
858
+ =item :all
859
+
860
+ Imports C<deflate>, C<$DeflateError> and all symbolic
861
+ constants that can be used by C<IO::Compress::Deflate>. Same as doing this
862
+
863
+ use IO::Compress::Deflate qw(deflate $DeflateError :constants) ;
864
+
865
+ =item :constants
866
+
867
+ Import all symbolic constants. Same as doing this
868
+
869
+ use IO::Compress::Deflate qw(:flush :level :strategy) ;
870
+
871
+ =item :flush
872
+
873
+ These symbolic constants are used by the C<flush> method.
874
+
875
+ Z_NO_FLUSH
876
+ Z_PARTIAL_FLUSH
877
+ Z_SYNC_FLUSH
878
+ Z_FULL_FLUSH
879
+ Z_FINISH
880
+ Z_BLOCK
881
+
882
+ =item :level
883
+
884
+ These symbolic constants are used by the C<Level> option in the constructor.
885
+
886
+ Z_NO_COMPRESSION
887
+ Z_BEST_SPEED
888
+ Z_BEST_COMPRESSION
889
+ Z_DEFAULT_COMPRESSION
890
+
891
+ =item :strategy
892
+
893
+ These symbolic constants are used by the C<Strategy> option in the constructor.
894
+
895
+ Z_FILTERED
896
+ Z_HUFFMAN_ONLY
897
+ Z_RLE
898
+ Z_FIXED
899
+ Z_DEFAULT_STRATEGY
900
+
901
+ =back
902
+
903
+ =head1 EXAMPLES
904
+
905
+ =head2 Apache::GZip Revisited
906
+
907
+ See L<IO::Compress::FAQ|IO::Compress::FAQ/"Apache::GZip Revisited">
908
+
909
+ =head2 Working with Net::FTP
910
+
911
+ See L<IO::Compress::FAQ|IO::Compress::FAQ/"Compressed files and Net::FTP">
912
+
913
+ =head1 SUPPORT
914
+
915
+ General feedback/questions/bug reports should be sent to
916
+ L<https://github.com/pmqs/IO-Compress/issues> (preferred) or
917
+ L<https://rt.cpan.org/Public/Dist/Display.html?Name=IO-Compress>.
918
+
919
+ =head1 SEE ALSO
920
+
921
+ L<Compress::Zlib>, L<IO::Compress::Gzip>, L<IO::Uncompress::Gunzip>, L<IO::Uncompress::Inflate>, L<IO::Compress::RawDeflate>, L<IO::Uncompress::RawInflate>, L<IO::Compress::Bzip2>, L<IO::Uncompress::Bunzip2>, L<IO::Compress::Lzma>, L<IO::Uncompress::UnLzma>, L<IO::Compress::Xz>, L<IO::Uncompress::UnXz>, L<IO::Compress::Lzip>, L<IO::Uncompress::UnLzip>, L<IO::Compress::Lzop>, L<IO::Uncompress::UnLzop>, L<IO::Compress::Lzf>, L<IO::Uncompress::UnLzf>, L<IO::Compress::Zstd>, L<IO::Uncompress::UnZstd>, L<IO::Uncompress::AnyInflate>, L<IO::Uncompress::AnyUncompress>
922
+
923
+ L<IO::Compress::FAQ|IO::Compress::FAQ>
924
+
925
+ L<File::GlobMapper|File::GlobMapper>, L<Archive::Zip|Archive::Zip>,
926
+ L<Archive::Tar|Archive::Tar>,
927
+ L<IO::Zlib|IO::Zlib>
928
+
929
+ For RFC 1950, 1951 and 1952 see
930
+ L<https://datatracker.ietf.org/doc/html/rfc1950>,
931
+ L<https://datatracker.ietf.org/doc/html/rfc1951> and
932
+ L<https://datatracker.ietf.org/doc/html/rfc1952>
933
+
934
+ The I<zlib> compression library was written by Jean-loup Gailly
935
+ C<gzip@prep.ai.mit.edu> and Mark Adler C<madler@alumni.caltech.edu>.
936
+
937
+ The primary site for the I<zlib> compression library is
938
+ L<http://www.zlib.org>.
939
+
940
+ The primary site for the I<zlib-ng> compression library is
941
+ L<https://github.com/zlib-ng/zlib-ng>.
942
+
943
+ The primary site for gzip is L<http://www.gzip.org>.
944
+
945
+ =head1 AUTHOR
946
+
947
+ This module was written by Paul Marquess, C<pmqs@cpan.org>.
948
+
949
+ =head1 MODIFICATION HISTORY
950
+
951
+ See the Changes file.
952
+
953
+ =head1 COPYRIGHT AND LICENSE
954
+
955
+ Copyright (c) 2005-2024 Paul Marquess. All rights reserved.
956
+
957
+ This program is free software; you can redistribute it and/or
958
+ modify it under the same terms as Perl itself.
git/usr/share/perl5/core_perl/IO/Compress/Gzip.pm ADDED
@@ -0,0 +1,1333 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package IO::Compress::Gzip ;
2
+
3
+ require 5.006 ;
4
+
5
+ use strict ;
6
+ use warnings;
7
+ use bytes;
8
+
9
+ require Exporter ;
10
+
11
+ use IO::Compress::RawDeflate 2.213 () ;
12
+ use IO::Compress::Adapter::Deflate 2.213 ;
13
+
14
+ use IO::Compress::Base::Common 2.213 qw(:Status );
15
+ use IO::Compress::Gzip::Constants 2.213 ;
16
+ use IO::Compress::Zlib::Extra 2.213 ;
17
+
18
+ BEGIN
19
+ {
20
+ if (defined &utf8::downgrade )
21
+ { *noUTF8 = \&utf8::downgrade }
22
+ else
23
+ { *noUTF8 = sub {} }
24
+ }
25
+
26
+ our ($VERSION, @ISA, @EXPORT_OK, %EXPORT_TAGS, %DEFLATE_CONSTANTS, $GzipError);
27
+
28
+ $VERSION = '2.213';
29
+ $GzipError = '' ;
30
+
31
+ @ISA = qw(IO::Compress::RawDeflate Exporter);
32
+ @EXPORT_OK = qw( $GzipError gzip ) ;
33
+ %EXPORT_TAGS = %IO::Compress::RawDeflate::DEFLATE_CONSTANTS ;
34
+
35
+ push @{ $EXPORT_TAGS{all} }, @EXPORT_OK ;
36
+ Exporter::export_ok_tags('all');
37
+
38
+ sub new
39
+ {
40
+ my $class = shift ;
41
+
42
+ my $obj = IO::Compress::Base::Common::createSelfTiedObject($class, \$GzipError);
43
+
44
+ $obj->_create(undef, @_);
45
+ }
46
+
47
+
48
+ sub gzip
49
+ {
50
+ my $obj = IO::Compress::Base::Common::createSelfTiedObject(undef, \$GzipError);
51
+ return $obj->_def(@_);
52
+ }
53
+
54
+ #sub newHeader
55
+ #{
56
+ # my $self = shift ;
57
+ # #return GZIP_MINIMUM_HEADER ;
58
+ # return $self->mkHeader(*$self->{Got});
59
+ #}
60
+
61
+ sub getExtraParams
62
+ {
63
+ my $self = shift ;
64
+
65
+ return (
66
+ # zlib behaviour
67
+ $self->getZlibParams(),
68
+
69
+ # Gzip header fields
70
+ 'minimal' => [IO::Compress::Base::Common::Parse_boolean, 0],
71
+ 'comment' => [IO::Compress::Base::Common::Parse_any, undef],
72
+ 'name' => [IO::Compress::Base::Common::Parse_any, undef],
73
+ 'time' => [IO::Compress::Base::Common::Parse_any, undef],
74
+ 'textflag' => [IO::Compress::Base::Common::Parse_boolean, 0],
75
+ 'headercrc' => [IO::Compress::Base::Common::Parse_boolean, 0],
76
+ 'os_code' => [IO::Compress::Base::Common::Parse_unsigned, $Compress::Raw::Zlib::gzip_os_code],
77
+ 'extrafield'=> [IO::Compress::Base::Common::Parse_any, undef],
78
+ 'extraflags'=> [IO::Compress::Base::Common::Parse_any, undef],
79
+
80
+ );
81
+ }
82
+
83
+
84
+ sub ckParams
85
+ {
86
+ my $self = shift ;
87
+ my $got = shift ;
88
+
89
+ # gzip always needs crc32
90
+ $got->setValue('crc32' => 1);
91
+
92
+ return 1
93
+ if $got->getValue('merge') ;
94
+
95
+ my $strict = $got->getValue('strict') ;
96
+
97
+
98
+ {
99
+ if (! $got->parsed('time') ) {
100
+ # Modification time defaults to now.
101
+ $got->setValue(time => time) ;
102
+ }
103
+
104
+ # Check that the Name & Comment don't have embedded NULLs
105
+ # Also check that they only contain ISO 8859-1 chars.
106
+ if ($got->parsed('name') && defined $got->getValue('name')) {
107
+ my $name = $got->getValue('name');
108
+
109
+ return $self->saveErrorString(undef, "Null Character found in Name",
110
+ Z_DATA_ERROR)
111
+ if $strict && $name =~ /\x00/ ;
112
+
113
+ return $self->saveErrorString(undef, "Non ISO 8859-1 Character found in Name",
114
+ Z_DATA_ERROR)
115
+ if $strict && $name =~ /$GZIP_FNAME_INVALID_CHAR_RE/o ;
116
+ }
117
+
118
+ if ($got->parsed('comment') && defined $got->getValue('comment')) {
119
+ my $comment = $got->getValue('comment');
120
+
121
+ return $self->saveErrorString(undef, "Null Character found in Comment",
122
+ Z_DATA_ERROR)
123
+ if $strict && $comment =~ /\x00/ ;
124
+
125
+ return $self->saveErrorString(undef, "Non ISO 8859-1 Character found in Comment",
126
+ Z_DATA_ERROR)
127
+ if $strict && $comment =~ /$GZIP_FCOMMENT_INVALID_CHAR_RE/o;
128
+ }
129
+
130
+ if ($got->parsed('os_code') ) {
131
+ my $value = $got->getValue('os_code');
132
+
133
+ return $self->saveErrorString(undef, "OS_Code must be between 0 and 255, got '$value'")
134
+ if $value < 0 || $value > 255 ;
135
+
136
+ }
137
+
138
+ # gzip only supports Deflate at present
139
+ $got->setValue('method' => Z_DEFLATED) ;
140
+
141
+ if ( ! $got->parsed('extraflags')) {
142
+ $got->setValue('extraflags' => 2)
143
+ if $got->getValue('level') == Z_BEST_COMPRESSION ;
144
+ $got->setValue('extraflags' => 4)
145
+ if $got->getValue('level') == Z_BEST_SPEED ;
146
+ }
147
+
148
+ my $data = $got->getValue('extrafield') ;
149
+ if (defined $data) {
150
+ my $bad = IO::Compress::Zlib::Extra::parseExtraField($data, $strict, 1) ;
151
+ return $self->saveErrorString(undef, "Error with ExtraField Parameter: $bad", Z_DATA_ERROR)
152
+ if $bad ;
153
+
154
+ $got->setValue('extrafield' => $data) ;
155
+ }
156
+ }
157
+
158
+ return 1;
159
+ }
160
+
161
+ sub mkTrailer
162
+ {
163
+ my $self = shift ;
164
+ return pack("V V", *$self->{Compress}->crc32(),
165
+ *$self->{UnCompSize}->get32bit());
166
+ }
167
+
168
+ sub getInverseClass
169
+ {
170
+ no warnings 'once';
171
+ return ('IO::Uncompress::Gunzip',
172
+ \$IO::Uncompress::Gunzip::GunzipError);
173
+ }
174
+
175
+ sub getFileInfo
176
+ {
177
+ my $self = shift ;
178
+ my $params = shift;
179
+ my $filename = shift ;
180
+
181
+ return if IO::Compress::Base::Common::isaScalar($filename);
182
+
183
+ my $defaultTime = (stat($filename))[9] ;
184
+
185
+ $params->setValue('name' => $filename)
186
+ if ! $params->parsed('name') ;
187
+
188
+ $params->setValue('time' => $defaultTime)
189
+ if ! $params->parsed('time') ;
190
+ }
191
+
192
+
193
+ sub mkHeader
194
+ {
195
+ my $self = shift ;
196
+ my $param = shift ;
197
+
198
+ # short-circuit if a minimal header is requested.
199
+ return GZIP_MINIMUM_HEADER if $param->getValue('minimal') ;
200
+
201
+ # METHOD
202
+ my $method = $param->valueOrDefault('method', GZIP_CM_DEFLATED) ;
203
+
204
+ # FLAGS
205
+ my $flags = GZIP_FLG_DEFAULT ;
206
+ $flags |= GZIP_FLG_FTEXT if $param->getValue('textflag') ;
207
+ $flags |= GZIP_FLG_FHCRC if $param->getValue('headercrc') ;
208
+ $flags |= GZIP_FLG_FEXTRA if $param->wantValue('extrafield') ;
209
+ $flags |= GZIP_FLG_FNAME if $param->wantValue('name') ;
210
+ $flags |= GZIP_FLG_FCOMMENT if $param->wantValue('comment') ;
211
+
212
+ # MTIME
213
+ my $time = $param->valueOrDefault('time', GZIP_MTIME_DEFAULT) ;
214
+
215
+ # EXTRA FLAGS
216
+ my $extra_flags = $param->valueOrDefault('extraflags', GZIP_XFL_DEFAULT);
217
+
218
+ # OS CODE
219
+ my $os_code = $param->valueOrDefault('os_code', GZIP_OS_DEFAULT) ;
220
+
221
+
222
+ my $out = pack("C4 V C C",
223
+ GZIP_ID1, # ID1
224
+ GZIP_ID2, # ID2
225
+ $method, # Compression Method
226
+ $flags, # Flags
227
+ $time, # Modification Time
228
+ $extra_flags, # Extra Flags
229
+ $os_code, # Operating System Code
230
+ ) ;
231
+
232
+ # EXTRA
233
+ if ($flags & GZIP_FLG_FEXTRA) {
234
+ my $extra = $param->getValue('extrafield') ;
235
+ $out .= pack("v", length $extra) . $extra ;
236
+ }
237
+
238
+ # NAME
239
+ if ($flags & GZIP_FLG_FNAME) {
240
+ my $name .= $param->getValue('name') ;
241
+ $name =~ s/\x00.*$//;
242
+ $out .= $name ;
243
+ # Terminate the filename with NULL unless it already is
244
+ $out .= GZIP_NULL_BYTE
245
+ if !length $name or
246
+ substr($name, 1, -1) ne GZIP_NULL_BYTE ;
247
+ }
248
+
249
+ # COMMENT
250
+ if ($flags & GZIP_FLG_FCOMMENT) {
251
+ my $comment .= $param->getValue('comment') ;
252
+ $comment =~ s/\x00.*$//;
253
+ $out .= $comment ;
254
+ # Terminate the comment with NULL unless it already is
255
+ $out .= GZIP_NULL_BYTE
256
+ if ! length $comment or
257
+ substr($comment, 1, -1) ne GZIP_NULL_BYTE;
258
+ }
259
+
260
+ # HEADER CRC
261
+ $out .= pack("v", Compress::Raw::Zlib::crc32($out) & 0x00FF )
262
+ if $param->getValue('headercrc') ;
263
+
264
+ noUTF8($out);
265
+
266
+ return $out ;
267
+ }
268
+
269
+ sub mkFinalTrailer
270
+ {
271
+ return '';
272
+ }
273
+
274
+ 1;
275
+
276
+ __END__
277
+
278
+ =head1 NAME
279
+
280
+ IO::Compress::Gzip - Write RFC 1952 files/buffers
281
+
282
+ =head1 SYNOPSIS
283
+
284
+ use IO::Compress::Gzip qw(gzip $GzipError) ;
285
+
286
+ my $status = gzip $input => $output [,OPTS]
287
+ or die "gzip failed: $GzipError\n";
288
+
289
+ my $z = IO::Compress::Gzip->new( $output [,OPTS] )
290
+ or die "gzip failed: $GzipError\n";
291
+
292
+ $z->print($string);
293
+ $z->printf($format, $string);
294
+ $z->write($string);
295
+ $z->syswrite($string [, $length, $offset]);
296
+ $z->flush();
297
+ $z->tell();
298
+ $z->eof();
299
+ $z->seek($position, $whence);
300
+ $z->binmode();
301
+ $z->fileno();
302
+ $z->opened();
303
+ $z->autoflush();
304
+ $z->input_line_number();
305
+ $z->newStream( [OPTS] );
306
+
307
+ $z->deflateParams();
308
+
309
+ $z->close() ;
310
+
311
+ $GzipError ;
312
+
313
+ # IO::File mode
314
+
315
+ print $z $string;
316
+ printf $z $format, $string;
317
+ tell $z
318
+ eof $z
319
+ seek $z, $position, $whence
320
+ binmode $z
321
+ fileno $z
322
+ close $z ;
323
+
324
+ =head1 DESCRIPTION
325
+
326
+ This module provides a Perl interface that allows writing compressed
327
+ data to files or buffer as defined in RFC 1952.
328
+
329
+ All the gzip headers defined in RFC 1952 can be created using
330
+ this module.
331
+
332
+ For reading RFC 1952 files/buffers, see the companion module
333
+ L<IO::Uncompress::Gunzip|IO::Uncompress::Gunzip>.
334
+
335
+ =head1 Functional Interface
336
+
337
+ A top-level function, C<gzip>, is provided to carry out
338
+ "one-shot" compression between buffers and/or files. For finer
339
+ control over the compression process, see the L</"OO Interface">
340
+ section.
341
+
342
+ use IO::Compress::Gzip qw(gzip $GzipError) ;
343
+
344
+ gzip $input_filename_or_reference => $output_filename_or_reference [,OPTS]
345
+ or die "gzip failed: $GzipError\n";
346
+
347
+ The functional interface needs Perl5.005 or better.
348
+
349
+ =head2 gzip $input_filename_or_reference => $output_filename_or_reference [, OPTS]
350
+
351
+ C<gzip> expects at least two parameters,
352
+ C<$input_filename_or_reference> and C<$output_filename_or_reference>
353
+ and zero or more optional parameters (see L</Optional Parameters>)
354
+
355
+ =head3 The C<$input_filename_or_reference> parameter
356
+
357
+ The parameter, C<$input_filename_or_reference>, is used to define the
358
+ source of the uncompressed data.
359
+
360
+ It can take one of the following forms:
361
+
362
+ =over 5
363
+
364
+ =item A filename
365
+
366
+ If the C<$input_filename_or_reference> parameter is a simple scalar, it is
367
+ assumed to be a filename. This file will be opened for reading and the
368
+ input data will be read from it.
369
+
370
+ =item A filehandle
371
+
372
+ If the C<$input_filename_or_reference> parameter is a filehandle, the input
373
+ data will be read from it. The string '-' can be used as an alias for
374
+ standard input.
375
+
376
+ =item A scalar reference
377
+
378
+ If C<$input_filename_or_reference> is a scalar reference, the input data
379
+ will be read from C<$$input_filename_or_reference>.
380
+
381
+ =item An array reference
382
+
383
+ If C<$input_filename_or_reference> is an array reference, each element in
384
+ the array must be a filename.
385
+
386
+ The input data will be read from each file in turn.
387
+
388
+ The complete array will be walked to ensure that it only
389
+ contains valid filenames before any data is compressed.
390
+
391
+ =item An Input FileGlob string
392
+
393
+ If C<$input_filename_or_reference> is a string that is delimited by the
394
+ characters "<" and ">" C<gzip> will assume that it is an
395
+ I<input fileglob string>. The input is the list of files that match the
396
+ fileglob.
397
+
398
+ See L<File::GlobMapper|File::GlobMapper> for more details.
399
+
400
+ =back
401
+
402
+ If the C<$input_filename_or_reference> parameter is any other type,
403
+ C<undef> will be returned.
404
+
405
+ In addition, if C<$input_filename_or_reference> is a simple filename,
406
+ the default values for
407
+ the C<Name> and C<Time> options will be sourced from that file.
408
+
409
+ If you do not want to use these defaults they can be overridden by
410
+ explicitly setting the C<Name> and C<Time> options or by setting the
411
+ C<Minimal> parameter.
412
+
413
+ =head3 The C<$output_filename_or_reference> parameter
414
+
415
+ The parameter C<$output_filename_or_reference> is used to control the
416
+ destination of the compressed data. This parameter can take one of
417
+ these forms.
418
+
419
+ =over 5
420
+
421
+ =item A filename
422
+
423
+ If the C<$output_filename_or_reference> parameter is a simple scalar, it is
424
+ assumed to be a filename. This file will be opened for writing and the
425
+ compressed data will be written to it.
426
+
427
+ =item A filehandle
428
+
429
+ If the C<$output_filename_or_reference> parameter is a filehandle, the
430
+ compressed data will be written to it. The string '-' can be used as
431
+ an alias for standard output.
432
+
433
+ =item A scalar reference
434
+
435
+ If C<$output_filename_or_reference> is a scalar reference, the
436
+ compressed data will be stored in C<$$output_filename_or_reference>.
437
+
438
+ =item An Array Reference
439
+
440
+ If C<$output_filename_or_reference> is an array reference,
441
+ the compressed data will be pushed onto the array.
442
+
443
+ =item An Output FileGlob
444
+
445
+ If C<$output_filename_or_reference> is a string that is delimited by the
446
+ characters "<" and ">" C<gzip> will assume that it is an
447
+ I<output fileglob string>. The output is the list of files that match the
448
+ fileglob.
449
+
450
+ When C<$output_filename_or_reference> is an fileglob string,
451
+ C<$input_filename_or_reference> must also be a fileglob string. Anything
452
+ else is an error.
453
+
454
+ See L<File::GlobMapper|File::GlobMapper> for more details.
455
+
456
+ =back
457
+
458
+ If the C<$output_filename_or_reference> parameter is any other type,
459
+ C<undef> will be returned.
460
+
461
+ =head2 Notes
462
+
463
+ When C<$input_filename_or_reference> maps to multiple files/buffers and
464
+ C<$output_filename_or_reference> is a single
465
+ file/buffer the input files/buffers will be stored
466
+ in C<$output_filename_or_reference> as a concatenated series of compressed data streams.
467
+
468
+ =head2 Optional Parameters
469
+
470
+ The optional parameters for the one-shot function C<gzip>
471
+ are (for the most part) identical to those used with the OO interface defined in the
472
+ L</"Constructor Options"> section. The exceptions are listed below
473
+
474
+ =over 5
475
+
476
+ =item C<< AutoClose => 0|1 >>
477
+
478
+ This option applies to any input or output data streams to
479
+ C<gzip> that are filehandles.
480
+
481
+ If C<AutoClose> is specified, and the value is true, it will result in all
482
+ input and/or output filehandles being closed once C<gzip> has
483
+ completed.
484
+
485
+ This parameter defaults to 0.
486
+
487
+ =item C<< BinModeIn => 0|1 >>
488
+
489
+ This option is now a no-op. All files will be read in binmode.
490
+
491
+ =item C<< Append => 0|1 >>
492
+
493
+ The behaviour of this option is dependent on the type of output data
494
+ stream.
495
+
496
+ =over 5
497
+
498
+ =item * A Buffer
499
+
500
+ If C<Append> is enabled, all compressed data will be append to the end of
501
+ the output buffer. Otherwise the output buffer will be cleared before any
502
+ compressed data is written to it.
503
+
504
+ =item * A Filename
505
+
506
+ If C<Append> is enabled, the file will be opened in append mode. Otherwise
507
+ the contents of the file, if any, will be truncated before any compressed
508
+ data is written to it.
509
+
510
+ =item * A Filehandle
511
+
512
+ If C<Append> is enabled, the filehandle will be positioned to the end of
513
+ the file via a call to C<seek> before any compressed data is
514
+ written to it. Otherwise the file pointer will not be moved.
515
+
516
+ =back
517
+
518
+ When C<Append> is specified, and set to true, it will I<append> all compressed
519
+ data to the output data stream.
520
+
521
+ So when the output is a filehandle it will carry out a seek to the eof
522
+ before writing any compressed data. If the output is a filename, it will be opened for
523
+ appending. If the output is a buffer, all compressed data will be
524
+ appended to the existing buffer.
525
+
526
+ Conversely when C<Append> is not specified, or it is present and is set to
527
+ false, it will operate as follows.
528
+
529
+ When the output is a filename, it will truncate the contents of the file
530
+ before writing any compressed data. If the output is a filehandle
531
+ its position will not be changed. If the output is a buffer, it will be
532
+ wiped before any compressed data is output.
533
+
534
+ Defaults to 0.
535
+
536
+ =back
537
+
538
+ =head2 Oneshot Examples
539
+
540
+ Here are a few example that show the capabilities of the module.
541
+
542
+ =head3 Streaming
543
+
544
+ This very simple command line example demonstrates the streaming capabilities of the module.
545
+ The code reads data from STDIN, compresses it, and writes the compressed data to STDOUT.
546
+
547
+ $ echo hello world | perl -MIO::Compress::Gzip=gzip -e 'gzip \*STDIN => \*STDOUT' >output.gz
548
+
549
+ The special filename "-" can be used as a standin for both C<\*STDIN> and C<\*STDOUT>,
550
+ so the above can be rewritten as
551
+
552
+ $ echo hello world | perl -MIO::Compress::Gzip=gzip -e 'gzip "-" => "-"' >output.gz
553
+
554
+ =head3 Compressing a file from the filesystem
555
+
556
+ To read the contents of the file C<file1.txt> and write the compressed
557
+ data to the file C<file1.txt.gz>.
558
+
559
+ use strict ;
560
+ use warnings ;
561
+ use IO::Compress::Gzip qw(gzip $GzipError) ;
562
+
563
+ my $input = "file1.txt";
564
+ gzip $input => "$input.gz"
565
+ or die "gzip failed: $GzipError\n";
566
+
567
+ =head3 Reading from a Filehandle and writing to an in-memory buffer
568
+
569
+ To read from an existing Perl filehandle, C<$input>, and write the
570
+ compressed data to a buffer, C<$buffer>.
571
+
572
+ use strict ;
573
+ use warnings ;
574
+ use IO::Compress::Gzip qw(gzip $GzipError) ;
575
+ use IO::File ;
576
+
577
+ my $input = IO::File->new( "<file1.txt" )
578
+ or die "Cannot open 'file1.txt': $!\n" ;
579
+ my $buffer ;
580
+ gzip $input => \$buffer
581
+ or die "gzip failed: $GzipError\n";
582
+
583
+ =head3 Compressing multiple files
584
+
585
+ To compress all files in the directory "/my/home" that match "*.txt"
586
+ and store the compressed data in the same directory
587
+
588
+ use strict ;
589
+ use warnings ;
590
+ use IO::Compress::Gzip qw(gzip $GzipError) ;
591
+
592
+ gzip '</my/home/*.txt>' => '<*.gz>'
593
+ or die "gzip failed: $GzipError\n";
594
+
595
+ and if you want to compress each file one at a time, this will do the trick
596
+
597
+ use strict ;
598
+ use warnings ;
599
+ use IO::Compress::Gzip qw(gzip $GzipError) ;
600
+
601
+ for my $input ( glob "/my/home/*.txt" )
602
+ {
603
+ my $output = "$input.gz" ;
604
+ gzip $input => $output
605
+ or die "Error compressing '$input': $GzipError\n";
606
+ }
607
+
608
+ =head1 OO Interface
609
+
610
+ =head2 Constructor
611
+
612
+ The format of the constructor for C<IO::Compress::Gzip> is shown below
613
+
614
+ my $z = IO::Compress::Gzip->new( $output [,OPTS] )
615
+ or die "IO::Compress::Gzip failed: $GzipError\n";
616
+
617
+ The constructor takes one mandatory parameter, C<$output>, defined below and
618
+ zero or more C<OPTS>, defined in L<Constructor Options>.
619
+
620
+ It returns an C<IO::Compress::Gzip> object on success and C<undef> on failure.
621
+ The variable C<$GzipError> will contain an error message on failure.
622
+
623
+ If you are running Perl 5.005 or better the object, C<$z>, returned from
624
+ IO::Compress::Gzip can be used exactly like an L<IO::File|IO::File> filehandle.
625
+ This means that all normal output file operations can be carried out
626
+ with C<$z>.
627
+ For example, to write to a compressed file/buffer you can use either of
628
+ these forms
629
+
630
+ $z->print("hello world\n");
631
+ print $z "hello world\n";
632
+
633
+ Below is a simple exaple of using the OO interface to create an output file
634
+ C<myfile.gz> and write some data to it.
635
+
636
+ my $filename = "myfile.gz";
637
+ my $z = IO::Compress::Gzip->new($filename)
638
+ or die "IO::Compress::Gzip failed: $GzipError\n";
639
+
640
+ $z->print("abcde");
641
+ $z->close();
642
+
643
+ See the L</Examples> for more.
644
+
645
+ The mandatory parameter C<$output> is used to control the destination
646
+ of the compressed data. This parameter can take one of these forms.
647
+
648
+ =over 5
649
+
650
+ =item A filename
651
+
652
+ If the C<$output> parameter is a simple scalar, it is assumed to be a
653
+ filename. This file will be opened for writing and the compressed data
654
+ will be written to it.
655
+
656
+ =item A filehandle
657
+
658
+ If the C<$output> parameter is a filehandle, the compressed data will be
659
+ written to it.
660
+ The string '-' can be used as an alias for standard output.
661
+
662
+ =item A scalar reference
663
+
664
+ If C<$output> is a scalar reference, the compressed data will be stored
665
+ in C<$$output>.
666
+
667
+ =back
668
+
669
+ If the C<$output> parameter is any other type, C<IO::Compress::Gzip>::new will
670
+ return undef.
671
+
672
+ =head2 Constructor Options
673
+
674
+ C<OPTS> is any combination of zero or more the following options:
675
+
676
+ =over 5
677
+
678
+ =item C<< AutoClose => 0|1 >>
679
+
680
+ This option is only valid when the C<$output> parameter is a filehandle. If
681
+ specified, and the value is true, it will result in the C<$output> being
682
+ closed once either the C<close> method is called or the C<IO::Compress::Gzip>
683
+ object is destroyed.
684
+
685
+ This parameter defaults to 0.
686
+
687
+ =item C<< Append => 0|1 >>
688
+
689
+ Opens C<$output> in append mode.
690
+
691
+ The behaviour of this option is dependent on the type of C<$output>.
692
+
693
+ =over 5
694
+
695
+ =item * A Buffer
696
+
697
+ If C<$output> is a buffer and C<Append> is enabled, all compressed data
698
+ will be append to the end of C<$output>. Otherwise C<$output> will be
699
+ cleared before any data is written to it.
700
+
701
+ =item * A Filename
702
+
703
+ If C<$output> is a filename and C<Append> is enabled, the file will be
704
+ opened in append mode. Otherwise the contents of the file, if any, will be
705
+ truncated before any compressed data is written to it.
706
+
707
+ =item * A Filehandle
708
+
709
+ If C<$output> is a filehandle, the file pointer will be positioned to the
710
+ end of the file via a call to C<seek> before any compressed data is written
711
+ to it. Otherwise the file pointer will not be moved.
712
+
713
+ =back
714
+
715
+ This parameter defaults to 0.
716
+
717
+ =item C<< Merge => 0|1 >>
718
+
719
+ This option is used to compress input data and append it to an existing
720
+ compressed data stream in C<$output>. The end result is a single compressed
721
+ data stream stored in C<$output>.
722
+
723
+ It is a fatal error to attempt to use this option when C<$output> is not an
724
+ RFC 1952 data stream.
725
+
726
+ There are a number of other limitations with the C<Merge> option:
727
+
728
+ =over 5
729
+
730
+ =item 1
731
+
732
+ This module needs to have been built with zlib 1.2.1 or better to work. A
733
+ fatal error will be thrown if C<Merge> is used with an older version of
734
+ zlib.
735
+
736
+ =item 2
737
+
738
+ If C<$output> is a file or a filehandle, it must be seekable.
739
+
740
+ =back
741
+
742
+ This parameter defaults to 0.
743
+
744
+ =item -Level
745
+
746
+ Defines the compression level used by zlib. The value should either be
747
+ a number between 0 and 9 (0 means no compression and 9 is maximum
748
+ compression), or one of the symbolic constants defined below.
749
+
750
+ Z_NO_COMPRESSION
751
+ Z_BEST_SPEED
752
+ Z_BEST_COMPRESSION
753
+ Z_DEFAULT_COMPRESSION
754
+
755
+ The default is Z_DEFAULT_COMPRESSION.
756
+
757
+ Note, these constants are not imported by C<IO::Compress::Gzip> by default.
758
+
759
+ use IO::Compress::Gzip qw(:strategy);
760
+ use IO::Compress::Gzip qw(:constants);
761
+ use IO::Compress::Gzip qw(:all);
762
+
763
+ =item -Strategy
764
+
765
+ Defines the strategy used to tune the compression. Use one of the symbolic
766
+ constants defined below.
767
+
768
+ Z_FILTERED
769
+ Z_HUFFMAN_ONLY
770
+ Z_RLE
771
+ Z_FIXED
772
+ Z_DEFAULT_STRATEGY
773
+
774
+ The default is Z_DEFAULT_STRATEGY.
775
+
776
+ =item C<< Minimal => 0|1 >>
777
+
778
+ If specified, this option will force the creation of the smallest possible
779
+ compliant gzip header (which is exactly 10 bytes long) as defined in
780
+ RFC 1952.
781
+
782
+ See the section titled "Compliance" in RFC 1952 for a definition
783
+ of the values used for the fields in the gzip header.
784
+
785
+ All other parameters that control the content of the gzip header will
786
+ be ignored if this parameter is set to 1.
787
+
788
+ This parameter defaults to 0.
789
+
790
+ =item C<< Comment => $comment >>
791
+
792
+ Stores the contents of C<$comment> in the COMMENT field in
793
+ the gzip header.
794
+ By default, no comment field is written to the gzip file.
795
+
796
+ If the C<-Strict> option is enabled, the comment can only consist of ISO
797
+ 8859-1 characters plus line feed.
798
+
799
+ If the C<-Strict> option is disabled, the comment field can contain any
800
+ character except NULL. If any null characters are present, the field
801
+ will be truncated at the first NULL.
802
+
803
+ =item C<< Name => $string >>
804
+
805
+ Stores the contents of C<$string> in the gzip NAME header field. If
806
+ C<Name> is not specified, no gzip NAME field will be created.
807
+
808
+ If the C<-Strict> option is enabled, C<$string> can only consist of ISO
809
+ 8859-1 characters.
810
+
811
+ If C<-Strict> is disabled, then C<$string> can contain any character
812
+ except NULL. If any null characters are present, the field will be
813
+ truncated at the first NULL.
814
+
815
+ =item C<< Time => $number >>
816
+
817
+ Sets the MTIME field in the gzip header to $number.
818
+
819
+ This field defaults to the time the C<IO::Compress::Gzip> object was created
820
+ if this option is not specified.
821
+
822
+ =item C<< TextFlag => 0|1 >>
823
+
824
+ This parameter controls the setting of the FLG.FTEXT bit in the gzip
825
+ header. It is used to signal that the data stored in the gzip file/buffer
826
+ is probably text.
827
+
828
+ The default is 0.
829
+
830
+ =item C<< HeaderCRC => 0|1 >>
831
+
832
+ When true this parameter will set the FLG.FHCRC bit to 1 in the gzip header
833
+ and set the CRC16 header field to the CRC of the complete gzip header
834
+ except the CRC16 field itself.
835
+
836
+ B<Note> that gzip files created with the C<HeaderCRC> flag set to 1 cannot
837
+ be read by most, if not all, of the standard gunzip utilities, most
838
+ notably gzip version 1.2.4. You should therefore avoid using this option if
839
+ you want to maximize the portability of your gzip files.
840
+
841
+ This parameter defaults to 0.
842
+
843
+ =item C<< OS_Code => $value >>
844
+
845
+ Stores C<$value> in the gzip OS header field. A number between 0 and 255 is
846
+ valid.
847
+
848
+ If not specified, this parameter defaults to the OS code of the Operating
849
+ System this module was built on. The value 3 is used as a catch-all for all
850
+ Unix variants and unknown Operating Systems.
851
+
852
+ =item C<< ExtraField => $data >>
853
+
854
+ This parameter allows additional metadata to be stored in the ExtraField in
855
+ the gzip header. An RFC 1952 compliant ExtraField consists of zero or more
856
+ subfields. Each subfield consists of a two byte header followed by the
857
+ subfield data.
858
+
859
+ The list of subfields can be supplied in any of the following formats
860
+
861
+ -ExtraField => [$id1, $data1,
862
+ $id2, $data2,
863
+ ...
864
+ ]
865
+ -ExtraField => [ [$id1 => $data1],
866
+ [$id2 => $data2],
867
+ ...
868
+ ]
869
+ -ExtraField => { $id1 => $data1,
870
+ $id2 => $data2,
871
+ ...
872
+ }
873
+
874
+ Where C<$id1>, C<$id2> are two byte subfield ID's. The second byte of
875
+ the ID cannot be 0, unless the C<Strict> option has been disabled.
876
+
877
+ If you use the hash syntax, you have no control over the order in which
878
+ the ExtraSubFields are stored, plus you cannot have SubFields with
879
+ duplicate ID.
880
+
881
+ Alternatively the list of subfields can by supplied as a scalar, thus
882
+
883
+ -ExtraField => $rawdata
884
+
885
+ If you use the raw format, and the C<Strict> option is enabled,
886
+ C<IO::Compress::Gzip> will check that C<$rawdata> consists of zero or more
887
+ conformant sub-fields. When C<Strict> is disabled, C<$rawdata> can
888
+ consist of any arbitrary byte stream.
889
+
890
+ The maximum size of the Extra Field 65535 bytes.
891
+
892
+ =item C<< ExtraFlags => $value >>
893
+
894
+ Sets the XFL byte in the gzip header to C<$value>.
895
+
896
+ If this option is not present, the value stored in XFL field will be
897
+ determined by the setting of the C<Level> option.
898
+
899
+ If C<< Level => Z_BEST_SPEED >> has been specified then XFL is set to 2.
900
+ If C<< Level => Z_BEST_COMPRESSION >> has been specified then XFL is set to 4.
901
+ Otherwise XFL is set to 0.
902
+
903
+ =item C<< Strict => 0|1 >>
904
+
905
+ C<Strict> will optionally police the values supplied with other options
906
+ to ensure they are compliant with RFC1952.
907
+
908
+ This option is enabled by default.
909
+
910
+ If C<Strict> is enabled the following behaviour will be policed:
911
+
912
+ =over 5
913
+
914
+ =item *
915
+
916
+ The value supplied with the C<Name> option can only contain ISO 8859-1
917
+ characters.
918
+
919
+ =item *
920
+
921
+ The value supplied with the C<Comment> option can only contain ISO 8859-1
922
+ characters plus line-feed.
923
+
924
+ =item *
925
+
926
+ The values supplied with the C<-Name> and C<-Comment> options cannot
927
+ contain multiple embedded nulls.
928
+
929
+ =item *
930
+
931
+ If an C<ExtraField> option is specified and it is a simple scalar,
932
+ it must conform to the sub-field structure as defined in RFC 1952.
933
+
934
+ =item *
935
+
936
+ If an C<ExtraField> option is specified the second byte of the ID will be
937
+ checked in each subfield to ensure that it does not contain the reserved
938
+ value 0x00.
939
+
940
+ =back
941
+
942
+ When C<Strict> is disabled the following behaviour will be policed:
943
+
944
+ =over 5
945
+
946
+ =item *
947
+
948
+ The value supplied with C<-Name> option can contain
949
+ any character except NULL.
950
+
951
+ =item *
952
+
953
+ The value supplied with C<-Comment> option can contain any character
954
+ except NULL.
955
+
956
+ =item *
957
+
958
+ The values supplied with the C<-Name> and C<-Comment> options can contain
959
+ multiple embedded nulls. The string written to the gzip header will
960
+ consist of the characters up to, but not including, the first embedded
961
+ NULL.
962
+
963
+ =item *
964
+
965
+ If an C<ExtraField> option is specified and it is a simple scalar, the
966
+ structure will not be checked. The only error is if the length is too big.
967
+
968
+ =item *
969
+
970
+ The ID header in an C<ExtraField> sub-field can consist of any two bytes.
971
+
972
+ =back
973
+
974
+ =back
975
+
976
+ =head2 Examples
977
+
978
+ =head3 Streaming
979
+
980
+ This very simple command line example demonstrates the streaming capabilities
981
+ of the module. The code reads data from STDIN or all the files given on the
982
+ commandline, compresses it, and writes the compressed data to STDOUT.
983
+
984
+ use strict ;
985
+ use warnings ;
986
+ use IO::Compress::Gzip qw(gzip $GzipError) ;
987
+
988
+ my $z = IO::Compress::Gzip->new("-", Stream => 1)
989
+ or die "IO::Compress::Gzip failed: $GzipError\n";
990
+
991
+ while (<>) {
992
+ $z->print("abcde");
993
+ }
994
+ $z->close();
995
+
996
+ Note the use of C<"-"> to means C<STDOUT>. Alternatively you can use C<\*STDOUT>.
997
+
998
+ =head3 Compressing a file from the filesystem
999
+
1000
+ To read the contents of the file C<file1.txt> and write the compressed
1001
+ data to the file C<file1.txt.gz> there are a few options
1002
+
1003
+ Start by creating the compression object and opening the input file
1004
+
1005
+ use strict ;
1006
+ use warnings ;
1007
+ use IO::Compress::Gzip qw(gzip $GzipError) ;
1008
+
1009
+ my $input = "file1.txt";
1010
+ my $z = IO::Compress::Gzip->new("file1.txt.gz")
1011
+ or die "IO::Compress::Gzip failed: $GzipError\n";
1012
+
1013
+ # open the input file
1014
+ open my $fh, "<", "file1.txt"
1015
+ or die "Cannot open file1.txt: $!\n";
1016
+
1017
+ # loop through the input file & write to the compressed file
1018
+ while (<$fh>) {
1019
+ $z->print($_);
1020
+ }
1021
+
1022
+ # not forgetting to close the compressed file
1023
+ $z->close();
1024
+
1025
+ =head1 Methods
1026
+
1027
+ =head2 print
1028
+
1029
+ Usage is
1030
+
1031
+ $z->print($data)
1032
+ print $z $data
1033
+
1034
+ Compresses and outputs the contents of the C<$data> parameter. This
1035
+ has the same behaviour as the C<print> built-in.
1036
+
1037
+ Returns true if successful.
1038
+
1039
+ =head2 printf
1040
+
1041
+ Usage is
1042
+
1043
+ $z->printf($format, $data)
1044
+ printf $z $format, $data
1045
+
1046
+ Compresses and outputs the contents of the C<$data> parameter.
1047
+
1048
+ Returns true if successful.
1049
+
1050
+ =head2 syswrite
1051
+
1052
+ Usage is
1053
+
1054
+ $z->syswrite $data
1055
+ $z->syswrite $data, $length
1056
+ $z->syswrite $data, $length, $offset
1057
+
1058
+ Compresses and outputs the contents of the C<$data> parameter.
1059
+
1060
+ Returns the number of uncompressed bytes written, or C<undef> if
1061
+ unsuccessful.
1062
+
1063
+ =head2 write
1064
+
1065
+ Usage is
1066
+
1067
+ $z->write $data
1068
+ $z->write $data, $length
1069
+ $z->write $data, $length, $offset
1070
+
1071
+ Compresses and outputs the contents of the C<$data> parameter.
1072
+
1073
+ Returns the number of uncompressed bytes written, or C<undef> if
1074
+ unsuccessful.
1075
+
1076
+ =head2 flush
1077
+
1078
+ Usage is
1079
+
1080
+ $z->flush;
1081
+ $z->flush($flush_type);
1082
+
1083
+ Flushes any pending compressed data to the output file/buffer.
1084
+
1085
+ This method takes an optional parameter, C<$flush_type>, that controls
1086
+ how the flushing will be carried out. By default the C<$flush_type>
1087
+ used is C<Z_FINISH>. Other valid values for C<$flush_type> are
1088
+ C<Z_NO_FLUSH>, C<Z_SYNC_FLUSH>, C<Z_FULL_FLUSH> and C<Z_BLOCK>. It is
1089
+ strongly recommended that you only set the C<flush_type> parameter if
1090
+ you fully understand the implications of what it does - overuse of C<flush>
1091
+ can seriously degrade the level of compression achieved. See the C<zlib>
1092
+ documentation for details.
1093
+
1094
+ Returns true on success.
1095
+
1096
+ =head2 tell
1097
+
1098
+ Usage is
1099
+
1100
+ $z->tell()
1101
+ tell $z
1102
+
1103
+ Returns the uncompressed file offset.
1104
+
1105
+ =head2 eof
1106
+
1107
+ Usage is
1108
+
1109
+ $z->eof();
1110
+ eof($z);
1111
+
1112
+ Returns true if the C<close> method has been called.
1113
+
1114
+ =head2 seek
1115
+
1116
+ $z->seek($position, $whence);
1117
+ seek($z, $position, $whence);
1118
+
1119
+ Provides a sub-set of the C<seek> functionality, with the restriction
1120
+ that it is only legal to seek forward in the output file/buffer.
1121
+ It is a fatal error to attempt to seek backward.
1122
+
1123
+ Empty parts of the file/buffer will have NULL (0x00) bytes written to them.
1124
+
1125
+ The C<$whence> parameter takes one the usual values, namely SEEK_SET,
1126
+ SEEK_CUR or SEEK_END.
1127
+
1128
+ Returns 1 on success, 0 on failure.
1129
+
1130
+ =head2 binmode
1131
+
1132
+ Usage is
1133
+
1134
+ $z->binmode
1135
+ binmode $z ;
1136
+
1137
+ This is a noop provided for completeness.
1138
+
1139
+ =head2 opened
1140
+
1141
+ $z->opened()
1142
+
1143
+ Returns true if the object currently refers to a opened file/buffer.
1144
+
1145
+ =head2 autoflush
1146
+
1147
+ my $prev = $z->autoflush()
1148
+ my $prev = $z->autoflush(EXPR)
1149
+
1150
+ If the C<$z> object is associated with a file or a filehandle, this method
1151
+ returns the current autoflush setting for the underlying filehandle. If
1152
+ C<EXPR> is present, and is non-zero, it will enable flushing after every
1153
+ write/print operation.
1154
+
1155
+ If C<$z> is associated with a buffer, this method has no effect and always
1156
+ returns C<undef>.
1157
+
1158
+ B<Note> that the special variable C<$|> B<cannot> be used to set or
1159
+ retrieve the autoflush setting.
1160
+
1161
+ =head2 input_line_number
1162
+
1163
+ $z->input_line_number()
1164
+ $z->input_line_number(EXPR)
1165
+
1166
+ This method always returns C<undef> when compressing.
1167
+
1168
+ =head2 fileno
1169
+
1170
+ $z->fileno()
1171
+ fileno($z)
1172
+
1173
+ If the C<$z> object is associated with a file or a filehandle, C<fileno>
1174
+ will return the underlying file descriptor. Once the C<close> method is
1175
+ called C<fileno> will return C<undef>.
1176
+
1177
+ If the C<$z> object is associated with a buffer, this method will return
1178
+ C<undef>.
1179
+
1180
+ =head2 close
1181
+
1182
+ $z->close() ;
1183
+ close $z ;
1184
+
1185
+ Flushes any pending compressed data and then closes the output file/buffer.
1186
+
1187
+ For most versions of Perl this method will be automatically invoked if
1188
+ the IO::Compress::Gzip object is destroyed (either explicitly or by the
1189
+ variable with the reference to the object going out of scope). The
1190
+ exceptions are Perl versions 5.005 through 5.00504 and 5.8.0. In
1191
+ these cases, the C<close> method will be called automatically, but
1192
+ not until global destruction of all live objects when the program is
1193
+ terminating.
1194
+
1195
+ Therefore, if you want your scripts to be able to run on all versions
1196
+ of Perl, you should call C<close> explicitly and not rely on automatic
1197
+ closing.
1198
+
1199
+ Returns true on success, otherwise 0.
1200
+
1201
+ If the C<AutoClose> option has been enabled when the IO::Compress::Gzip
1202
+ object was created, and the object is associated with a file, the
1203
+ underlying file will also be closed.
1204
+
1205
+ =head2 newStream([OPTS])
1206
+
1207
+ Usage is
1208
+
1209
+ $z->newStream( [OPTS] )
1210
+
1211
+ Closes the current compressed data stream and starts a new one.
1212
+
1213
+ OPTS consists of any of the options that are available when creating
1214
+ the C<$z> object.
1215
+
1216
+ See the L</"Constructor Options"> section for more details.
1217
+
1218
+ =head2 deflateParams
1219
+
1220
+ Usage is
1221
+
1222
+ $z->deflateParams
1223
+
1224
+ TODO
1225
+
1226
+ =head1 Importing
1227
+
1228
+ A number of symbolic constants are required by some methods in
1229
+ C<IO::Compress::Gzip>. None are imported by default.
1230
+
1231
+ =over 5
1232
+
1233
+ =item :all
1234
+
1235
+ Imports C<gzip>, C<$GzipError> and all symbolic
1236
+ constants that can be used by C<IO::Compress::Gzip>. Same as doing this
1237
+
1238
+ use IO::Compress::Gzip qw(gzip $GzipError :constants) ;
1239
+
1240
+ =item :constants
1241
+
1242
+ Import all symbolic constants. Same as doing this
1243
+
1244
+ use IO::Compress::Gzip qw(:flush :level :strategy) ;
1245
+
1246
+ =item :flush
1247
+
1248
+ These symbolic constants are used by the C<flush> method.
1249
+
1250
+ Z_NO_FLUSH
1251
+ Z_PARTIAL_FLUSH
1252
+ Z_SYNC_FLUSH
1253
+ Z_FULL_FLUSH
1254
+ Z_FINISH
1255
+ Z_BLOCK
1256
+
1257
+ =item :level
1258
+
1259
+ These symbolic constants are used by the C<Level> option in the constructor.
1260
+
1261
+ Z_NO_COMPRESSION
1262
+ Z_BEST_SPEED
1263
+ Z_BEST_COMPRESSION
1264
+ Z_DEFAULT_COMPRESSION
1265
+
1266
+ =item :strategy
1267
+
1268
+ These symbolic constants are used by the C<Strategy> option in the constructor.
1269
+
1270
+ Z_FILTERED
1271
+ Z_HUFFMAN_ONLY
1272
+ Z_RLE
1273
+ Z_FIXED
1274
+ Z_DEFAULT_STRATEGY
1275
+
1276
+ =back
1277
+
1278
+ =head1 EXAMPLES
1279
+
1280
+ =head2 Apache::GZip Revisited
1281
+
1282
+ See L<IO::Compress::FAQ|IO::Compress::FAQ/"Apache::GZip Revisited">
1283
+
1284
+ =head2 Working with Net::FTP
1285
+
1286
+ See L<IO::Compress::FAQ|IO::Compress::FAQ/"Compressed files and Net::FTP">
1287
+
1288
+ =head1 SUPPORT
1289
+
1290
+ General feedback/questions/bug reports should be sent to
1291
+ L<https://github.com/pmqs/IO-Copress/issues> (preferred) or
1292
+ L<https://rt.cpan.org/Public/Dist/Display.html?Name=IO-Copress>.
1293
+
1294
+ =head1 SEE ALSO
1295
+
1296
+ L<Compress::Zlib>, L<IO::Uncompress::Gunzip>, L<IO::Compress::Deflate>, L<IO::Uncompress::Inflate>, L<IO::Compress::RawDeflate>, L<IO::Uncompress::RawInflate>, L<IO::Compress::Bzip2>, L<IO::Uncompress::Bunzip2>, L<IO::Compress::Lzma>, L<IO::Uncompress::UnLzma>, L<IO::Compress::Xz>, L<IO::Uncompress::UnXz>, L<IO::Compress::Lzip>, L<IO::Uncompress::UnLzip>, L<IO::Compress::Lzop>, L<IO::Uncompress::UnLzop>, L<IO::Compress::Lzf>, L<IO::Uncompress::UnLzf>, L<IO::Compress::Zstd>, L<IO::Uncompress::UnZstd>, L<IO::Uncompress::AnyInflate>, L<IO::Uncompress::AnyUncompress>
1297
+
1298
+ L<IO::Compress::FAQ|IO::Compress::FAQ>
1299
+
1300
+ L<File::GlobMapper|File::GlobMapper>, L<Archive::Zip|Archive::Zip>,
1301
+ L<Archive::Tar|Archive::Tar>,
1302
+ L<IO::Zlib|IO::Zlib>
1303
+
1304
+ For RFC 1950, 1951 and 1952 see
1305
+ L<https://datatracker.ietf.org/doc/html/rfc1950>,
1306
+ L<https://datatracker.ietf.org/doc/html/rfc1951> and
1307
+ L<https://datatracker.ietf.org/doc/html/rfc1952>
1308
+
1309
+ The I<zlib> compression library was written by Jean-loup Gailly
1310
+ C<gzip@prep.ai.mit.edu> and Mark Adler C<madler@alumni.caltech.edu>.
1311
+
1312
+ The primary site for the I<zlib> compression library is
1313
+ L<http://www.zlib.org>.
1314
+
1315
+ The primary site for the I<zlib-ng> compression library is
1316
+ L<https://github.com/zlib-ng/zlib-ng>.
1317
+
1318
+ The primary site for gzip is L<http://www.gzip.org>.
1319
+
1320
+ =head1 AUTHOR
1321
+
1322
+ This module was written by Paul Marquess, C<pmqs@cpan.org>.
1323
+
1324
+ =head1 MODIFICATION HISTORY
1325
+
1326
+ See the Changes file.
1327
+
1328
+ =head1 COPYRIGHT AND LICENSE
1329
+
1330
+ Copyright (c) 2005-2024 Paul Marquess. All rights reserved.
1331
+
1332
+ This program is free software; you can redistribute it and/or
1333
+ modify it under the same terms as Perl itself.
git/usr/share/perl5/core_perl/IO/Compress/RawDeflate.pm ADDED
@@ -0,0 +1,1076 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package IO::Compress::RawDeflate ;
2
+
3
+ # create RFC1951
4
+ #
5
+ use strict ;
6
+ use warnings;
7
+ use bytes;
8
+
9
+ use IO::Compress::Base 2.213 ;
10
+ use IO::Compress::Base::Common 2.213 qw(:Status :Parse);
11
+ use IO::Compress::Adapter::Deflate 2.213 ;
12
+ use Compress::Raw::Zlib 2.213 qw(Z_DEFLATED Z_DEFAULT_COMPRESSION Z_DEFAULT_STRATEGY);
13
+
14
+ require Exporter ;
15
+
16
+ our ($VERSION, @ISA, @EXPORT_OK, %DEFLATE_CONSTANTS, %EXPORT_TAGS, $RawDeflateError);
17
+
18
+ $VERSION = '2.213';
19
+ $RawDeflateError = '';
20
+
21
+ @ISA = qw(IO::Compress::Base Exporter);
22
+ @EXPORT_OK = qw( $RawDeflateError rawdeflate ) ;
23
+ push @EXPORT_OK, @IO::Compress::Adapter::Deflate::EXPORT_OK ;
24
+
25
+ %EXPORT_TAGS = %IO::Compress::Adapter::Deflate::DEFLATE_CONSTANTS;
26
+
27
+
28
+ {
29
+ my %seen;
30
+ foreach (keys %EXPORT_TAGS )
31
+ {
32
+ push @{$EXPORT_TAGS{constants}},
33
+ grep { !$seen{$_}++ }
34
+ @{ $EXPORT_TAGS{$_} }
35
+ }
36
+ $EXPORT_TAGS{all} = $EXPORT_TAGS{constants} ;
37
+ }
38
+
39
+
40
+ %DEFLATE_CONSTANTS = %EXPORT_TAGS;
41
+
42
+ #push @{ $EXPORT_TAGS{all} }, @EXPORT_OK ;
43
+
44
+ Exporter::export_ok_tags('all');
45
+
46
+
47
+
48
+ sub new
49
+ {
50
+ my $class = shift ;
51
+
52
+ my $obj = IO::Compress::Base::Common::createSelfTiedObject($class, \$RawDeflateError);
53
+
54
+ return $obj->_create(undef, @_);
55
+ }
56
+
57
+ sub rawdeflate
58
+ {
59
+ my $obj = IO::Compress::Base::Common::createSelfTiedObject(undef, \$RawDeflateError);
60
+ return $obj->_def(@_);
61
+ }
62
+
63
+ sub ckParams
64
+ {
65
+ my $self = shift ;
66
+ my $got = shift;
67
+
68
+ return 1 ;
69
+ }
70
+
71
+ sub mkComp
72
+ {
73
+ my $self = shift ;
74
+ my $got = shift ;
75
+
76
+ my ($obj, $errstr, $errno) = IO::Compress::Adapter::Deflate::mkCompObject(
77
+ $got->getValue('crc32'),
78
+ $got->getValue('adler32'),
79
+ $got->getValue('level'),
80
+ $got->getValue('strategy')
81
+ );
82
+
83
+ return $self->saveErrorString(undef, $errstr, $errno)
84
+ if ! defined $obj;
85
+
86
+ return $obj;
87
+ }
88
+
89
+
90
+ sub mkHeader
91
+ {
92
+ my $self = shift ;
93
+ return '';
94
+ }
95
+
96
+ sub mkTrailer
97
+ {
98
+ my $self = shift ;
99
+ return '';
100
+ }
101
+
102
+ sub mkFinalTrailer
103
+ {
104
+ return '';
105
+ }
106
+
107
+
108
+ #sub newHeader
109
+ #{
110
+ # my $self = shift ;
111
+ # return '';
112
+ #}
113
+
114
+ sub getExtraParams
115
+ {
116
+ my $self = shift ;
117
+ return getZlibParams();
118
+ }
119
+
120
+ our %PARAMS = (
121
+ #'method' => [IO::Compress::Base::Common::Parse_unsigned, Z_DEFLATED],
122
+ 'level' => [IO::Compress::Base::Common::Parse_signed, Z_DEFAULT_COMPRESSION],
123
+ 'strategy' => [IO::Compress::Base::Common::Parse_signed, Z_DEFAULT_STRATEGY],
124
+
125
+ 'crc32' => [IO::Compress::Base::Common::Parse_boolean, 0],
126
+ 'adler32' => [IO::Compress::Base::Common::Parse_boolean, 0],
127
+ 'merge' => [IO::Compress::Base::Common::Parse_boolean, 0],
128
+ );
129
+
130
+ sub getZlibParams
131
+ {
132
+ return %PARAMS;
133
+ }
134
+
135
+ sub getInverseClass
136
+ {
137
+ no warnings 'once';
138
+ return ('IO::Uncompress::RawInflate',
139
+ \$IO::Uncompress::RawInflate::RawInflateError);
140
+ }
141
+
142
+ sub getFileInfo
143
+ {
144
+ my $self = shift ;
145
+ my $params = shift;
146
+ my $file = shift ;
147
+
148
+ }
149
+
150
+ use Fcntl qw(SEEK_SET);
151
+
152
+ sub createMerge
153
+ {
154
+ my $self = shift ;
155
+ my $outValue = shift ;
156
+ my $outType = shift ;
157
+
158
+ my ($invClass, $error_ref) = $self->getInverseClass();
159
+ eval "require $invClass"
160
+ or die "aaaahhhh" ;
161
+
162
+ my $inf = $invClass->new( $outValue,
163
+ Transparent => 0,
164
+ #Strict => 1,
165
+ AutoClose => 0,
166
+ Scan => 1)
167
+ or return $self->saveErrorString(undef, "Cannot create InflateScan object: $$error_ref" ) ;
168
+
169
+ my $end_offset = 0;
170
+ $inf->scan()
171
+ or return $self->saveErrorString(undef, "Error Scanning: $$error_ref", $inf->errorNo) ;
172
+ $inf->zap($end_offset)
173
+ or return $self->saveErrorString(undef, "Error Zapping: $$error_ref", $inf->errorNo) ;
174
+
175
+ my $def = *$self->{Compress} = $inf->createDeflate();
176
+
177
+ *$self->{Header} = *$inf->{Info}{Header};
178
+ *$self->{UnCompSize} = *$inf->{UnCompSize}->clone();
179
+ *$self->{CompSize} = *$inf->{CompSize}->clone();
180
+ # TODO -- fix this
181
+ #*$self->{CompSize} = U64->new(0, *$self->{UnCompSize_32bit});
182
+
183
+
184
+ if ( $outType eq 'buffer')
185
+ { substr( ${ *$self->{Buffer} }, $end_offset) = '' }
186
+ elsif ($outType eq 'handle' || $outType eq 'filename') {
187
+ *$self->{FH} = *$inf->{FH} ;
188
+ delete *$inf->{FH};
189
+ *$self->{FH}->flush() ;
190
+ *$self->{Handle} = 1 if $outType eq 'handle';
191
+
192
+ #seek(*$self->{FH}, $end_offset, SEEK_SET)
193
+ *$self->{FH}->seek($end_offset, SEEK_SET)
194
+ or return $self->saveErrorString(undef, $!, $!) ;
195
+ }
196
+
197
+ return $def ;
198
+ }
199
+
200
+ #### zlib specific methods
201
+
202
+ sub deflateParams
203
+ {
204
+ my $self = shift ;
205
+
206
+ my $level = shift ;
207
+ my $strategy = shift ;
208
+
209
+ my $status = *$self->{Compress}->deflateParams(Level => $level, Strategy => $strategy) ;
210
+ return $self->saveErrorString(0, *$self->{Compress}{Error}, *$self->{Compress}{ErrorNo})
211
+ if $status == STATUS_ERROR;
212
+
213
+ return 1;
214
+ }
215
+
216
+
217
+
218
+
219
+ 1;
220
+
221
+ __END__
222
+
223
+ =head1 NAME
224
+
225
+ IO::Compress::RawDeflate - Write RFC 1951 files/buffers
226
+
227
+ =head1 SYNOPSIS
228
+
229
+ use IO::Compress::RawDeflate qw(rawdeflate $RawDeflateError) ;
230
+
231
+ my $status = rawdeflate $input => $output [,OPTS]
232
+ or die "rawdeflate failed: $RawDeflateError\n";
233
+
234
+ my $z = IO::Compress::RawDeflate->new( $output [,OPTS] )
235
+ or die "rawdeflate failed: $RawDeflateError\n";
236
+
237
+ $z->print($string);
238
+ $z->printf($format, $string);
239
+ $z->write($string);
240
+ $z->syswrite($string [, $length, $offset]);
241
+ $z->flush();
242
+ $z->tell();
243
+ $z->eof();
244
+ $z->seek($position, $whence);
245
+ $z->binmode();
246
+ $z->fileno();
247
+ $z->opened();
248
+ $z->autoflush();
249
+ $z->input_line_number();
250
+ $z->newStream( [OPTS] );
251
+
252
+ $z->deflateParams();
253
+
254
+ $z->close() ;
255
+
256
+ $RawDeflateError ;
257
+
258
+ # IO::File mode
259
+
260
+ print $z $string;
261
+ printf $z $format, $string;
262
+ tell $z
263
+ eof $z
264
+ seek $z, $position, $whence
265
+ binmode $z
266
+ fileno $z
267
+ close $z ;
268
+
269
+ =head1 DESCRIPTION
270
+
271
+ This module provides a Perl interface that allows writing compressed
272
+ data to files or buffer as defined in RFC 1951.
273
+
274
+ Note that RFC 1951 data is not a good choice of compression format
275
+ to use in isolation, especially if you want to auto-detect it.
276
+
277
+ For reading RFC 1951 files/buffers, see the companion module
278
+ L<IO::Uncompress::RawInflate|IO::Uncompress::RawInflate>.
279
+
280
+ =head1 Functional Interface
281
+
282
+ A top-level function, C<rawdeflate>, is provided to carry out
283
+ "one-shot" compression between buffers and/or files. For finer
284
+ control over the compression process, see the L</"OO Interface">
285
+ section.
286
+
287
+ use IO::Compress::RawDeflate qw(rawdeflate $RawDeflateError) ;
288
+
289
+ rawdeflate $input_filename_or_reference => $output_filename_or_reference [,OPTS]
290
+ or die "rawdeflate failed: $RawDeflateError\n";
291
+
292
+ The functional interface needs Perl5.005 or better.
293
+
294
+ =head2 rawdeflate $input_filename_or_reference => $output_filename_or_reference [, OPTS]
295
+
296
+ C<rawdeflate> expects at least two parameters,
297
+ C<$input_filename_or_reference> and C<$output_filename_or_reference>
298
+ and zero or more optional parameters (see L</Optional Parameters>)
299
+
300
+ =head3 The C<$input_filename_or_reference> parameter
301
+
302
+ The parameter, C<$input_filename_or_reference>, is used to define the
303
+ source of the uncompressed data.
304
+
305
+ It can take one of the following forms:
306
+
307
+ =over 5
308
+
309
+ =item A filename
310
+
311
+ If the C<$input_filename_or_reference> parameter is a simple scalar, it is
312
+ assumed to be a filename. This file will be opened for reading and the
313
+ input data will be read from it.
314
+
315
+ =item A filehandle
316
+
317
+ If the C<$input_filename_or_reference> parameter is a filehandle, the input
318
+ data will be read from it. The string '-' can be used as an alias for
319
+ standard input.
320
+
321
+ =item A scalar reference
322
+
323
+ If C<$input_filename_or_reference> is a scalar reference, the input data
324
+ will be read from C<$$input_filename_or_reference>.
325
+
326
+ =item An array reference
327
+
328
+ If C<$input_filename_or_reference> is an array reference, each element in
329
+ the array must be a filename.
330
+
331
+ The input data will be read from each file in turn.
332
+
333
+ The complete array will be walked to ensure that it only
334
+ contains valid filenames before any data is compressed.
335
+
336
+ =item An Input FileGlob string
337
+
338
+ If C<$input_filename_or_reference> is a string that is delimited by the
339
+ characters "<" and ">" C<rawdeflate> will assume that it is an
340
+ I<input fileglob string>. The input is the list of files that match the
341
+ fileglob.
342
+
343
+ See L<File::GlobMapper|File::GlobMapper> for more details.
344
+
345
+ =back
346
+
347
+ If the C<$input_filename_or_reference> parameter is any other type,
348
+ C<undef> will be returned.
349
+
350
+ =head3 The C<$output_filename_or_reference> parameter
351
+
352
+ The parameter C<$output_filename_or_reference> is used to control the
353
+ destination of the compressed data. This parameter can take one of
354
+ these forms.
355
+
356
+ =over 5
357
+
358
+ =item A filename
359
+
360
+ If the C<$output_filename_or_reference> parameter is a simple scalar, it is
361
+ assumed to be a filename. This file will be opened for writing and the
362
+ compressed data will be written to it.
363
+
364
+ =item A filehandle
365
+
366
+ If the C<$output_filename_or_reference> parameter is a filehandle, the
367
+ compressed data will be written to it. The string '-' can be used as
368
+ an alias for standard output.
369
+
370
+ =item A scalar reference
371
+
372
+ If C<$output_filename_or_reference> is a scalar reference, the
373
+ compressed data will be stored in C<$$output_filename_or_reference>.
374
+
375
+ =item An Array Reference
376
+
377
+ If C<$output_filename_or_reference> is an array reference,
378
+ the compressed data will be pushed onto the array.
379
+
380
+ =item An Output FileGlob
381
+
382
+ If C<$output_filename_or_reference> is a string that is delimited by the
383
+ characters "<" and ">" C<rawdeflate> will assume that it is an
384
+ I<output fileglob string>. The output is the list of files that match the
385
+ fileglob.
386
+
387
+ When C<$output_filename_or_reference> is an fileglob string,
388
+ C<$input_filename_or_reference> must also be a fileglob string. Anything
389
+ else is an error.
390
+
391
+ See L<File::GlobMapper|File::GlobMapper> for more details.
392
+
393
+ =back
394
+
395
+ If the C<$output_filename_or_reference> parameter is any other type,
396
+ C<undef> will be returned.
397
+
398
+ =head2 Notes
399
+
400
+ When C<$input_filename_or_reference> maps to multiple files/buffers and
401
+ C<$output_filename_or_reference> is a single
402
+ file/buffer the input files/buffers will be stored
403
+ in C<$output_filename_or_reference> as a concatenated series of compressed data streams.
404
+
405
+ =head2 Optional Parameters
406
+
407
+ The optional parameters for the one-shot function C<rawdeflate>
408
+ are (for the most part) identical to those used with the OO interface defined in the
409
+ L</"Constructor Options"> section. The exceptions are listed below
410
+
411
+ =over 5
412
+
413
+ =item C<< AutoClose => 0|1 >>
414
+
415
+ This option applies to any input or output data streams to
416
+ C<rawdeflate> that are filehandles.
417
+
418
+ If C<AutoClose> is specified, and the value is true, it will result in all
419
+ input and/or output filehandles being closed once C<rawdeflate> has
420
+ completed.
421
+
422
+ This parameter defaults to 0.
423
+
424
+ =item C<< BinModeIn => 0|1 >>
425
+
426
+ This option is now a no-op. All files will be read in binmode.
427
+
428
+ =item C<< Append => 0|1 >>
429
+
430
+ The behaviour of this option is dependent on the type of output data
431
+ stream.
432
+
433
+ =over 5
434
+
435
+ =item * A Buffer
436
+
437
+ If C<Append> is enabled, all compressed data will be append to the end of
438
+ the output buffer. Otherwise the output buffer will be cleared before any
439
+ compressed data is written to it.
440
+
441
+ =item * A Filename
442
+
443
+ If C<Append> is enabled, the file will be opened in append mode. Otherwise
444
+ the contents of the file, if any, will be truncated before any compressed
445
+ data is written to it.
446
+
447
+ =item * A Filehandle
448
+
449
+ If C<Append> is enabled, the filehandle will be positioned to the end of
450
+ the file via a call to C<seek> before any compressed data is
451
+ written to it. Otherwise the file pointer will not be moved.
452
+
453
+ =back
454
+
455
+ When C<Append> is specified, and set to true, it will I<append> all compressed
456
+ data to the output data stream.
457
+
458
+ So when the output is a filehandle it will carry out a seek to the eof
459
+ before writing any compressed data. If the output is a filename, it will be opened for
460
+ appending. If the output is a buffer, all compressed data will be
461
+ appended to the existing buffer.
462
+
463
+ Conversely when C<Append> is not specified, or it is present and is set to
464
+ false, it will operate as follows.
465
+
466
+ When the output is a filename, it will truncate the contents of the file
467
+ before writing any compressed data. If the output is a filehandle
468
+ its position will not be changed. If the output is a buffer, it will be
469
+ wiped before any compressed data is output.
470
+
471
+ Defaults to 0.
472
+
473
+ =back
474
+
475
+ =head2 Oneshot Examples
476
+
477
+ Here are a few example that show the capabilities of the module.
478
+
479
+ =head3 Streaming
480
+
481
+ This very simple command line example demonstrates the streaming capabilities of the module.
482
+ The code reads data from STDIN, compresses it, and writes the compressed data to STDOUT.
483
+
484
+ $ echo hello world | perl -MIO::Compress::RawDeflate=rawdeflate -e 'rawdeflate \*STDIN => \*STDOUT' >output.1951
485
+
486
+ The special filename "-" can be used as a standin for both C<\*STDIN> and C<\*STDOUT>,
487
+ so the above can be rewritten as
488
+
489
+ $ echo hello world | perl -MIO::Compress::RawDeflate=rawdeflate -e 'rawdeflate "-" => "-"' >output.1951
490
+
491
+ =head3 Compressing a file from the filesystem
492
+
493
+ To read the contents of the file C<file1.txt> and write the compressed
494
+ data to the file C<file1.txt.1951>.
495
+
496
+ use strict ;
497
+ use warnings ;
498
+ use IO::Compress::RawDeflate qw(rawdeflate $RawDeflateError) ;
499
+
500
+ my $input = "file1.txt";
501
+ rawdeflate $input => "$input.1951"
502
+ or die "rawdeflate failed: $RawDeflateError\n";
503
+
504
+ =head3 Reading from a Filehandle and writing to an in-memory buffer
505
+
506
+ To read from an existing Perl filehandle, C<$input>, and write the
507
+ compressed data to a buffer, C<$buffer>.
508
+
509
+ use strict ;
510
+ use warnings ;
511
+ use IO::Compress::RawDeflate qw(rawdeflate $RawDeflateError) ;
512
+ use IO::File ;
513
+
514
+ my $input = IO::File->new( "<file1.txt" )
515
+ or die "Cannot open 'file1.txt': $!\n" ;
516
+ my $buffer ;
517
+ rawdeflate $input => \$buffer
518
+ or die "rawdeflate failed: $RawDeflateError\n";
519
+
520
+ =head3 Compressing multiple files
521
+
522
+ To compress all files in the directory "/my/home" that match "*.txt"
523
+ and store the compressed data in the same directory
524
+
525
+ use strict ;
526
+ use warnings ;
527
+ use IO::Compress::RawDeflate qw(rawdeflate $RawDeflateError) ;
528
+
529
+ rawdeflate '</my/home/*.txt>' => '<*.1951>'
530
+ or die "rawdeflate failed: $RawDeflateError\n";
531
+
532
+ and if you want to compress each file one at a time, this will do the trick
533
+
534
+ use strict ;
535
+ use warnings ;
536
+ use IO::Compress::RawDeflate qw(rawdeflate $RawDeflateError) ;
537
+
538
+ for my $input ( glob "/my/home/*.txt" )
539
+ {
540
+ my $output = "$input.1951" ;
541
+ rawdeflate $input => $output
542
+ or die "Error compressing '$input': $RawDeflateError\n";
543
+ }
544
+
545
+ =head1 OO Interface
546
+
547
+ =head2 Constructor
548
+
549
+ The format of the constructor for C<IO::Compress::RawDeflate> is shown below
550
+
551
+ my $z = IO::Compress::RawDeflate->new( $output [,OPTS] )
552
+ or die "IO::Compress::RawDeflate failed: $RawDeflateError\n";
553
+
554
+ The constructor takes one mandatory parameter, C<$output>, defined below and
555
+ zero or more C<OPTS>, defined in L<Constructor Options>.
556
+
557
+ It returns an C<IO::Compress::RawDeflate> object on success and C<undef> on failure.
558
+ The variable C<$RawDeflateError> will contain an error message on failure.
559
+
560
+ If you are running Perl 5.005 or better the object, C<$z>, returned from
561
+ IO::Compress::RawDeflate can be used exactly like an L<IO::File|IO::File> filehandle.
562
+ This means that all normal output file operations can be carried out
563
+ with C<$z>.
564
+ For example, to write to a compressed file/buffer you can use either of
565
+ these forms
566
+
567
+ $z->print("hello world\n");
568
+ print $z "hello world\n";
569
+
570
+ Below is a simple exaple of using the OO interface to create an output file
571
+ C<myfile.1951> and write some data to it.
572
+
573
+ my $filename = "myfile.1951";
574
+ my $z = IO::Compress::RawDeflate->new($filename)
575
+ or die "IO::Compress::RawDeflate failed: $RawDeflateError\n";
576
+
577
+ $z->print("abcde");
578
+ $z->close();
579
+
580
+ See the L</Examples> for more.
581
+
582
+ The mandatory parameter C<$output> is used to control the destination
583
+ of the compressed data. This parameter can take one of these forms.
584
+
585
+ =over 5
586
+
587
+ =item A filename
588
+
589
+ If the C<$output> parameter is a simple scalar, it is assumed to be a
590
+ filename. This file will be opened for writing and the compressed data
591
+ will be written to it.
592
+
593
+ =item A filehandle
594
+
595
+ If the C<$output> parameter is a filehandle, the compressed data will be
596
+ written to it.
597
+ The string '-' can be used as an alias for standard output.
598
+
599
+ =item A scalar reference
600
+
601
+ If C<$output> is a scalar reference, the compressed data will be stored
602
+ in C<$$output>.
603
+
604
+ =back
605
+
606
+ If the C<$output> parameter is any other type, C<IO::Compress::RawDeflate>::new will
607
+ return undef.
608
+
609
+ =head2 Constructor Options
610
+
611
+ C<OPTS> is any combination of zero or more the following options:
612
+
613
+ =over 5
614
+
615
+ =item C<< AutoClose => 0|1 >>
616
+
617
+ This option is only valid when the C<$output> parameter is a filehandle. If
618
+ specified, and the value is true, it will result in the C<$output> being
619
+ closed once either the C<close> method is called or the C<IO::Compress::RawDeflate>
620
+ object is destroyed.
621
+
622
+ This parameter defaults to 0.
623
+
624
+ =item C<< Append => 0|1 >>
625
+
626
+ Opens C<$output> in append mode.
627
+
628
+ The behaviour of this option is dependent on the type of C<$output>.
629
+
630
+ =over 5
631
+
632
+ =item * A Buffer
633
+
634
+ If C<$output> is a buffer and C<Append> is enabled, all compressed data
635
+ will be append to the end of C<$output>. Otherwise C<$output> will be
636
+ cleared before any data is written to it.
637
+
638
+ =item * A Filename
639
+
640
+ If C<$output> is a filename and C<Append> is enabled, the file will be
641
+ opened in append mode. Otherwise the contents of the file, if any, will be
642
+ truncated before any compressed data is written to it.
643
+
644
+ =item * A Filehandle
645
+
646
+ If C<$output> is a filehandle, the file pointer will be positioned to the
647
+ end of the file via a call to C<seek> before any compressed data is written
648
+ to it. Otherwise the file pointer will not be moved.
649
+
650
+ =back
651
+
652
+ This parameter defaults to 0.
653
+
654
+ =item C<< Merge => 0|1 >>
655
+
656
+ This option is used to compress input data and append it to an existing
657
+ compressed data stream in C<$output>. The end result is a single compressed
658
+ data stream stored in C<$output>.
659
+
660
+ It is a fatal error to attempt to use this option when C<$output> is not an
661
+ RFC 1951 data stream.
662
+
663
+ There are a number of other limitations with the C<Merge> option:
664
+
665
+ =over 5
666
+
667
+ =item 1
668
+
669
+ This module needs to have been built with zlib 1.2.1 or better to work. A
670
+ fatal error will be thrown if C<Merge> is used with an older version of
671
+ zlib.
672
+
673
+ =item 2
674
+
675
+ If C<$output> is a file or a filehandle, it must be seekable.
676
+
677
+ =back
678
+
679
+ This parameter defaults to 0.
680
+
681
+ =item -Level
682
+
683
+ Defines the compression level used by zlib. The value should either be
684
+ a number between 0 and 9 (0 means no compression and 9 is maximum
685
+ compression), or one of the symbolic constants defined below.
686
+
687
+ Z_NO_COMPRESSION
688
+ Z_BEST_SPEED
689
+ Z_BEST_COMPRESSION
690
+ Z_DEFAULT_COMPRESSION
691
+
692
+ The default is Z_DEFAULT_COMPRESSION.
693
+
694
+ Note, these constants are not imported by C<IO::Compress::RawDeflate> by default.
695
+
696
+ use IO::Compress::RawDeflate qw(:strategy);
697
+ use IO::Compress::RawDeflate qw(:constants);
698
+ use IO::Compress::RawDeflate qw(:all);
699
+
700
+ =item -Strategy
701
+
702
+ Defines the strategy used to tune the compression. Use one of the symbolic
703
+ constants defined below.
704
+
705
+ Z_FILTERED
706
+ Z_HUFFMAN_ONLY
707
+ Z_RLE
708
+ Z_FIXED
709
+ Z_DEFAULT_STRATEGY
710
+
711
+ The default is Z_DEFAULT_STRATEGY.
712
+
713
+ =item C<< Strict => 0|1 >>
714
+
715
+ This is a placeholder option.
716
+
717
+ =back
718
+
719
+ =head2 Examples
720
+
721
+ =head3 Streaming
722
+
723
+ This very simple command line example demonstrates the streaming capabilities
724
+ of the module. The code reads data from STDIN or all the files given on the
725
+ commandline, compresses it, and writes the compressed data to STDOUT.
726
+
727
+ use strict ;
728
+ use warnings ;
729
+ use IO::Compress::RawDeflate qw(rawdeflate $RawDeflateError) ;
730
+
731
+ my $z = IO::Compress::RawDeflate->new("-", Stream => 1)
732
+ or die "IO::Compress::RawDeflate failed: $RawDeflateError\n";
733
+
734
+ while (<>) {
735
+ $z->print("abcde");
736
+ }
737
+ $z->close();
738
+
739
+ Note the use of C<"-"> to means C<STDOUT>. Alternatively you can use C<\*STDOUT>.
740
+
741
+ =head3 Compressing a file from the filesystem
742
+
743
+ To read the contents of the file C<file1.txt> and write the compressed
744
+ data to the file C<file1.txt.1951> there are a few options
745
+
746
+ Start by creating the compression object and opening the input file
747
+
748
+ use strict ;
749
+ use warnings ;
750
+ use IO::Compress::RawDeflate qw(rawdeflate $RawDeflateError) ;
751
+
752
+ my $input = "file1.txt";
753
+ my $z = IO::Compress::RawDeflate->new("file1.txt.1951")
754
+ or die "IO::Compress::RawDeflate failed: $RawDeflateError\n";
755
+
756
+ # open the input file
757
+ open my $fh, "<", "file1.txt"
758
+ or die "Cannot open file1.txt: $!\n";
759
+
760
+ # loop through the input file & write to the compressed file
761
+ while (<$fh>) {
762
+ $z->print($_);
763
+ }
764
+
765
+ # not forgetting to close the compressed file
766
+ $z->close();
767
+
768
+ =head1 Methods
769
+
770
+ =head2 print
771
+
772
+ Usage is
773
+
774
+ $z->print($data)
775
+ print $z $data
776
+
777
+ Compresses and outputs the contents of the C<$data> parameter. This
778
+ has the same behaviour as the C<print> built-in.
779
+
780
+ Returns true if successful.
781
+
782
+ =head2 printf
783
+
784
+ Usage is
785
+
786
+ $z->printf($format, $data)
787
+ printf $z $format, $data
788
+
789
+ Compresses and outputs the contents of the C<$data> parameter.
790
+
791
+ Returns true if successful.
792
+
793
+ =head2 syswrite
794
+
795
+ Usage is
796
+
797
+ $z->syswrite $data
798
+ $z->syswrite $data, $length
799
+ $z->syswrite $data, $length, $offset
800
+
801
+ Compresses and outputs the contents of the C<$data> parameter.
802
+
803
+ Returns the number of uncompressed bytes written, or C<undef> if
804
+ unsuccessful.
805
+
806
+ =head2 write
807
+
808
+ Usage is
809
+
810
+ $z->write $data
811
+ $z->write $data, $length
812
+ $z->write $data, $length, $offset
813
+
814
+ Compresses and outputs the contents of the C<$data> parameter.
815
+
816
+ Returns the number of uncompressed bytes written, or C<undef> if
817
+ unsuccessful.
818
+
819
+ =head2 flush
820
+
821
+ Usage is
822
+
823
+ $z->flush;
824
+ $z->flush($flush_type);
825
+
826
+ Flushes any pending compressed data to the output file/buffer.
827
+
828
+ This method takes an optional parameter, C<$flush_type>, that controls
829
+ how the flushing will be carried out. By default the C<$flush_type>
830
+ used is C<Z_FINISH>. Other valid values for C<$flush_type> are
831
+ C<Z_NO_FLUSH>, C<Z_SYNC_FLUSH>, C<Z_FULL_FLUSH> and C<Z_BLOCK>. It is
832
+ strongly recommended that you only set the C<flush_type> parameter if
833
+ you fully understand the implications of what it does - overuse of C<flush>
834
+ can seriously degrade the level of compression achieved. See the C<zlib>
835
+ documentation for details.
836
+
837
+ Returns true on success.
838
+
839
+ =head2 tell
840
+
841
+ Usage is
842
+
843
+ $z->tell()
844
+ tell $z
845
+
846
+ Returns the uncompressed file offset.
847
+
848
+ =head2 eof
849
+
850
+ Usage is
851
+
852
+ $z->eof();
853
+ eof($z);
854
+
855
+ Returns true if the C<close> method has been called.
856
+
857
+ =head2 seek
858
+
859
+ $z->seek($position, $whence);
860
+ seek($z, $position, $whence);
861
+
862
+ Provides a sub-set of the C<seek> functionality, with the restriction
863
+ that it is only legal to seek forward in the output file/buffer.
864
+ It is a fatal error to attempt to seek backward.
865
+
866
+ Empty parts of the file/buffer will have NULL (0x00) bytes written to them.
867
+
868
+ The C<$whence> parameter takes one the usual values, namely SEEK_SET,
869
+ SEEK_CUR or SEEK_END.
870
+
871
+ Returns 1 on success, 0 on failure.
872
+
873
+ =head2 binmode
874
+
875
+ Usage is
876
+
877
+ $z->binmode
878
+ binmode $z ;
879
+
880
+ This is a noop provided for completeness.
881
+
882
+ =head2 opened
883
+
884
+ $z->opened()
885
+
886
+ Returns true if the object currently refers to a opened file/buffer.
887
+
888
+ =head2 autoflush
889
+
890
+ my $prev = $z->autoflush()
891
+ my $prev = $z->autoflush(EXPR)
892
+
893
+ If the C<$z> object is associated with a file or a filehandle, this method
894
+ returns the current autoflush setting for the underlying filehandle. If
895
+ C<EXPR> is present, and is non-zero, it will enable flushing after every
896
+ write/print operation.
897
+
898
+ If C<$z> is associated with a buffer, this method has no effect and always
899
+ returns C<undef>.
900
+
901
+ B<Note> that the special variable C<$|> B<cannot> be used to set or
902
+ retrieve the autoflush setting.
903
+
904
+ =head2 input_line_number
905
+
906
+ $z->input_line_number()
907
+ $z->input_line_number(EXPR)
908
+
909
+ This method always returns C<undef> when compressing.
910
+
911
+ =head2 fileno
912
+
913
+ $z->fileno()
914
+ fileno($z)
915
+
916
+ If the C<$z> object is associated with a file or a filehandle, C<fileno>
917
+ will return the underlying file descriptor. Once the C<close> method is
918
+ called C<fileno> will return C<undef>.
919
+
920
+ If the C<$z> object is associated with a buffer, this method will return
921
+ C<undef>.
922
+
923
+ =head2 close
924
+
925
+ $z->close() ;
926
+ close $z ;
927
+
928
+ Flushes any pending compressed data and then closes the output file/buffer.
929
+
930
+ For most versions of Perl this method will be automatically invoked if
931
+ the IO::Compress::RawDeflate object is destroyed (either explicitly or by the
932
+ variable with the reference to the object going out of scope). The
933
+ exceptions are Perl versions 5.005 through 5.00504 and 5.8.0. In
934
+ these cases, the C<close> method will be called automatically, but
935
+ not until global destruction of all live objects when the program is
936
+ terminating.
937
+
938
+ Therefore, if you want your scripts to be able to run on all versions
939
+ of Perl, you should call C<close> explicitly and not rely on automatic
940
+ closing.
941
+
942
+ Returns true on success, otherwise 0.
943
+
944
+ If the C<AutoClose> option has been enabled when the IO::Compress::RawDeflate
945
+ object was created, and the object is associated with a file, the
946
+ underlying file will also be closed.
947
+
948
+ =head2 newStream([OPTS])
949
+
950
+ Usage is
951
+
952
+ $z->newStream( [OPTS] )
953
+
954
+ Closes the current compressed data stream and starts a new one.
955
+
956
+ OPTS consists of any of the options that are available when creating
957
+ the C<$z> object.
958
+
959
+ See the L</"Constructor Options"> section for more details.
960
+
961
+ =head2 deflateParams
962
+
963
+ Usage is
964
+
965
+ $z->deflateParams
966
+
967
+ TODO
968
+
969
+ =head1 Importing
970
+
971
+ A number of symbolic constants are required by some methods in
972
+ C<IO::Compress::RawDeflate>. None are imported by default.
973
+
974
+ =over 5
975
+
976
+ =item :all
977
+
978
+ Imports C<rawdeflate>, C<$RawDeflateError> and all symbolic
979
+ constants that can be used by C<IO::Compress::RawDeflate>. Same as doing this
980
+
981
+ use IO::Compress::RawDeflate qw(rawdeflate $RawDeflateError :constants) ;
982
+
983
+ =item :constants
984
+
985
+ Import all symbolic constants. Same as doing this
986
+
987
+ use IO::Compress::RawDeflate qw(:flush :level :strategy) ;
988
+
989
+ =item :flush
990
+
991
+ These symbolic constants are used by the C<flush> method.
992
+
993
+ Z_NO_FLUSH
994
+ Z_PARTIAL_FLUSH
995
+ Z_SYNC_FLUSH
996
+ Z_FULL_FLUSH
997
+ Z_FINISH
998
+ Z_BLOCK
999
+
1000
+ =item :level
1001
+
1002
+ These symbolic constants are used by the C<Level> option in the constructor.
1003
+
1004
+ Z_NO_COMPRESSION
1005
+ Z_BEST_SPEED
1006
+ Z_BEST_COMPRESSION
1007
+ Z_DEFAULT_COMPRESSION
1008
+
1009
+ =item :strategy
1010
+
1011
+ These symbolic constants are used by the C<Strategy> option in the constructor.
1012
+
1013
+ Z_FILTERED
1014
+ Z_HUFFMAN_ONLY
1015
+ Z_RLE
1016
+ Z_FIXED
1017
+ Z_DEFAULT_STRATEGY
1018
+
1019
+ =back
1020
+
1021
+ =head1 EXAMPLES
1022
+
1023
+ =head2 Apache::GZip Revisited
1024
+
1025
+ See L<IO::Compress::FAQ|IO::Compress::FAQ/"Apache::GZip Revisited">
1026
+
1027
+ =head2 Working with Net::FTP
1028
+
1029
+ See L<IO::Compress::FAQ|IO::Compress::FAQ/"Compressed files and Net::FTP">
1030
+
1031
+ =head1 SUPPORT
1032
+
1033
+ General feedback/questions/bug reports should be sent to
1034
+ L<https://github.com/pmqs/IO-Compress/issues> (preferred) or
1035
+ L<https://rt.cpan.org/Public/Dist/Display.html?Name=IO-Compress>.
1036
+
1037
+ =head1 SEE ALSO
1038
+
1039
+ L<Compress::Zlib>, L<IO::Compress::Gzip>, L<IO::Uncompress::Gunzip>, L<IO::Compress::Deflate>, L<IO::Uncompress::Inflate>, L<IO::Uncompress::RawInflate>, L<IO::Compress::Bzip2>, L<IO::Uncompress::Bunzip2>, L<IO::Compress::Lzma>, L<IO::Uncompress::UnLzma>, L<IO::Compress::Xz>, L<IO::Uncompress::UnXz>, L<IO::Compress::Lzip>, L<IO::Uncompress::UnLzip>, L<IO::Compress::Lzop>, L<IO::Uncompress::UnLzop>, L<IO::Compress::Lzf>, L<IO::Uncompress::UnLzf>, L<IO::Compress::Zstd>, L<IO::Uncompress::UnZstd>, L<IO::Uncompress::AnyInflate>, L<IO::Uncompress::AnyUncompress>
1040
+
1041
+ L<IO::Compress::FAQ|IO::Compress::FAQ>
1042
+
1043
+ L<File::GlobMapper|File::GlobMapper>, L<Archive::Zip|Archive::Zip>,
1044
+ L<Archive::Tar|Archive::Tar>,
1045
+ L<IO::Zlib|IO::Zlib>
1046
+
1047
+ For RFC 1950, 1951 and 1952 see
1048
+ L<https://datatracker.ietf.org/doc/html/rfc1950>,
1049
+ L<https://datatracker.ietf.org/doc/html/rfc1951> and
1050
+ L<https://datatracker.ietf.org/doc/html/rfc1952>
1051
+
1052
+ The I<zlib> compression library was written by Jean-loup Gailly
1053
+ C<gzip@prep.ai.mit.edu> and Mark Adler C<madler@alumni.caltech.edu>.
1054
+
1055
+ The primary site for the I<zlib> compression library is
1056
+ L<http://www.zlib.org>.
1057
+
1058
+ The primary site for the I<zlib-ng> compression library is
1059
+ L<https://github.com/zlib-ng/zlib-ng>.
1060
+
1061
+ The primary site for gzip is L<http://www.gzip.org>.
1062
+
1063
+ =head1 AUTHOR
1064
+
1065
+ This module was written by Paul Marquess, C<pmqs@cpan.org>.
1066
+
1067
+ =head1 MODIFICATION HISTORY
1068
+
1069
+ See the Changes file.
1070
+
1071
+ =head1 COPYRIGHT AND LICENSE
1072
+
1073
+ Copyright (c) 2005-2024 Paul Marquess. All rights reserved.
1074
+
1075
+ This program is free software; you can redistribute it and/or
1076
+ modify it under the same terms as Perl itself.
git/usr/share/perl5/core_perl/JSON/PP/Boolean.pm ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package JSON::PP::Boolean;
2
+
3
+ use strict;
4
+ use warnings;
5
+ use overload ();
6
+ overload::unimport('overload', qw(0+ ++ -- fallback));
7
+ overload::import('overload',
8
+ "0+" => sub { ${$_[0]} },
9
+ "++" => sub { $_[0] = ${$_[0]} + 1 },
10
+ "--" => sub { $_[0] = ${$_[0]} - 1 },
11
+ fallback => 1,
12
+ );
13
+
14
+ our $VERSION = '4.16';
15
+
16
+ 1;
17
+
18
+ __END__
19
+
20
+ =head1 NAME
21
+
22
+ JSON::PP::Boolean - dummy module providing JSON::PP::Boolean
23
+
24
+ =head1 SYNOPSIS
25
+
26
+ # do not "use" yourself
27
+
28
+ =head1 DESCRIPTION
29
+
30
+ This module exists only to provide overload resolution for Storable and similar modules. See
31
+ L<JSON::PP> for more info about this class.
32
+
33
+ =head1 AUTHOR
34
+
35
+ This idea is from L<JSON::XS::Boolean> written by Marc Lehmann <schmorp[at]schmorp.de>
36
+
37
+ =head1 LICENSE
38
+
39
+ This library is free software; you can redistribute it and/or modify
40
+ it under the same terms as Perl itself.
41
+
42
+ =cut
43
+
git/usr/share/perl5/core_perl/Math/BigFloat/Trace.pm ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- mode: perl; -*-
2
+
3
+ package Math::BigFloat::Trace;
4
+
5
+ use strict;
6
+ use warnings;
7
+
8
+ use Exporter;
9
+ use Math::BigFloat;
10
+
11
+ our @ISA = qw(Exporter Math::BigFloat);
12
+
13
+ our $VERSION = '0.67';
14
+
15
+ use overload; # inherit overload from Math::BigFloat
16
+
17
+ # Globals
18
+ our $accuracy = undef;
19
+ our $precision = undef;
20
+ our $round_mode = 'even';
21
+ our $div_scale = 40;
22
+
23
+ sub new {
24
+ my $proto = shift;
25
+ my $class = ref($proto) || $proto;
26
+
27
+ my $value = shift;
28
+
29
+ my $a = $accuracy;
30
+ $a = $_[0] if defined $_[0];
31
+
32
+ my $p = $precision;
33
+ $p = $_[1] if defined $_[1];
34
+
35
+ my $self = $class -> SUPER::new($value, $a, $p, $round_mode);
36
+
37
+ printf "Math::BigFloat new '%s' => '%s' (%s)\n",
38
+ $value, $self, ref($self);
39
+
40
+ return $self;
41
+ }
42
+
43
+ sub import {
44
+ my $class = shift;
45
+
46
+ printf "%s -> import(%s)\n", $class, join(", ", @_);
47
+
48
+ # we catch the constants, the rest goes to parent
49
+
50
+ my $constant = grep { $_ eq ':constant' } @_;
51
+ my @a = grep { $_ ne ':constant' } @_;
52
+
53
+ if ($constant) {
54
+ overload::constant
55
+
56
+ integer => sub {
57
+ $class -> new(shift);
58
+ },
59
+
60
+ float => sub {
61
+ $class -> new(shift);
62
+ },
63
+
64
+ binary => sub {
65
+ # E.g., a literal 0377 shall result in an object whose value
66
+ # is decimal 255, but new("0377") returns decimal 377.
67
+ return $class -> from_oct($_[0]) if $_[0] =~ /^0_*[0-7]/;
68
+ $class -> new(shift);
69
+ };
70
+ }
71
+
72
+ $class -> SUPER::import(@a); # need it for subclasses
73
+ #$self -> export_to_level(1, $class, @_); # need this ?
74
+ }
75
+
76
+ 1;
git/usr/share/perl5/core_perl/Math/BigInt/Calc.pm ADDED
@@ -0,0 +1,2613 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package Math::BigInt::Calc;
2
+
3
+ use 5.006001;
4
+ use strict;
5
+ use warnings;
6
+
7
+ use Carp qw< carp croak >;
8
+ use Math::BigInt::Lib;
9
+
10
+ our $VERSION = '2.005002';
11
+ $VERSION =~ tr/_//d;
12
+
13
+ our @ISA = ('Math::BigInt::Lib');
14
+
15
+ # Package to store unsigned big integers in decimal and do math with them
16
+ #
17
+ # Internally the numbers are stored in an array with at least 1 element, no
18
+ # leading zero parts (except the first) and in base 1eX where X is determined
19
+ # automatically at loading time to be the maximum possible value
20
+ #
21
+ # todo:
22
+ # - fully remove funky $# stuff in div() (maybe - that code scares me...)
23
+
24
+ ##############################################################################
25
+ # global constants, flags and accessory
26
+
27
+ # constants for easier life
28
+
29
+ my $MAX_EXP_F; # the maximum possible base 10 exponent with "no integer"
30
+ my $MAX_EXP_I; # the maximum possible base 10 exponent with "use integer"
31
+
32
+ my $MAX_BITS; # the maximum possible number of bits for $AND_BITS etc.
33
+
34
+ my $BASE_LEN; # the current base exponent in use
35
+ my $USE_INT; # whether "use integer" is used in the computations
36
+
37
+ my $BASE; # the current base, e.g., 10000 if $BASE_LEN is 5
38
+ my $MAX_VAL; # maximum value for an element, i.e., $BASE - 1
39
+
40
+ my $AND_BITS; # maximum value used in binary and, e.g., 0xffff
41
+ my $OR_BITS; # ditto for binary or
42
+ my $XOR_BITS; # ditto for binary xor
43
+
44
+ my $AND_MASK; # $AND_BITS + 1, e.g., 0x10000 if $AND_BITS is 0xffff
45
+ my $OR_MASK; # ditto for binary or
46
+ my $XOR_MASK; # ditto for binary xor
47
+
48
+ sub config {
49
+ my $self = shift;
50
+
51
+ croak "Missing input argument" unless @_;
52
+
53
+ # Called as a getter.
54
+
55
+ if (@_ == 1) {
56
+ my $param = shift;
57
+ croak "Parameter name must be a non-empty string"
58
+ unless defined $param && length $param;
59
+ return $BASE_LEN if $param eq 'base_len';
60
+ return $USE_INT if $param eq 'use_int';
61
+ croak "Unknown parameter '$param'";
62
+ }
63
+
64
+ # Called as a setter.
65
+
66
+ my $opts;
67
+ while (@_) {
68
+ my $param = shift;
69
+ croak "Parameter name must be a non-empty string"
70
+ unless defined $param && length $param;
71
+ croak "Missing value for parameter '$param'"
72
+ unless @_;
73
+ my $value = shift;
74
+
75
+ if ($param eq 'base_len' || $param eq 'use_int') {
76
+ $opts -> {$param} = $value;
77
+ next;
78
+ }
79
+
80
+ croak "Unknown parameter '$param'";
81
+ }
82
+
83
+ $BASE_LEN = $opts -> {base_len} if exists $opts -> {base_len};
84
+ $USE_INT = $opts -> {use_int} if exists $opts -> {use_int};
85
+ __PACKAGE__ -> _base_len($BASE_LEN, $USE_INT);
86
+
87
+ return $self;
88
+ }
89
+
90
+ sub _base_len {
91
+ #my $class = shift; # $class is not used
92
+ shift;
93
+
94
+ if (@_) { # if called as setter ...
95
+ my ($base_len, $use_int) = @_;
96
+
97
+ croak "The base length must be a positive integer"
98
+ unless defined($base_len) && $base_len == int($base_len)
99
+ && $base_len > 0;
100
+
101
+ if ( $use_int && ($base_len > $MAX_EXP_I) ||
102
+ !$use_int && ($base_len > $MAX_EXP_F))
103
+ {
104
+ croak "The maximum base length (exponent) is $MAX_EXP_I with",
105
+ " 'use integer' and $MAX_EXP_F without 'use integer'. The",
106
+ " requested settings, a base length of $base_len ",
107
+ $use_int ? "with" : "without", " 'use integer', is invalid.";
108
+ }
109
+
110
+ $BASE_LEN = $base_len;
111
+ $BASE = 0 + ("1" . ("0" x $BASE_LEN));
112
+ $MAX_VAL = $BASE - 1;
113
+ $USE_INT = $use_int ? 1 : 0;
114
+
115
+ {
116
+ no warnings "redefine";
117
+ if ($use_int) {
118
+ *_mul = \&_mul_use_int;
119
+ *_div = \&_div_use_int;
120
+ } else {
121
+ *_mul = \&_mul_no_int;
122
+ *_div = \&_div_no_int;
123
+ }
124
+ }
125
+ }
126
+
127
+ # Find max bits. This is the largest power of two that is both no larger
128
+ # than $BASE and no larger than the maximum integer (i.e., ~0). We need
129
+ # this limitation because _and(), _or(), and _xor() only work on one
130
+ # element at a time.
131
+
132
+ my $umax = ~0; # largest unsigned integer
133
+ my $tmp = $umax < $BASE ? $umax : $BASE;
134
+
135
+ $MAX_BITS = 0;
136
+ while ($tmp >>= 1) {
137
+ $MAX_BITS++;
138
+ }
139
+
140
+ # Limit to 32 bits for portability. Is this really necessary? XXX
141
+
142
+ $MAX_BITS = 32 if $MAX_BITS > 32;
143
+
144
+ # Find out how many bits _and, _or and _xor can take (old default = 16).
145
+ # Are these tests really necessary? Can't we just use $MAX_BITS? XXX
146
+
147
+ for ($AND_BITS = $MAX_BITS ; $AND_BITS > 0 ; $AND_BITS--) {
148
+ my $x = CORE::oct('0b' . '1' x $AND_BITS);
149
+ my $y = $x & $x;
150
+ my $z = 2 * (2 ** ($AND_BITS - 1)) + 1;
151
+ last unless $AND_BITS < $MAX_BITS && $x == $z && $y == $x;
152
+ }
153
+
154
+ for ($XOR_BITS = $MAX_BITS ; $XOR_BITS > 0 ; $XOR_BITS--) {
155
+ my $x = CORE::oct('0b' . '1' x $XOR_BITS);
156
+ my $y = $x ^ $x;
157
+ my $z = 2 * (2 ** ($XOR_BITS - 1)) + 1;
158
+ last unless $XOR_BITS < $MAX_BITS && $x == $z && $y == $x;
159
+ }
160
+
161
+ for ($OR_BITS = $MAX_BITS ; $OR_BITS > 0 ; $OR_BITS--) {
162
+ my $x = CORE::oct('0b' . '1' x $OR_BITS);
163
+ my $y = $x | $x;
164
+ my $z = 2 * (2 ** ($OR_BITS - 1)) + 1;
165
+ last unless $OR_BITS < $MAX_BITS && $x == $z && $y == $x;
166
+ }
167
+
168
+ $AND_MASK = __PACKAGE__->_new(( 2 ** $AND_BITS ));
169
+ $XOR_MASK = __PACKAGE__->_new(( 2 ** $XOR_BITS ));
170
+ $OR_MASK = __PACKAGE__->_new(( 2 ** $OR_BITS ));
171
+
172
+ return $BASE_LEN unless wantarray;
173
+ return ($BASE_LEN, $BASE, $AND_BITS, $XOR_BITS, $OR_BITS, $BASE_LEN, $MAX_VAL,
174
+ $MAX_BITS, $MAX_EXP_F, $MAX_EXP_I, $USE_INT);
175
+ }
176
+
177
+ sub _new {
178
+ # Given a string representing an integer, returns a reference to an array
179
+ # of integers, where each integer represents a chunk of the original input
180
+ # integer.
181
+
182
+ my ($class, $str) = @_;
183
+ #unless ($str =~ /^([1-9]\d*|0)\z/) {
184
+ # croak("Invalid input string '$str'");
185
+ #}
186
+
187
+ my $input_len = length($str) - 1;
188
+
189
+ # Shortcut for small numbers.
190
+ return bless [ $str ], $class if $input_len < $BASE_LEN;
191
+
192
+ my $format = "a" . (($input_len % $BASE_LEN) + 1);
193
+ $format .= $] < 5.008 ? "a$BASE_LEN" x int($input_len / $BASE_LEN)
194
+ : "(a$BASE_LEN)*";
195
+
196
+ my $self = [ reverse(map { 0 + $_ } unpack($format, $str)) ];
197
+ return bless $self, $class;
198
+ }
199
+
200
+ BEGIN {
201
+
202
+ # Compute $MAX_EXP_F, the maximum usable base 10 exponent.
203
+
204
+ # The largest element in base 10**$BASE_LEN is 10**$BASE_LEN-1. For instance,
205
+ # with $BASE_LEN = 5, the largest element is 99_999, and the largest carry is
206
+ #
207
+ # int( 99_999 * 99_999 / 100_000 ) = 99_998
208
+ #
209
+ # so make sure that 99_999 * 99_999 + 99_998 is within the range of integers
210
+ # that can be represented accuratly.
211
+ #
212
+ # Note that on some systems with quadmath support, the following is within
213
+ # the range of numbers that can be represented exactly, but it still gives
214
+ # the incorrect value $r = 2 (even though POSIX::fmod($x, $y) gives the
215
+ # correct value of 1:
216
+ #
217
+ # $x = 99999999999999999;
218
+ # $y = 100000000000000000;
219
+ # $r = $x * $x % $y; # should be 1
220
+ #
221
+ # so also check for this.
222
+
223
+ for ($MAX_EXP_F = 1 ; ; $MAX_EXP_F++) { # when $MAX_EXP_F = 5
224
+ my $MAX_EXP_FM1 = $MAX_EXP_F - 1; # = 4
225
+ my $bs = "1" . ("0" x $MAX_EXP_F); # = "100000"
226
+ my $xs = "9" x $MAX_EXP_F; # = "99999"
227
+ my $cs = ("9" x $MAX_EXP_FM1) . "8"; # = "99998"
228
+ my $ys = $cs . ("0" x $MAX_EXP_FM1) . "1"; # = "9999800001"
229
+
230
+ # Compute and check the product.
231
+ my $yn = $xs * $xs; # = 9999800001
232
+ last if $yn != $ys;
233
+
234
+ # Compute and check the remainder.
235
+ my $rn = $yn % $bs; # = 1
236
+ last if $rn != 1;
237
+
238
+ # Compute and check the carry. The division here is exact.
239
+ my $cn = ($yn - $rn) / $bs; # = 99998
240
+ last if $cn != $cs;
241
+
242
+ # Compute and check product plus carry.
243
+ my $zs = $cs . ("9" x $MAX_EXP_F); # = "9999899999"
244
+ my $zn = $yn + $cn; # = 99998999999
245
+ last if $zn != $zs;
246
+ last if $zn - ($zn - 1) != 1;
247
+ }
248
+ $MAX_EXP_F--; # last test failed, so retract one step
249
+
250
+ # Compute $MAX_EXP_I, the maximum usable base 10 exponent within the range
251
+ # of what is available with "use integer". On older versions of Perl,
252
+ # integers are converted to floating point numbers, even though they are
253
+ # within the range of what can be represented as integers. For example, on
254
+ # some 64 bit Perls, 999999999 * 999999999 becomes 999999998000000000, not
255
+ # 999999998000000001, even though the latter is less than the maximum value
256
+ # for a 64 bit integer, 18446744073709551615.
257
+
258
+ my $umax = ~0; # largest unsigned integer
259
+ for ($MAX_EXP_I = int(0.5 * log($umax) / log(10));
260
+ $MAX_EXP_I > 0;
261
+ $MAX_EXP_I--)
262
+ { # when $MAX_EXP_I = 5
263
+ my $MAX_EXP_IM1 = $MAX_EXP_I - 1; # = 4
264
+ my $bs = "1" . ("0" x $MAX_EXP_I); # = "100000"
265
+ my $xs = "9" x $MAX_EXP_I; # = "99999"
266
+ my $cs = ("9" x $MAX_EXP_IM1) . "8"; # = "99998"
267
+ my $ys = $cs . ("0" x $MAX_EXP_IM1) . "1"; # = "9999800001"
268
+
269
+ # Compute and check the product.
270
+ my $yn = $xs * $xs; # = 9999800001
271
+ next if $yn != $ys;
272
+
273
+ # Compute and check the remainder.
274
+ my $rn = $yn % $bs; # = 1
275
+ next if $rn != 1;
276
+
277
+ # Compute and check the carry. The division here is exact.
278
+ my $cn = ($yn - $rn) / $bs; # = 99998
279
+ next if $cn != $cs;
280
+
281
+ # Compute and check product plus carry.
282
+ my $zs = $cs . ("9" x $MAX_EXP_I); # = "9999899999"
283
+ my $zn = $yn + $cn; # = 99998999999
284
+ next if $zn != $zs;
285
+ next if $zn - ($zn - 1) != 1;
286
+ last;
287
+ }
288
+
289
+ ($BASE_LEN, $USE_INT) = $MAX_EXP_F > $MAX_EXP_I
290
+ ? ($MAX_EXP_F, 0) : ($MAX_EXP_I, 1);
291
+
292
+ __PACKAGE__ -> _base_len($BASE_LEN, $USE_INT);
293
+ }
294
+
295
+ ###############################################################################
296
+
297
+ sub _zero {
298
+ # create a zero
299
+ my $class = shift;
300
+ return bless [ 0 ], $class;
301
+ }
302
+
303
+ sub _one {
304
+ # create a one
305
+ my $class = shift;
306
+ return bless [ 1 ], $class;
307
+ }
308
+
309
+ sub _two {
310
+ # create a two
311
+ my $class = shift;
312
+ return bless [ 2 ], $class;
313
+ }
314
+
315
+ sub _ten {
316
+ # create a 10
317
+ my $class = shift;
318
+ my $self = $BASE_LEN == 1 ? [ 0, 1 ] : [ 10 ];
319
+ bless $self, $class;
320
+ }
321
+
322
+ sub _1ex {
323
+ # create a 1Ex
324
+ my $class = shift;
325
+
326
+ my $rem = $_[0] % $BASE_LEN; # remainder
327
+ my $div = ($_[0] - $rem) / $BASE_LEN; # parts
328
+
329
+ # With a $BASE_LEN of 6, 1e14 becomes
330
+ # [ 000000, 000000, 100 ] -> [ 0, 0, 100 ]
331
+ bless [ (0) x $div, 0 + ("1" . ("0" x $rem)) ], $class;
332
+ }
333
+
334
+ sub _copy {
335
+ # make a true copy
336
+ my $class = shift;
337
+ return bless [ @{ $_[0] } ], $class;
338
+ }
339
+
340
+ sub import {
341
+ my $self = shift;
342
+
343
+ my $opts;
344
+ my ($base_len, $use_int);
345
+ while (@_) {
346
+ my $param = shift;
347
+ croak "Parameter name must be a non-empty string"
348
+ unless defined $param && length $param;
349
+ croak "Missing value for parameter '$param'"
350
+ unless @_;
351
+ my $value = shift;
352
+
353
+ if ($param eq 'base_len' || $param eq 'use_int') {
354
+ $opts -> {$param} = $value;
355
+ next;
356
+ }
357
+
358
+ croak "Unknown parameter '$param'";
359
+ }
360
+
361
+ $base_len = exists $opts -> {base_len} ? $opts -> {base_len} : $BASE_LEN;
362
+ $use_int = exists $opts -> {use_int} ? $opts -> {use_int} : $USE_INT;
363
+ __PACKAGE__ -> _base_len($base_len, $use_int);
364
+
365
+ return $self;
366
+ }
367
+
368
+ ##############################################################################
369
+ # convert back to string and number
370
+
371
+ sub _str {
372
+ # Convert number from internal base 1eN format to string format. Internal
373
+ # format is always normalized, i.e., no leading zeros.
374
+
375
+ my $ary = $_[1];
376
+ my $idx = $#$ary; # index of last element
377
+
378
+ if ($idx < 0) { # should not happen
379
+ croak("$_[1] has no elements");
380
+ }
381
+
382
+ # Handle first one differently, since it should not have any leading zeros.
383
+ my $ret = int($ary->[$idx]);
384
+ if ($idx > 0) {
385
+ # Interestingly, the pre-padd method uses more time.
386
+ # The old grep variant takes longer (14 vs. 10 sec).
387
+ my $z = '0' x ($BASE_LEN - 1);
388
+ while (--$idx >= 0) {
389
+ $ret .= substr($z . $ary->[$idx], -$BASE_LEN);
390
+ }
391
+ }
392
+ $ret;
393
+ }
394
+
395
+ sub _num {
396
+ # Make a Perl scalar number (int/float) from a BigInt object.
397
+ my $x = $_[1];
398
+
399
+ return $x->[0] if @$x == 1; # below $BASE
400
+
401
+ # Start with the most significant element and work towards the least
402
+ # significant element. Avoid multiplying "inf" (which happens if the number
403
+ # overflows) with "0" (if there are zero elements in $x) since this gives
404
+ # "nan" which propagates to the output.
405
+
406
+ my $num = 0;
407
+ for (my $i = $#$x ; $i >= 0 ; --$i) {
408
+ $num *= $BASE;
409
+ $num += $x -> [$i];
410
+ }
411
+ return $num;
412
+ }
413
+
414
+ ##############################################################################
415
+ # actual math code
416
+
417
+ sub _add {
418
+ # (ref to int_num_array, ref to int_num_array)
419
+ #
420
+ # Routine to add two base 1eX numbers stolen from Knuth Vol 2 Algorithm A
421
+ # pg 231. There are separate routines to add and sub as per Knuth pg 233.
422
+ # This routine modifies array x, but not y.
423
+
424
+ my ($c, $x, $y) = @_;
425
+
426
+ # $x + 0 => $x
427
+
428
+ return $x if @$y == 1 && $y->[0] == 0;
429
+
430
+ # 0 + $y => $y->copy
431
+
432
+ if (@$x == 1 && $x->[0] == 0) {
433
+ @$x = @$y;
434
+ return $x;
435
+ }
436
+
437
+ # For each in Y, add Y to X and carry. If after that, something is left in
438
+ # X, foreach in X add carry to X and then return X, carry. Trades one
439
+ # "$j++" for having to shift arrays.
440
+
441
+ my $car = 0;
442
+ my $j = 0;
443
+ for my $i (@$y) {
444
+ $x->[$j] -= $BASE if $car = (($x->[$j] += $i + $car) >= $BASE) ? 1 : 0;
445
+ $j++;
446
+ }
447
+ while ($car != 0) {
448
+ $x->[$j] -= $BASE if $car = (($x->[$j] += $car) >= $BASE) ? 1 : 0;
449
+ $j++;
450
+ }
451
+ $x;
452
+ }
453
+
454
+ sub _inc {
455
+ # (ref to int_num_array, ref to int_num_array)
456
+ # Add 1 to $x, modify $x in place
457
+ my ($c, $x) = @_;
458
+
459
+ for my $i (@$x) {
460
+ return $x if ($i += 1) < $BASE; # early out
461
+ $i = 0; # overflow, next
462
+ }
463
+ push @$x, 1 if $x->[-1] == 0; # last overflowed, so extend
464
+ $x;
465
+ }
466
+
467
+ sub _dec {
468
+ # (ref to int_num_array, ref to int_num_array)
469
+ # Sub 1 from $x, modify $x in place
470
+ my ($c, $x) = @_;
471
+
472
+ my $MAX = $BASE - 1; # since MAX_VAL based on BASE
473
+ for my $i (@$x) {
474
+ last if ($i -= 1) >= 0; # early out
475
+ $i = $MAX; # underflow, next
476
+ }
477
+ pop @$x if $x->[-1] == 0 && @$x > 1; # last underflowed (but leave 0)
478
+ $x;
479
+ }
480
+
481
+ sub _sub {
482
+ # (ref to int_num_array, ref to int_num_array, swap)
483
+ #
484
+ # Subtract base 1eX numbers -- stolen from Knuth Vol 2 pg 232, $x > $y
485
+ # subtract Y from X by modifying x in place
486
+ my ($c, $sx, $sy, $s) = @_;
487
+
488
+ my $car = 0;
489
+ my $j = 0;
490
+ if (!$s) {
491
+ for my $i (@$sx) {
492
+ last unless defined $sy->[$j] || $car;
493
+ $i += $BASE if $car = (($i -= ($sy->[$j] || 0) + $car) < 0);
494
+ $j++;
495
+ }
496
+ # might leave leading zeros, so fix that
497
+ return __strip_zeros($sx);
498
+ }
499
+ for my $i (@$sx) {
500
+ # We can't do an early out if $x < $y, since we need to copy the high
501
+ # chunks from $y. Found by Bob Mathews.
502
+ #last unless defined $sy->[$j] || $car;
503
+ $sy->[$j] += $BASE
504
+ if $car = ($sy->[$j] = $i - ($sy->[$j] || 0) - $car) < 0;
505
+ $j++;
506
+ }
507
+ # might leave leading zeros, so fix that
508
+ __strip_zeros($sy);
509
+ }
510
+
511
+ sub _mul_use_int {
512
+ # (ref to int_num_array, ref to int_num_array)
513
+ # multiply two numbers in internal representation
514
+ # modifies first arg, second need not be different from first
515
+ # works for 64 bit integer with "use integer"
516
+ my ($c, $xv, $yv) = @_;
517
+ use integer;
518
+
519
+ if (@$yv == 1) {
520
+ # shortcut for two very short numbers (improved by Nathan Zook) works
521
+ # also if xv and yv are the same reference, and handles also $x == 0
522
+ if (@$xv == 1) {
523
+ if (($xv->[0] *= $yv->[0]) >= $BASE) {
524
+ $xv->[0] =
525
+ $xv->[0] - ($xv->[1] = $xv->[0] / $BASE) * $BASE;
526
+ }
527
+ return $xv;
528
+ }
529
+ # $x * 0 => 0
530
+ if ($yv->[0] == 0) {
531
+ @$xv = (0);
532
+ return $xv;
533
+ }
534
+
535
+ # multiply a large number a by a single element one, so speed up
536
+ my $y = $yv->[0];
537
+ my $car = 0;
538
+ foreach my $i (@$xv) {
539
+ #$i = $i * $y + $car; $car = $i / $BASE; $i -= $car * $BASE;
540
+ $i = $i * $y + $car;
541
+ $i -= ($car = $i / $BASE) * $BASE;
542
+ }
543
+ push @$xv, $car if $car != 0;
544
+ return $xv;
545
+ }
546
+
547
+ # shortcut for result $x == 0 => result = 0
548
+ return $xv if @$xv == 1 && $xv->[0] == 0;
549
+
550
+ # since multiplying $x with $x fails, make copy in this case
551
+ $yv = $c->_copy($xv) if $xv == $yv; # same references?
552
+
553
+ my @prod = ();
554
+ my ($prod, $car, $cty);
555
+ for my $xi (@$xv) {
556
+ $car = 0;
557
+ $cty = 0;
558
+ # looping through this if $xi == 0 is silly - so optimize it away!
559
+ $xi = (shift(@prod) || 0), next if $xi == 0;
560
+ for my $yi (@$yv) {
561
+ $prod = $xi * $yi + ($prod[$cty] || 0) + $car;
562
+ $prod[$cty++] = $prod - ($car = $prod / $BASE) * $BASE;
563
+ }
564
+ $prod[$cty] += $car if $car; # need really to check for 0?
565
+ $xi = shift(@prod) || 0; # || 0 makes v5.005_3 happy
566
+ }
567
+ push @$xv, @prod;
568
+ $xv;
569
+ }
570
+
571
+ sub _mul_no_int {
572
+ # (ref to int_num_array, ref to int_num_array)
573
+ # multiply two numbers in internal representation
574
+ # modifies first arg, second need not be different from first
575
+ my ($c, $xv, $yv) = @_;
576
+
577
+ if (@$yv == 1) {
578
+ # shortcut for two very short numbers (improved by Nathan Zook) works
579
+ # also if xv and yv are the same reference, and handles also $x == 0
580
+ if (@$xv == 1) {
581
+ if (($xv->[0] *= $yv->[0]) >= $BASE) {
582
+ my $rem = $xv->[0] % $BASE;
583
+ $xv->[1] = ($xv->[0] - $rem) / $BASE;
584
+ $xv->[0] = $rem;
585
+ }
586
+ return $xv;
587
+ }
588
+ # $x * 0 => 0
589
+ if ($yv->[0] == 0) {
590
+ @$xv = (0);
591
+ return $xv;
592
+ }
593
+
594
+ # multiply a large number a by a single element one, so speed up
595
+ my $y = $yv->[0];
596
+ my $car = 0;
597
+ my $rem;
598
+ foreach my $i (@$xv) {
599
+ $i = $i * $y + $car;
600
+ $rem = $i % $BASE;
601
+ $car = ($i - $rem) / $BASE;
602
+ $i = $rem;
603
+ }
604
+ push @$xv, $car if $car != 0;
605
+ return $xv;
606
+ }
607
+
608
+ # shortcut for result $x == 0 => result = 0
609
+ return $xv if @$xv == 1 && $xv->[0] == 0;
610
+
611
+ # since multiplying $x with $x fails, make copy in this case
612
+ $yv = $c->_copy($xv) if $xv == $yv; # same references?
613
+
614
+ my @prod = ();
615
+ my ($prod, $rem, $car, $cty);
616
+ for my $xi (@$xv) {
617
+ $car = 0;
618
+ $cty = 0;
619
+ # looping through this if $xi == 0 is silly - so optimize it away!
620
+ $xi = (shift(@prod) || 0), next if $xi == 0;
621
+ for my $yi (@$yv) {
622
+ $prod = $xi * $yi + ($prod[$cty] || 0) + $car;
623
+ $rem = $prod % $BASE;
624
+ $car = ($prod - $rem) / $BASE;
625
+ $prod[$cty++] = $rem;
626
+ }
627
+ $prod[$cty] += $car if $car; # need really to check for 0?
628
+ $xi = shift(@prod) || 0; # || 0 makes v5.005_3 happy
629
+ }
630
+ push @$xv, @prod;
631
+ $xv;
632
+ }
633
+
634
+ sub _div_use_int {
635
+ # ref to array, ref to array, modify first array and return remainder if
636
+ # in list context
637
+
638
+ # This version works on integers
639
+ use integer;
640
+
641
+ my ($c, $x, $yorg) = @_;
642
+
643
+ # the general div algorithm here is about O(N*N) and thus quite slow, so
644
+ # we first check for some special cases and use shortcuts to handle them.
645
+
646
+ # if both numbers have only one element:
647
+ if (@$x == 1 && @$yorg == 1) {
648
+ # shortcut, $yorg and $x are two small numbers
649
+ if (wantarray) {
650
+ my $rem = [ $x->[0] % $yorg->[0] ];
651
+ bless $rem, $c;
652
+ $x->[0] = $x->[0] / $yorg->[0];
653
+ return ($x, $rem);
654
+ } else {
655
+ $x->[0] = $x->[0] / $yorg->[0];
656
+ return $x;
657
+ }
658
+ }
659
+
660
+ # if x has more than one, but y has only one element:
661
+ if (@$yorg == 1) {
662
+ my $rem;
663
+ $rem = $c->_mod($c->_copy($x), $yorg) if wantarray;
664
+
665
+ # shortcut, $y is < $BASE
666
+ my $j = @$x;
667
+ my $r = 0;
668
+ my $y = $yorg->[0];
669
+ my $b;
670
+ while ($j-- > 0) {
671
+ $b = $r * $BASE + $x->[$j];
672
+ $r = $b % $y;
673
+ $x->[$j] = $b / $y;
674
+ }
675
+ pop(@$x) if @$x > 1 && $x->[-1] == 0; # remove any trailing zero
676
+ return ($x, $rem) if wantarray;
677
+ return $x;
678
+ }
679
+
680
+ # now x and y have more than one element
681
+
682
+ # check whether y has more elements than x, if so, the result is 0
683
+ if (@$yorg > @$x) {
684
+ my $rem;
685
+ $rem = $c->_copy($x) if wantarray; # make copy
686
+ @$x = 0; # set to 0
687
+ return ($x, $rem) if wantarray; # including remainder?
688
+ return $x; # only x, which is [0] now
689
+ }
690
+
691
+ # check whether the numbers have the same number of elements, in that case
692
+ # the result will fit into one element and can be computed efficiently
693
+ if (@$yorg == @$x) {
694
+ my $cmp = 0;
695
+ for (my $j = $#$x ; $j >= 0 ; --$j) {
696
+ last if $cmp = $x->[$j] - $yorg->[$j];
697
+ }
698
+
699
+ if ($cmp == 0) { # x = y
700
+ @$x = 1;
701
+ return $x, $c->_zero() if wantarray;
702
+ return $x;
703
+ }
704
+
705
+ if ($cmp < 0) { # x < y
706
+ if (wantarray) {
707
+ my $rem = $c->_copy($x);
708
+ @$x = 0;
709
+ return $x, $rem;
710
+ }
711
+ @$x = 0;
712
+ return $x;
713
+ }
714
+ }
715
+
716
+ # all other cases:
717
+
718
+ my $y = $c->_copy($yorg); # always make copy to preserve
719
+
720
+ my $tmp;
721
+ my $dd = $BASE / ($y->[-1] + 1);
722
+ if ($dd != 1) {
723
+ my $car = 0;
724
+ for my $xi (@$x) {
725
+ $xi = $xi * $dd + $car;
726
+ $xi -= ($car = $xi / $BASE) * $BASE;
727
+ }
728
+ push(@$x, $car);
729
+ $car = 0;
730
+ for my $yi (@$y) {
731
+ $yi = $yi * $dd + $car;
732
+ $yi -= ($car = $yi / $BASE) * $BASE;
733
+ }
734
+ } else {
735
+ push(@$x, 0);
736
+ }
737
+
738
+ # @q will accumulate the final result, $q contains the current computed
739
+ # part of the final result
740
+
741
+ my @q = ();
742
+ my ($v2, $v1) = @$y[-2, -1];
743
+ $v2 = 0 unless $v2;
744
+ while ($#$x > $#$y) {
745
+ my ($u2, $u1, $u0) = @$x[-3 .. -1];
746
+ $u2 = 0 unless $u2;
747
+ #warn "oups v1 is 0, u0: $u0 $y->[-2] $y->[-1] l ",scalar @$y,"\n"
748
+ # if $v1 == 0;
749
+ my $tmp = $u0 * $BASE + $u1;
750
+ my $rem = $tmp % $v1;
751
+ my $q = $u0 == $v1 ? $MAX_VAL : (($tmp - $rem) / $v1);
752
+ --$q while $v2 * $q > ($u0 * $BASE + $u1 - $q * $v1) * $BASE + $u2;
753
+ if ($q) {
754
+ my $prd;
755
+ my ($car, $bar) = (0, 0);
756
+ for (my $yi = 0, my $xi = $#$x - $#$y - 1; $yi <= $#$y; ++$yi, ++$xi) {
757
+ $prd = $q * $y->[$yi] + $car;
758
+ $prd -= ($car = int($prd / $BASE)) * $BASE;
759
+ $x->[$xi] += $BASE if $bar = (($x->[$xi] -= $prd + $bar) < 0);
760
+ }
761
+ if ($x->[-1] < $car + $bar) {
762
+ $car = 0;
763
+ --$q;
764
+ for (my $yi = 0, my $xi = $#$x - $#$y - 1; $yi <= $#$y; ++$yi, ++$xi) {
765
+ $x->[$xi] -= $BASE
766
+ if $car = (($x->[$xi] += $y->[$yi] + $car) >= $BASE);
767
+ }
768
+ }
769
+ }
770
+ pop(@$x);
771
+ unshift(@q, $q);
772
+ }
773
+
774
+ if (wantarray) {
775
+ my $d = bless [], $c;
776
+ if ($dd != 1) {
777
+ my $car = 0;
778
+ my $prd;
779
+ for my $xi (reverse @$x) {
780
+ $prd = $car * $BASE + $xi;
781
+ $car = $prd - ($tmp = $prd / $dd) * $dd;
782
+ unshift @$d, $tmp;
783
+ }
784
+ } else {
785
+ @$d = @$x;
786
+ }
787
+ @$x = @q;
788
+ __strip_zeros($x);
789
+ __strip_zeros($d);
790
+ return ($x, $d);
791
+ }
792
+ @$x = @q;
793
+ __strip_zeros($x);
794
+ $x;
795
+ }
796
+
797
+ sub _div_no_int {
798
+ # ref to array, ref to array, modify first array and return remainder if
799
+ # in list context
800
+
801
+ my ($c, $x, $yorg) = @_;
802
+
803
+ # the general div algorithm here is about O(N*N) and thus quite slow, so
804
+ # we first check for some special cases and use shortcuts to handle them.
805
+
806
+ # if both numbers have only one element:
807
+ if (@$x == 1 && @$yorg == 1) {
808
+ # shortcut, $yorg and $x are two small numbers
809
+ my $rem = [ $x->[0] % $yorg->[0] ];
810
+ bless $rem, $c;
811
+ $x->[0] = ($x->[0] - $rem->[0]) / $yorg->[0];
812
+ return ($x, $rem) if wantarray;
813
+ return $x;
814
+ }
815
+
816
+ # if x has more than one, but y has only one element:
817
+ if (@$yorg == 1) {
818
+ my $rem;
819
+ $rem = $c->_mod($c->_copy($x), $yorg) if wantarray;
820
+
821
+ # shortcut, $y is < $BASE
822
+ my $j = @$x;
823
+ my $r = 0;
824
+ my $y = $yorg->[0];
825
+ my $b;
826
+ while ($j-- > 0) {
827
+ $b = $r * $BASE + $x->[$j];
828
+ $r = $b % $y;
829
+ $x->[$j] = ($b - $r) / $y;
830
+ }
831
+ pop(@$x) if @$x > 1 && $x->[-1] == 0; # remove any trailing zero
832
+ return ($x, $rem) if wantarray;
833
+ return $x;
834
+ }
835
+
836
+ # now x and y have more than one element
837
+
838
+ # check whether y has more elements than x, if so, the result is 0
839
+ if (@$yorg > @$x) {
840
+ my $rem;
841
+ $rem = $c->_copy($x) if wantarray; # make copy
842
+ @$x = 0; # set to 0
843
+ return ($x, $rem) if wantarray; # including remainder?
844
+ return $x; # only x, which is [0] now
845
+ }
846
+
847
+ # check whether the numbers have the same number of elements, in that case
848
+ # the result will fit into one element and can be computed efficiently
849
+ if (@$yorg == @$x) {
850
+ my $cmp = 0;
851
+ for (my $j = $#$x ; $j >= 0 ; --$j) {
852
+ last if $cmp = $x->[$j] - $yorg->[$j];
853
+ }
854
+
855
+ if ($cmp == 0) { # x = y
856
+ @$x = 1;
857
+ return $x, $c->_zero() if wantarray;
858
+ return $x;
859
+ }
860
+
861
+ if ($cmp < 0) { # x < y
862
+ if (wantarray) {
863
+ my $rem = $c->_copy($x);
864
+ @$x = 0;
865
+ return $x, $rem;
866
+ }
867
+ @$x = 0;
868
+ return $x;
869
+ }
870
+ }
871
+
872
+ # all other cases:
873
+
874
+ my $y = $c->_copy($yorg); # always make copy to preserve
875
+
876
+ my $tmp = $y->[-1] + 1;
877
+ my $rem = $BASE % $tmp;
878
+ my $dd = ($BASE - $rem) / $tmp;
879
+ if ($dd != 1) {
880
+ my $car = 0;
881
+ for my $xi (@$x) {
882
+ $xi = $xi * $dd + $car;
883
+ $rem = $xi % $BASE;
884
+ $car = ($xi - $rem) / $BASE;
885
+ $xi = $rem;
886
+ }
887
+ push(@$x, $car);
888
+ $car = 0;
889
+ for my $yi (@$y) {
890
+ $yi = $yi * $dd + $car;
891
+ $rem = $yi % $BASE;
892
+ $car = ($yi - $rem) / $BASE;
893
+ $yi = $rem;
894
+ }
895
+ } else {
896
+ push(@$x, 0);
897
+ }
898
+
899
+ # @q will accumulate the final result, $q contains the current computed
900
+ # part of the final result
901
+
902
+ my @q = ();
903
+ my ($v2, $v1) = @$y[-2, -1];
904
+ $v2 = 0 unless $v2;
905
+ while ($#$x > $#$y) {
906
+ my ($u2, $u1, $u0) = @$x[-3 .. -1];
907
+ $u2 = 0 unless $u2;
908
+ #warn "oups v1 is 0, u0: $u0 $y->[-2] $y->[-1] l ",scalar @$y,"\n"
909
+ # if $v1 == 0;
910
+ my $tmp = $u0 * $BASE + $u1;
911
+ my $rem = $tmp % $v1;
912
+ my $q = $u0 == $v1 ? $MAX_VAL : (($tmp - $rem) / $v1);
913
+ --$q while $v2 * $q > ($u0 * $BASE + $u1 - $q * $v1) * $BASE + $u2;
914
+ if ($q) {
915
+ my $prd;
916
+ my ($car, $bar) = (0, 0);
917
+ for (my $yi = 0, my $xi = $#$x - $#$y - 1; $yi <= $#$y; ++$yi, ++$xi) {
918
+ $prd = $q * $y->[$yi] + $car;
919
+ $rem = $prd % $BASE;
920
+ $car = ($prd - $rem) / $BASE;
921
+ $prd -= $car * $BASE;
922
+ $x->[$xi] += $BASE if $bar = (($x->[$xi] -= $prd + $bar) < 0);
923
+ }
924
+ if ($x->[-1] < $car + $bar) {
925
+ $car = 0;
926
+ --$q;
927
+ for (my $yi = 0, my $xi = $#$x - $#$y - 1; $yi <= $#$y; ++$yi, ++$xi) {
928
+ $x->[$xi] -= $BASE
929
+ if $car = (($x->[$xi] += $y->[$yi] + $car) >= $BASE);
930
+ }
931
+ }
932
+ }
933
+ pop(@$x);
934
+ unshift(@q, $q);
935
+ }
936
+
937
+ if (wantarray) {
938
+ my $d = bless [], $c;
939
+ if ($dd != 1) {
940
+ my $car = 0;
941
+ my ($prd, $rem);
942
+ for my $xi (reverse @$x) {
943
+ $prd = $car * $BASE + $xi;
944
+ $rem = $prd % $dd;
945
+ $tmp = ($prd - $rem) / $dd;
946
+ $car = $rem;
947
+ unshift @$d, $tmp;
948
+ }
949
+ } else {
950
+ @$d = @$x;
951
+ }
952
+ @$x = @q;
953
+ __strip_zeros($x);
954
+ __strip_zeros($d);
955
+ return ($x, $d);
956
+ }
957
+ @$x = @q;
958
+ __strip_zeros($x);
959
+ $x;
960
+ }
961
+
962
+ ##############################################################################
963
+ # testing
964
+
965
+ sub _acmp {
966
+ # Internal absolute post-normalized compare (ignore signs)
967
+ # ref to array, ref to array, return <0, 0, >0
968
+ # Arrays must have at least one entry; this is not checked for.
969
+ my ($c, $cx, $cy) = @_;
970
+
971
+ # shortcut for short numbers
972
+ return (($cx->[0] <=> $cy->[0]) <=> 0)
973
+ if @$cx == 1 && @$cy == 1;
974
+
975
+ # fast comp based on number of array elements (aka pseudo-length)
976
+ my $lxy = (@$cx - @$cy)
977
+ # or length of first element if same number of elements (aka difference 0)
978
+ ||
979
+ # need int() here because sometimes the last element is '00018' vs '18'
980
+ (length(int($cx->[-1])) - length(int($cy->[-1])));
981
+
982
+ return -1 if $lxy < 0; # already differs, ret
983
+ return 1 if $lxy > 0; # ditto
984
+
985
+ # manual way (abort if unequal, good for early ne)
986
+ my $a;
987
+ my $j = @$cx;
988
+ while (--$j >= 0) {
989
+ last if $a = $cx->[$j] - $cy->[$j];
990
+ }
991
+ $a <=> 0;
992
+ }
993
+
994
+ sub _len {
995
+ # compute number of digits in base 10
996
+
997
+ # int() because add/sub sometimes leaves strings (like '00005') instead of
998
+ # '5' in this place, thus causing length() to report wrong length
999
+ my $cx = $_[1];
1000
+
1001
+ (@$cx - 1) * $BASE_LEN + length(int($cx->[-1]));
1002
+ }
1003
+
1004
+ sub _digit {
1005
+ # Return the nth digit. Zero is rightmost, so _digit(123, 0) gives 3.
1006
+ # Negative values count from the left, so _digit(123, -1) gives 1.
1007
+ my ($c, $x, $n) = @_;
1008
+
1009
+ my $len = _len('', $x);
1010
+
1011
+ $n += $len if $n < 0; # -1 last, -2 second-to-last
1012
+
1013
+ # Math::BigInt::Calc returns 0 if N is out of range, but this is not done
1014
+ # by the other backend libraries.
1015
+
1016
+ return "0" if $n < 0 || $n >= $len; # return 0 for digits out of range
1017
+
1018
+ my $elem = int($n / $BASE_LEN); # index of array element
1019
+ my $digit = $n % $BASE_LEN; # index of digit within the element
1020
+ substr("0" x $BASE_LEN . "$x->[$elem]", -1 - $digit, 1);
1021
+ }
1022
+
1023
+ sub _zeros {
1024
+ # Return number of trailing zeros in decimal.
1025
+ # Check each array element for having 0 at end as long as elem == 0
1026
+ # Upon finding a elem != 0, stop.
1027
+
1028
+ my $x = $_[1];
1029
+
1030
+ return 0 if @$x == 1 && $x->[0] == 0;
1031
+
1032
+ my $zeros = 0;
1033
+ foreach my $elem (@$x) {
1034
+ if ($elem != 0) {
1035
+ $elem =~ /[^0](0*)\z/;
1036
+ $zeros += length($1); # count trailing zeros
1037
+ last; # early out
1038
+ }
1039
+ $zeros += $BASE_LEN;
1040
+ }
1041
+ $zeros;
1042
+ }
1043
+
1044
+ ##############################################################################
1045
+ # _is_* routines
1046
+
1047
+ sub _is_zero {
1048
+ # return true if arg is zero
1049
+ @{$_[1]} == 1 && $_[1]->[0] == 0 ? 1 : 0;
1050
+ }
1051
+
1052
+ sub _is_even {
1053
+ # return true if arg is even
1054
+ $_[1]->[0] % 2 ? 0 : 1;
1055
+ }
1056
+
1057
+ sub _is_odd {
1058
+ # return true if arg is odd
1059
+ $_[1]->[0] % 2 ? 1 : 0;
1060
+ }
1061
+
1062
+ sub _is_one {
1063
+ # return true if arg is one
1064
+ @{$_[1]} == 1 && $_[1]->[0] == 1 ? 1 : 0;
1065
+ }
1066
+
1067
+ sub _is_two {
1068
+ # return true if arg is two
1069
+ @{$_[1]} == 1 && $_[1]->[0] == 2 ? 1 : 0;
1070
+ }
1071
+
1072
+ sub _is_ten {
1073
+ # return true if arg is ten
1074
+ if ($BASE_LEN == 1) {
1075
+ @{$_[1]} == 2 && $_[1]->[0] == 0 && $_[1]->[1] == 1 ? 1 : 0;
1076
+ } else {
1077
+ @{$_[1]} == 1 && $_[1]->[0] == 10 ? 1 : 0;
1078
+ }
1079
+ }
1080
+
1081
+ sub __strip_zeros {
1082
+ # Internal normalization function that strips leading zeros from the array.
1083
+ # Args: ref to array
1084
+ my $x = shift;
1085
+
1086
+ push @$x, 0 if @$x == 0; # div might return empty results, so fix it
1087
+ return $x if @$x == 1; # early out
1088
+
1089
+ #print "strip: cnt $cnt i $i\n";
1090
+ # '0', '3', '4', '0', '0',
1091
+ # 0 1 2 3 4
1092
+ # cnt = 5, i = 4
1093
+ # i = 4
1094
+ # i = 3
1095
+ # => fcnt = cnt - i (5-2 => 3, cnt => 5-1 = 4, throw away from 4th pos)
1096
+ # >= 1: skip first part (this can be zero)
1097
+
1098
+ my $i = $#$x;
1099
+ while ($i > 0) {
1100
+ last if $x->[$i] != 0;
1101
+ $i--;
1102
+ }
1103
+ $i++;
1104
+ splice(@$x, $i) if $i < @$x;
1105
+ $x;
1106
+ }
1107
+
1108
+ ###############################################################################
1109
+ # check routine to test internal state for corruptions
1110
+
1111
+ sub _check {
1112
+ # used by the test suite
1113
+ my ($class, $x) = @_;
1114
+
1115
+ my $msg = $class -> SUPER::_check($x);
1116
+ return $msg if $msg;
1117
+
1118
+ my $n;
1119
+ eval { $n = @$x };
1120
+ return "Not an array reference" unless $@ eq '';
1121
+
1122
+ return "Reference to an empty array" unless $n > 0;
1123
+
1124
+ # The following fails with Math::BigInt::FastCalc because a
1125
+ # Math::BigInt::FastCalc "object" is an unblessed array ref.
1126
+ #
1127
+ #return 0 unless ref($x) eq $class;
1128
+
1129
+ for (my $i = 0 ; $i <= $#$x ; ++ $i) {
1130
+ my $e = $x -> [$i];
1131
+
1132
+ return "Element at index $i is undefined"
1133
+ unless defined $e;
1134
+
1135
+ return "Element at index $i is a '" . ref($e) .
1136
+ "', which is not a scalar"
1137
+ unless ref($e) eq "";
1138
+
1139
+ # It would be better to use the regex /^([1-9]\d*|0)\z/, but that fails
1140
+ # in Math::BigInt::FastCalc, because it sometimes creates array
1141
+ # elements like "000000".
1142
+ return "Element at index $i is '$e', which does not look like an" .
1143
+ " normal integer" unless $e =~ /^\d+\z/;
1144
+
1145
+ return "Element at index $i is '$e', which is not smaller than" .
1146
+ " the base '$BASE'" if $e >= $BASE;
1147
+
1148
+ return "Element at index $i (last element) is zero"
1149
+ if $#$x > 0 && $i == $#$x && $e == 0;
1150
+ }
1151
+
1152
+ return 0;
1153
+ }
1154
+
1155
+ ###############################################################################
1156
+
1157
+ sub _mod {
1158
+ # if possible, use mod shortcut
1159
+ my ($c, $x, $yo) = @_;
1160
+
1161
+ # slow way since $y too big
1162
+ if (@$yo > 1) {
1163
+ my ($xo, $rem) = $c->_div($x, $yo);
1164
+ @$x = @$rem;
1165
+ return $x;
1166
+ }
1167
+
1168
+ my $y = $yo->[0];
1169
+
1170
+ # if both are single element arrays
1171
+ if (@$x == 1) {
1172
+ $x->[0] %= $y;
1173
+ return $x;
1174
+ }
1175
+
1176
+ # if @$x has more than one element, but @$y is a single element
1177
+ my $b = $BASE % $y;
1178
+ if ($b == 0) {
1179
+ # when BASE % Y == 0 then (B * BASE) % Y == 0
1180
+ # (B * BASE) % $y + A % Y => A % Y
1181
+ # so need to consider only last element: O(1)
1182
+ $x->[0] %= $y;
1183
+ } elsif ($b == 1) {
1184
+ # else need to go through all elements in @$x: O(N), but loop is a bit
1185
+ # simplified
1186
+ my $r = 0;
1187
+ foreach (@$x) {
1188
+ $r = ($r + $_) % $y; # not much faster, but heh...
1189
+ #$r += $_ % $y; $r %= $y;
1190
+ }
1191
+ $r = 0 if $r == $y;
1192
+ $x->[0] = $r;
1193
+ } else {
1194
+ # else need to go through all elements in @$x: O(N)
1195
+ my $r = 0;
1196
+ my $bm = 1;
1197
+ foreach (@$x) {
1198
+ $r = ($_ * $bm + $r) % $y;
1199
+ $bm = ($bm * $b) % $y;
1200
+
1201
+ #$r += ($_ % $y) * $bm;
1202
+ #$bm *= $b;
1203
+ #$bm %= $y;
1204
+ #$r %= $y;
1205
+ }
1206
+ $r = 0 if $r == $y;
1207
+ $x->[0] = $r;
1208
+ }
1209
+ @$x = $x->[0]; # keep one element of @$x
1210
+ return $x;
1211
+ }
1212
+
1213
+ ##############################################################################
1214
+ # shifts
1215
+
1216
+ sub _rsft {
1217
+ my ($c, $x, $n, $b) = @_;
1218
+ return $x if $c->_is_zero($x) || $c->_is_zero($n);
1219
+
1220
+ # For backwards compatibility, allow the base $b to be a scalar.
1221
+
1222
+ $b = $c->_new($b) unless ref $b;
1223
+
1224
+ if ($c -> _acmp($b, $c -> _ten())) {
1225
+ return scalar $c->_div($x, $c->_pow($c->_copy($b), $n));
1226
+ }
1227
+
1228
+ # shortcut (faster) for shifting by 10)
1229
+ # multiples of $BASE_LEN
1230
+ my $dst = 0; # destination
1231
+ my $src = $c->_num($n); # as normal int
1232
+ my $xlen = (@$x - 1) * $BASE_LEN + length(int($x->[-1]));
1233
+ if ($src >= $xlen or ($src == $xlen and !defined $x->[1])) {
1234
+ # 12345 67890 shifted right by more than 10 digits => 0
1235
+ splice(@$x, 1); # leave only one element
1236
+ $x->[0] = 0; # set to zero
1237
+ return $x;
1238
+ }
1239
+ my $rem = $src % $BASE_LEN; # remainder to shift
1240
+ $src = int($src / $BASE_LEN); # source
1241
+ if ($rem == 0) {
1242
+ splice(@$x, 0, $src); # even faster, 38.4 => 39.3
1243
+ } else {
1244
+ my $len = @$x - $src; # elems to go
1245
+ my $vd;
1246
+ my $z = '0' x $BASE_LEN;
1247
+ $x->[ @$x ] = 0; # avoid || 0 test inside loop
1248
+ while ($dst < $len) {
1249
+ $vd = $z . $x->[$src];
1250
+ $vd = substr($vd, -$BASE_LEN, $BASE_LEN - $rem);
1251
+ $src++;
1252
+ $vd = substr($z . $x->[$src], -$rem, $rem) . $vd;
1253
+ $vd = substr($vd, -$BASE_LEN, $BASE_LEN) if length($vd) > $BASE_LEN;
1254
+ $x->[$dst] = int($vd);
1255
+ $dst++;
1256
+ }
1257
+ splice(@$x, $dst) if $dst > 0; # kill left-over array elems
1258
+ pop(@$x) if $x->[-1] == 0 && @$x > 1; # kill last element if 0
1259
+ } # else rem == 0
1260
+ $x;
1261
+ }
1262
+
1263
+ sub _lsft {
1264
+ my ($c, $x, $n, $b) = @_;
1265
+
1266
+ return $x if $c->_is_zero($x) || $c->_is_zero($n);
1267
+
1268
+ # For backwards compatibility, allow the base $b to be a scalar.
1269
+
1270
+ $b = $c->_new($b) unless ref $b;
1271
+
1272
+ # If the base is a power of 10, use shifting, since the internal
1273
+ # representation is in base 10eX.
1274
+
1275
+ my $bstr = $c->_str($b);
1276
+ if ($bstr =~ /^1(0+)\z/) {
1277
+
1278
+ # Adjust $n so that we're shifting in base 10. Do this by multiplying
1279
+ # $n by the base 10 logarithm of $b: $b ** $n = 10 ** (log10($b) * $n).
1280
+
1281
+ my $log10b = length($1);
1282
+ $n = $c->_mul($c->_new($log10b), $n);
1283
+ $n = $c->_num($n); # shift-len as normal int
1284
+
1285
+ # $q is the number of places to shift the elements within the array,
1286
+ # and $r is the number of places to shift the values within the
1287
+ # elements.
1288
+
1289
+ my $r = $n % $BASE_LEN;
1290
+ my $q = ($n - $r) / $BASE_LEN;
1291
+
1292
+ # If we must shift the values within the elements ...
1293
+
1294
+ if ($r) {
1295
+ my $i = @$x; # index
1296
+ $x->[$i] = 0; # initialize most significant element
1297
+ my $z = '0' x $BASE_LEN;
1298
+ my $vd;
1299
+ while ($i >= 0) {
1300
+ $vd = $x->[$i];
1301
+ $vd = $z . $vd;
1302
+ $vd = substr($vd, $r - $BASE_LEN, $BASE_LEN - $r);
1303
+ $vd .= $i > 0 ? substr($z . $x->[$i - 1], -$BASE_LEN, $r)
1304
+ : '0' x $r;
1305
+ $vd = substr($vd, -$BASE_LEN, $BASE_LEN) if length($vd) > $BASE_LEN;
1306
+ $x->[$i] = int($vd); # e.g., "0...048" -> 48 etc.
1307
+ $i--;
1308
+ }
1309
+
1310
+ pop(@$x) if $x->[-1] == 0; # if most significant element is zero
1311
+ }
1312
+
1313
+ # If we must shift the elements within the array ...
1314
+
1315
+ if ($q) {
1316
+ unshift @$x, (0) x $q;
1317
+ }
1318
+
1319
+ } else {
1320
+ $x = $c->_mul($x, $c->_pow($b, $n));
1321
+ }
1322
+
1323
+ return $x;
1324
+ }
1325
+
1326
+ sub _pow {
1327
+ # power of $x to $y
1328
+ # ref to array, ref to array, return ref to array
1329
+ my ($c, $cx, $cy) = @_;
1330
+
1331
+ if (@$cy == 1 && $cy->[0] == 0) {
1332
+ splice(@$cx, 1);
1333
+ $cx->[0] = 1; # y == 0 => x => 1
1334
+ return $cx;
1335
+ }
1336
+
1337
+ if ((@$cx == 1 && $cx->[0] == 1) || # x == 1
1338
+ (@$cy == 1 && $cy->[0] == 1)) # or y == 1
1339
+ {
1340
+ return $cx;
1341
+ }
1342
+
1343
+ if (@$cx == 1 && $cx->[0] == 0) {
1344
+ splice (@$cx, 1);
1345
+ $cx->[0] = 0; # 0 ** y => 0 (if not y <= 0)
1346
+ return $cx;
1347
+ }
1348
+
1349
+ my $pow2 = $c->_one();
1350
+
1351
+ my $y_bin = $c->_as_bin($cy);
1352
+ $y_bin =~ s/^0b//;
1353
+ my $len = length($y_bin);
1354
+ while (--$len > 0) {
1355
+ $c->_mul($pow2, $cx) if substr($y_bin, $len, 1) eq '1'; # is odd?
1356
+ $c->_mul($cx, $cx);
1357
+ }
1358
+
1359
+ $c->_mul($cx, $pow2);
1360
+ $cx;
1361
+ }
1362
+
1363
+ sub _nok {
1364
+ # Return binomial coefficient (n over k).
1365
+ # Given refs to arrays, return ref to array.
1366
+ # First input argument is modified.
1367
+
1368
+ my ($c, $n, $k) = @_;
1369
+
1370
+ # If k > n/2, or, equivalently, 2*k > n, compute nok(n, k) as
1371
+ # nok(n, n-k), to minimize the number if iterations in the loop.
1372
+
1373
+ {
1374
+ my $twok = $c->_mul($c->_two(), $c->_copy($k)); # 2 * k
1375
+ if ($c->_acmp($twok, $n) > 0) { # if 2*k > n
1376
+ $k = $c->_sub($c->_copy($n), $k); # k = n - k
1377
+ }
1378
+ }
1379
+
1380
+ # Example:
1381
+ #
1382
+ # / 7 \ 7! 1*2*3*4 * 5*6*7 5 * 6 * 7 6 7
1383
+ # | | = --------- = --------------- = --------- = 5 * - * -
1384
+ # \ 3 / (7-3)! 3! 1*2*3*4 * 1*2*3 1 * 2 * 3 2 3
1385
+
1386
+ if ($c->_is_zero($k)) {
1387
+ @$n = 1;
1388
+ } else {
1389
+
1390
+ # Make a copy of the original n, since we'll be modifying n in-place.
1391
+
1392
+ my $n_orig = $c->_copy($n);
1393
+
1394
+ # n = 5, f = 6, d = 2 (cf. example above)
1395
+
1396
+ $c->_sub($n, $k);
1397
+ $c->_inc($n);
1398
+
1399
+ my $f = $c->_copy($n);
1400
+ $c->_inc($f);
1401
+
1402
+ my $d = $c->_two();
1403
+
1404
+ # while f <= n (the original n, that is) ...
1405
+
1406
+ while ($c->_acmp($f, $n_orig) <= 0) {
1407
+
1408
+ # n = (n * f / d) == 5 * 6 / 2 (cf. example above)
1409
+
1410
+ $c->_mul($n, $f);
1411
+ $c->_div($n, $d);
1412
+
1413
+ # f = 7, d = 3 (cf. example above)
1414
+
1415
+ $c->_inc($f);
1416
+ $c->_inc($d);
1417
+ }
1418
+
1419
+ }
1420
+
1421
+ return $n;
1422
+ }
1423
+
1424
+ sub _fac {
1425
+ # factorial of $x
1426
+ # ref to array, return ref to array
1427
+ my ($c, $cx) = @_;
1428
+
1429
+ # We cache the smallest values. Don't assume that a single element has a
1430
+ # value larger than 9 or else it won't work with a $BASE_LEN of 1.
1431
+
1432
+ if (@$cx == 1) {
1433
+ my @factorials =
1434
+ (
1435
+ '1',
1436
+ '1',
1437
+ '2',
1438
+ '6',
1439
+ '24',
1440
+ '120',
1441
+ '720',
1442
+ '5040',
1443
+ '40320',
1444
+ '362880',
1445
+ );
1446
+ if ($cx->[0] <= $#factorials) {
1447
+ my $tmp = $c -> _new($factorials[ $cx->[0] ]);
1448
+ @$cx = @$tmp;
1449
+ return $cx;
1450
+ }
1451
+ }
1452
+
1453
+ # The old code further below doesn't work for small values of $BASE_LEN.
1454
+ # Alas, I have not been able to (or taken the time to) decipher it, so for
1455
+ # the case when $BASE_LEN is small, we call the parent class. This code
1456
+ # works in for every value of $x and $BASE_LEN. We could use this code for
1457
+ # all cases, but it is a little slower than the code further below, so at
1458
+ # least for now we keep the code below.
1459
+
1460
+ if ($BASE_LEN <= 2) {
1461
+ my $tmp = $c -> SUPER::_fac($cx);
1462
+ @$cx = @$tmp;
1463
+ return $cx;
1464
+ }
1465
+
1466
+ # This code does not work for small values of $BASE_LEN.
1467
+
1468
+ if ((@$cx == 1) && # we do this only if $x >= 12 and $x <= 7000
1469
+ ($cx->[0] >= 12 && $cx->[0] < 7000)) {
1470
+
1471
+ # Calculate (k-j) * (k-j+1) ... k .. (k+j-1) * (k + j)
1472
+ # See http://blogten.blogspot.com/2007/01/calculating-n.html
1473
+ # The above series can be expressed as factors:
1474
+ # k * k - (j - i) * 2
1475
+ # We cache k*k, and calculate (j * j) as the sum of the first j odd integers
1476
+
1477
+ # This will not work when N exceeds the storage of a Perl scalar, however,
1478
+ # in this case the algorithm would be way too slow to terminate, anyway.
1479
+
1480
+ # As soon as the last element of $cx is 0, we split it up and remember
1481
+ # how many zeors we got so far. The reason is that n! will accumulate
1482
+ # zeros at the end rather fast.
1483
+ my $zero_elements = 0;
1484
+
1485
+ # If n is even, set n = n -1
1486
+ my $k = $c->_num($cx);
1487
+ my $even = 1;
1488
+ if (($k & 1) == 0) {
1489
+ $even = $k;
1490
+ $k --;
1491
+ }
1492
+ # set k to the center point
1493
+ $k = ($k + 1) / 2;
1494
+ # print "k $k even: $even\n";
1495
+ # now calculate k * k
1496
+ my $k2 = $k * $k;
1497
+ my $odd = 1;
1498
+ my $sum = 1;
1499
+ my $i = $k - 1;
1500
+ # keep reference to x
1501
+ my $new_x = $c->_new($k * $even);
1502
+ @$cx = @$new_x;
1503
+ if ($cx->[0] == 0) {
1504
+ $zero_elements ++;
1505
+ shift @$cx;
1506
+ }
1507
+ # print STDERR "x = ", $c->_str($cx), "\n";
1508
+ my $BASE2 = int(sqrt($BASE))-1;
1509
+ my $j = 1;
1510
+ while ($j <= $i) {
1511
+ my $m = ($k2 - $sum);
1512
+ $odd += 2;
1513
+ $sum += $odd;
1514
+ $j++;
1515
+ while ($j <= $i && ($m < $BASE2) && (($k2 - $sum) < $BASE2)) {
1516
+ $m *= ($k2 - $sum);
1517
+ $odd += 2;
1518
+ $sum += $odd;
1519
+ $j++;
1520
+ # print STDERR "\n k2 $k2 m $m sum $sum odd $odd\n"; sleep(1);
1521
+ }
1522
+ if ($m < $BASE) {
1523
+ $c->_mul($cx, [$m]);
1524
+ } else {
1525
+ $c->_mul($cx, $c->_new($m));
1526
+ }
1527
+ if ($cx->[0] == 0) {
1528
+ $zero_elements ++;
1529
+ shift @$cx;
1530
+ }
1531
+ # print STDERR "Calculate $k2 - $sum = $m (x = ", $c->_str($cx), ")\n";
1532
+ }
1533
+ # multiply in the zeros again
1534
+ unshift @$cx, (0) x $zero_elements;
1535
+ return $cx;
1536
+ }
1537
+
1538
+ # go forward until $base is exceeded limit is either $x steps (steps == 100
1539
+ # means a result always too high) or $base.
1540
+ my $steps = 100;
1541
+ $steps = $cx->[0] if @$cx == 1;
1542
+ my $r = 2;
1543
+ my $cf = 3;
1544
+ my $step = 2;
1545
+ my $last = $r;
1546
+ while ($r * $cf < $BASE && $step < $steps) {
1547
+ $last = $r;
1548
+ $r *= $cf++;
1549
+ $step++;
1550
+ }
1551
+ if ((@$cx == 1) && $step == $cx->[0]) {
1552
+ # completely done, so keep reference to $x and return
1553
+ $cx->[0] = $r;
1554
+ return $cx;
1555
+ }
1556
+
1557
+ # now we must do the left over steps
1558
+ my $n; # steps still to do
1559
+ if (@$cx == 1) {
1560
+ $n = $cx->[0];
1561
+ } else {
1562
+ $n = $c->_copy($cx);
1563
+ }
1564
+
1565
+ # Set $cx to the last result below $BASE (but keep ref to $x)
1566
+ $cx->[0] = $last;
1567
+ splice (@$cx, 1);
1568
+ # As soon as the last element of $cx is 0, we split it up and remember
1569
+ # how many zeors we got so far. The reason is that n! will accumulate
1570
+ # zeros at the end rather fast.
1571
+ my $zero_elements = 0;
1572
+
1573
+ # do left-over steps fit into a scalar?
1574
+ if (ref $n eq 'ARRAY') {
1575
+ # No, so use slower inc() & cmp()
1576
+ # ($n is at least $BASE here)
1577
+ my $base_2 = int(sqrt($BASE)) - 1;
1578
+ #print STDERR "base_2: $base_2\n";
1579
+ while ($step < $base_2) {
1580
+ if ($cx->[0] == 0) {
1581
+ $zero_elements ++;
1582
+ shift @$cx;
1583
+ }
1584
+ my $b = $step * ($step + 1);
1585
+ $step += 2;
1586
+ $c->_mul($cx, [$b]);
1587
+ }
1588
+ $step = [$step];
1589
+ while ($c->_acmp($step, $n) <= 0) {
1590
+ if ($cx->[0] == 0) {
1591
+ $zero_elements ++;
1592
+ shift @$cx;
1593
+ }
1594
+ $c->_mul($cx, $step);
1595
+ $c->_inc($step);
1596
+ }
1597
+ } else {
1598
+ # Yes, so we can speed it up slightly
1599
+
1600
+ # print "# left over steps $n\n";
1601
+
1602
+ my $base_4 = int(sqrt(sqrt($BASE))) - 2;
1603
+ #print STDERR "base_4: $base_4\n";
1604
+ my $n4 = $n - 4;
1605
+ while ($step < $n4 && $step < $base_4) {
1606
+ if ($cx->[0] == 0) {
1607
+ $zero_elements ++;
1608
+ shift @$cx;
1609
+ }
1610
+ my $b = $step * ($step + 1);
1611
+ $step += 2;
1612
+ $b *= $step * ($step + 1);
1613
+ $step += 2;
1614
+ $c->_mul($cx, [$b]);
1615
+ }
1616
+ my $base_2 = int(sqrt($BASE)) - 1;
1617
+ my $n2 = $n - 2;
1618
+ #print STDERR "base_2: $base_2\n";
1619
+ while ($step < $n2 && $step < $base_2) {
1620
+ if ($cx->[0] == 0) {
1621
+ $zero_elements ++;
1622
+ shift @$cx;
1623
+ }
1624
+ my $b = $step * ($step + 1);
1625
+ $step += 2;
1626
+ $c->_mul($cx, [$b]);
1627
+ }
1628
+ # do what's left over
1629
+ while ($step <= $n) {
1630
+ $c->_mul($cx, [$step]);
1631
+ $step++;
1632
+ if ($cx->[0] == 0) {
1633
+ $zero_elements ++;
1634
+ shift @$cx;
1635
+ }
1636
+ }
1637
+ }
1638
+ # multiply in the zeros again
1639
+ unshift @$cx, (0) x $zero_elements;
1640
+ $cx; # return result
1641
+ }
1642
+
1643
+ sub _log_int {
1644
+ # calculate integer log of $x to base $base
1645
+ # ref to array, ref to array - return ref to array
1646
+ my ($c, $x, $base) = @_;
1647
+
1648
+ # X == 0 => NaN
1649
+ return if @$x == 1 && $x->[0] == 0;
1650
+
1651
+ # BASE 0 or 1 => NaN
1652
+ return if @$base == 1 && $base->[0] < 2;
1653
+
1654
+ # X == 1 => 0 (is exact)
1655
+ if (@$x == 1 && $x->[0] == 1) {
1656
+ @$x = 0;
1657
+ return $x, 1;
1658
+ }
1659
+
1660
+ my $cmp = $c->_acmp($x, $base);
1661
+
1662
+ # X == BASE => 1 (is exact)
1663
+ if ($cmp == 0) {
1664
+ @$x = 1;
1665
+ return $x, 1;
1666
+ }
1667
+
1668
+ # 1 < X < BASE => 0 (is truncated)
1669
+ if ($cmp < 0) {
1670
+ @$x = 0;
1671
+ return $x, 0;
1672
+ }
1673
+
1674
+ my $x_org = $c->_copy($x); # preserve x
1675
+
1676
+ # Compute a guess for the result based on:
1677
+ # $guess = int ( length_in_base_10(X) / ( log(base) / log(10) ) )
1678
+ my $len = $c->_len($x_org);
1679
+ my $log = log($base->[-1]) / log(10);
1680
+
1681
+ # for each additional element in $base, we add $BASE_LEN to the result,
1682
+ # based on the observation that log($BASE, 10) is BASE_LEN and
1683
+ # log(x*y) == log(x) + log(y):
1684
+ $log += (@$base - 1) * $BASE_LEN;
1685
+
1686
+ # calculate now a guess based on the values obtained above:
1687
+ my $res = $c->_new(int($len / $log));
1688
+
1689
+ @$x = @$res;
1690
+ my $trial = $c->_pow($c->_copy($base), $x);
1691
+ my $acmp = $c->_acmp($trial, $x_org);
1692
+
1693
+ # Did we get the exact result?
1694
+
1695
+ return $x, 1 if $acmp == 0;
1696
+
1697
+ # Too small?
1698
+
1699
+ while ($acmp < 0) {
1700
+ $c->_mul($trial, $base);
1701
+ $c->_inc($x);
1702
+ $acmp = $c->_acmp($trial, $x_org);
1703
+ }
1704
+
1705
+ # Too big?
1706
+
1707
+ while ($acmp > 0) {
1708
+ $c->_div($trial, $base);
1709
+ $c->_dec($x);
1710
+ $acmp = $c->_acmp($trial, $x_org);
1711
+ }
1712
+
1713
+ return $x, 1 if $acmp == 0; # result is exact
1714
+ return $x, 0; # result is too small
1715
+ }
1716
+
1717
+ sub _ilog2 {
1718
+ # calculate int(log2($x))
1719
+
1720
+ # There is virtually nothing to gain from computing this any differently
1721
+ # than _log_int(), but it is important that we don't use the method
1722
+ # inherited from the parent, because that method is very slow for backend
1723
+ # libraries whose internal representation uses base 10.
1724
+
1725
+ my ($c, $x) = @_;
1726
+ ($x, my $is_exact) = $c -> _log_int($x, $c -> _two());
1727
+ return wantarray ? ($x, $is_exact) : $x;
1728
+ }
1729
+
1730
+ sub _ilog10 {
1731
+ # calculate int(log10($x))
1732
+
1733
+ my ($c, $x) = @_;
1734
+
1735
+ # X == 0 => NaN
1736
+ return if @$x == 1 && $x->[0] == 0;
1737
+
1738
+ # X == 1 => 0 (is exact)
1739
+ if (@$x == 1 && $x->[0] == 1) {
1740
+ @$x = 0;
1741
+ return wantarray ? ($x, 1) : $x;
1742
+ }
1743
+
1744
+ my $x_orig = $c -> _copy($x);
1745
+ my $nm1 = $c -> _len($x) - 1;
1746
+
1747
+ my $xtmp = $c -> _new($nm1);
1748
+ @$x = @$xtmp;
1749
+
1750
+ return $x unless wantarray;
1751
+
1752
+ # See if the original $x is an exact power of 10, in which case all but the
1753
+ # most significan chunks are 0, and the most significant chunk is a power
1754
+ # of 10.
1755
+
1756
+ my $is_pow10 = 1;
1757
+ for my $i (0 .. $#$x_orig - 1) {
1758
+ last unless $is_pow10 = $x_orig->[$i] == 0;
1759
+ }
1760
+ $is_pow10 &&= $x_orig->[-1] == 10**int(0.5 + log($x_orig->[-1]) / log(10));
1761
+
1762
+ return wantarray ? ($x, 1) : $x if $is_pow10;
1763
+ return wantarray ? ($x, 0) : $x;
1764
+ }
1765
+
1766
+ sub _clog2 {
1767
+ # calculate ceil(log2($x))
1768
+
1769
+ my ($c, $x) = @_;
1770
+
1771
+ # X == 0 => NaN
1772
+
1773
+ return if @$x == 1 && $x->[0] == 0;
1774
+
1775
+ # X == 1 => 0 (is exact)
1776
+
1777
+ if (@$x == 1 && $x->[0] == 1) {
1778
+ @$x = 0;
1779
+ return wantarray ? ($x, 1) : $x;
1780
+ }
1781
+
1782
+ my $base = $c -> _two();
1783
+ my $acmp = $c -> _acmp($x, $base);
1784
+
1785
+ # X == BASE => 1 (is exact)
1786
+
1787
+ if ($acmp == 0) {
1788
+ @$x = 1;
1789
+ return wantarray ? ($x, 1) : $x;
1790
+ }
1791
+
1792
+ # 1 < X < BASE => 0 (is truncated)
1793
+
1794
+ if ($acmp < 0) {
1795
+ @$x = 0;
1796
+ return wantarray ? ($x, 0) : $x;
1797
+ }
1798
+
1799
+ # Compute a guess for the result based on:
1800
+ # $guess = int( length_in_base_10(X) / (log(base) / log(10)) )
1801
+
1802
+ my $len = $c -> _len($x);
1803
+ my $log = log(2) / log(10);
1804
+ my $guess = $c -> _new(int($len / $log));
1805
+ my $x_orig = $c -> _copy($x);
1806
+ @$x = @$guess;
1807
+
1808
+ my $trial = $c -> _pow($c -> _copy($base), $x);
1809
+ $acmp = $c -> _acmp($trial, $x_orig);
1810
+
1811
+ # Too big?
1812
+
1813
+ while ($acmp > 0) {
1814
+ $c -> _div($trial, $base);
1815
+ $c -> _dec($x);
1816
+ $acmp = $c -> _acmp($trial, $x_orig);
1817
+ }
1818
+
1819
+ # Too small?
1820
+
1821
+ while ($acmp < 0) {
1822
+ $c -> _mul($trial, $base);
1823
+ $c -> _inc($x);
1824
+ $acmp = $c -> _acmp($trial, $x_orig);
1825
+ }
1826
+
1827
+ return wantarray ? ($x, 1) : $x if $acmp == 0; # result is exact
1828
+ return wantarray ? ($x, 0) : $x; # result is too small
1829
+ }
1830
+
1831
+ sub _clog10 {
1832
+ # calculate ceil(log2($x))
1833
+ my ($c, $x) = @_;
1834
+
1835
+ # X == 0 => NaN
1836
+ return if @$x == 1 && $x->[0] == 0;
1837
+
1838
+ # X == 1 => 0 (is exact)
1839
+ if (@$x == 1 && $x->[0] == 1) {
1840
+ @$x = 0;
1841
+ return wantarray ? ($x, 1) : $x;
1842
+ }
1843
+
1844
+ # Get the number of base 10 digits. $n is the desired output, except when
1845
+ # $x is an exact power of 10, in which case $n is 1 too big.
1846
+
1847
+ my $n = $c -> _len($x);
1848
+
1849
+ # See if $x is an exact power of 10, in which case all but the most
1850
+ # significan chunks are 0, and the most significant chunk is a power of 10.
1851
+
1852
+ my $is_pow10 = 1;
1853
+ for my $i (0 .. $#$x - 1) {
1854
+ last unless $is_pow10 = $x->[$i] == 0;
1855
+ }
1856
+ $is_pow10 &&= $x->[-1] == 10**int(0.5 + log($x->[-1]) / log(10));
1857
+
1858
+ $n-- if $is_pow10;
1859
+
1860
+ my $xtmp = $c ->_new($n);
1861
+ @$x = @$xtmp;
1862
+
1863
+ return wantarray ? ($x, 1) : $x if $is_pow10; # result is exact
1864
+ return wantarray ? ($x, 0) : $x; # result is too small
1865
+ }
1866
+
1867
+ # for debugging:
1868
+ use constant DEBUG => 0;
1869
+ my $steps = 0;
1870
+ sub steps { $steps };
1871
+
1872
+ sub _sqrt {
1873
+ # square-root of $x in-place
1874
+
1875
+ my ($c, $x) = @_;
1876
+
1877
+ if (@$x == 1) {
1878
+ # fits into one Perl scalar, so result can be computed directly
1879
+ $x->[0] = int(sqrt($x->[0]));
1880
+ return $x;
1881
+ }
1882
+
1883
+ # Create an initial guess for the square root.
1884
+
1885
+ my $s;
1886
+ if (@$x % 2) {
1887
+ $s = [ (0) x ((@$x - 1) / 2), int(sqrt($x->[-1])) ];
1888
+ } else {
1889
+ $s = [ (0) x ((@$x - 2) / 2), int(sqrt($x->[-2] + $x->[-1] * $BASE)) ];
1890
+ }
1891
+
1892
+ # Newton's method for the square root of y:
1893
+ #
1894
+ # x(n) * x(n) - y
1895
+ # x(n+1) = x(n) - -----------------
1896
+ # 2 * x(n)
1897
+
1898
+ my $cmp;
1899
+ while (1) {
1900
+ my $sq = $c -> _mul($c -> _copy($s), $s);
1901
+ $cmp = $c -> _acmp($sq, $x);
1902
+
1903
+ # If x(n)*x(n) > y, compute
1904
+ #
1905
+ # x(n) * x(n) - y
1906
+ # x(n+1) = x(n) - -----------------
1907
+ # 2 * x(n)
1908
+
1909
+ if ($cmp > 0) {
1910
+ my $num = $c -> _sub($c -> _copy($sq), $x);
1911
+ my $den = $c -> _mul($c -> _two(), $s);
1912
+ my $delta = $c -> _div($num, $den);
1913
+ last if $c -> _is_zero($delta);
1914
+ $s = $c -> _sub($s, $delta);
1915
+ }
1916
+
1917
+ # If x(n)*x(n) < y, compute
1918
+ #
1919
+ # y - x(n) * x(n)
1920
+ # x(n+1) = x(n) + -----------------
1921
+ # 2 * x(n)
1922
+
1923
+ elsif ($cmp < 0) {
1924
+ my $num = $c -> _sub($c -> _copy($x), $sq);
1925
+ my $den = $c -> _mul($c -> _two(), $s);
1926
+ my $delta = $c -> _div($num, $den);
1927
+ last if $c -> _is_zero($delta);
1928
+ $s = $c -> _add($s, $delta);
1929
+ }
1930
+
1931
+ # If x(n)*x(n) = y, we have the exact result.
1932
+
1933
+ else {
1934
+ last;
1935
+ }
1936
+ }
1937
+
1938
+ $s = $c -> _dec($s) if $cmp > 0; # never overshoot
1939
+ @$x = @$s;
1940
+ return $x;
1941
+ }
1942
+
1943
+ sub _root {
1944
+ # Take n'th root of $x in place.
1945
+
1946
+ my ($c, $x, $n) = @_;
1947
+
1948
+ # Small numbers.
1949
+
1950
+ if (@$x == 1) {
1951
+ return $x if $x -> [0] == 0 || $x -> [0] == 1;
1952
+
1953
+ if (@$n == 1) {
1954
+ # Result can be computed directly. Adjust initial result for
1955
+ # numerical errors, e.g., int(1000**(1/3)) is 2, not 3.
1956
+ my $y = int($x->[0] ** (1 / $n->[0]));
1957
+ my $yp1 = $y + 1;
1958
+ $y = $yp1 if $yp1 ** $n->[0] == $x->[0];
1959
+ $x->[0] = $y;
1960
+ return $x;
1961
+ }
1962
+ }
1963
+
1964
+ # If x <= n, the result is always (truncated to) 1.
1965
+
1966
+ if ((@$x > 1 || $x -> [0] > 0) && # if x is non-zero ...
1967
+ $c -> _acmp($x, $n) <= 0) # ... and x <= n
1968
+ {
1969
+ my $one = $c -> _one();
1970
+ @$x = @$one;
1971
+ return $x;
1972
+ }
1973
+
1974
+ # If $n is a power of two, take sqrt($x) repeatedly, e.g., root($x, 4) =
1975
+ # sqrt(sqrt($x)), root($x, 8) = sqrt(sqrt(sqrt($x))).
1976
+
1977
+ my $b = $c -> _as_bin($n);
1978
+ if ($b =~ /0b1(0+)$/) {
1979
+ my $count = length($1); # 0b100 => len('00') => 2
1980
+ my $cnt = $count; # counter for loop
1981
+ unshift @$x, 0; # add one element, together with one
1982
+ # more below in the loop this makes 2
1983
+ while ($cnt-- > 0) {
1984
+ # 'Inflate' $x by adding one element, basically computing
1985
+ # $x * $BASE * $BASE. This gives us more $BASE_LEN digits for
1986
+ # result since len(sqrt($X)) approx == len($x) / 2.
1987
+ unshift @$x, 0;
1988
+ # Calculate sqrt($x), $x is now one element to big, again. In the
1989
+ # next round we make that two, again.
1990
+ $c -> _sqrt($x);
1991
+ }
1992
+
1993
+ # $x is now one element too big, so truncate result by removing it.
1994
+ shift @$x;
1995
+
1996
+ return $x;
1997
+ }
1998
+
1999
+ my $DEBUG = 0;
2000
+
2001
+ # Now the general case. This works by finding an initial guess. If this
2002
+ # guess is incorrect, a relatively small delta is chosen. This delta is
2003
+ # used to find a lower and upper limit for the correct value. The delta is
2004
+ # doubled in each iteration. When a lower and upper limit is found,
2005
+ # bisection is applied to narrow down the region until we have the correct
2006
+ # value.
2007
+
2008
+ # Split x into mantissa and exponent in base 10, so that
2009
+ #
2010
+ # x = xm * 10^xe, where 0 < xm < 1 and xe is an integer
2011
+
2012
+ my $x_str = $c -> _str($x);
2013
+ my $xm = "." . $x_str;
2014
+ my $xe = length($x_str);
2015
+
2016
+ # From this we compute the base 10 logarithm of x
2017
+ #
2018
+ # log_10(x) = log_10(xm) + log_10(xe^10)
2019
+ # = log(xm)/log(10) + xe
2020
+ #
2021
+ # and then the base 10 logarithm of y, where y = x^(1/n)
2022
+ #
2023
+ # log_10(y) = log_10(x)/n
2024
+
2025
+ my $log10x = log($xm) / log(10) + $xe;
2026
+ my $log10y = $log10x / $c -> _num($n);
2027
+
2028
+ # And from this we compute ym and ye, the mantissa and exponent (in
2029
+ # base 10) of y, where 1 < ym <= 10 and ye is an integer.
2030
+
2031
+ my $ye = int $log10y;
2032
+ my $ym = 10 ** ($log10y - $ye);
2033
+
2034
+ # Finally, we scale the mantissa and exponent to incraese the integer
2035
+ # part of ym, before building the string representing our guess of y.
2036
+
2037
+ if ($DEBUG) {
2038
+ print "\n";
2039
+ print "xm = $xm\n";
2040
+ print "xe = $xe\n";
2041
+ print "log10x = $log10x\n";
2042
+ print "log10y = $log10y\n";
2043
+ print "ym = $ym\n";
2044
+ print "ye = $ye\n";
2045
+ print "\n";
2046
+ }
2047
+
2048
+ my $d = $ye < 15 ? $ye : 15;
2049
+ $ym *= 10 ** $d;
2050
+ $ye -= $d;
2051
+
2052
+ my $y_str = sprintf('%.0f', $ym) . "0" x $ye;
2053
+ my $y = $c -> _new($y_str);
2054
+
2055
+ if ($DEBUG) {
2056
+ print "ym = $ym\n";
2057
+ print "ye = $ye\n";
2058
+ print "\n";
2059
+ print "y_str = $y_str (initial guess)\n";
2060
+ print "\n";
2061
+ }
2062
+
2063
+ # See if our guess y is correct.
2064
+
2065
+ my $trial = $c -> _pow($c -> _copy($y), $n);
2066
+ my $acmp = $c -> _acmp($trial, $x);
2067
+
2068
+ if ($acmp == 0) {
2069
+ @$x = @$y;
2070
+ return $x;
2071
+ }
2072
+
2073
+ # Find a lower and upper limit for the correct value of y. Start off with a
2074
+ # delta value that is approximately the size of the accuracy of the guess.
2075
+
2076
+ my $lower;
2077
+ my $upper;
2078
+
2079
+ my $delta = $c -> _new("1" . ("0" x $ye));
2080
+ my $two = $c -> _two();
2081
+
2082
+ if ($acmp < 0) {
2083
+ $lower = $y;
2084
+ while ($acmp < 0) {
2085
+ $upper = $c -> _add($c -> _copy($lower), $delta);
2086
+
2087
+ if ($DEBUG) {
2088
+ print "lower = $lower\n";
2089
+ print "upper = $upper\n";
2090
+ print "delta = $delta\n";
2091
+ print "\n";
2092
+ }
2093
+ $acmp = $c -> _acmp($c -> _pow($c -> _copy($upper), $n), $x);
2094
+ if ($acmp == 0) {
2095
+ @$x = @$upper;
2096
+ return $x;
2097
+ }
2098
+ $delta = $c -> _mul($delta, $two);
2099
+ }
2100
+ }
2101
+
2102
+ elsif ($acmp > 0) {
2103
+ $upper = $y;
2104
+ while ($acmp > 0) {
2105
+ if ($c -> _acmp($upper, $delta) <= 0) {
2106
+ $lower = $c -> _zero();
2107
+ last;
2108
+ }
2109
+ $lower = $c -> _sub($c -> _copy($upper), $delta);
2110
+
2111
+ if ($DEBUG) {
2112
+ print "lower = $lower\n";
2113
+ print "upper = $upper\n";
2114
+ print "delta = $delta\n";
2115
+ print "\n";
2116
+ }
2117
+ $acmp = $c -> _acmp($c -> _pow($c -> _copy($lower), $n), $x);
2118
+ if ($acmp == 0) {
2119
+ @$x = @$lower;
2120
+ return $x;
2121
+ }
2122
+ $delta = $c -> _mul($delta, $two);
2123
+ }
2124
+ }
2125
+
2126
+ # Use bisection to narrow down the interval.
2127
+
2128
+ my $one = $c -> _one();
2129
+ {
2130
+
2131
+ $delta = $c -> _sub($c -> _copy($upper), $lower);
2132
+ if ($c -> _acmp($delta, $one) <= 0) {
2133
+ @$x = @$lower;
2134
+ return $x;
2135
+ }
2136
+
2137
+ if ($DEBUG) {
2138
+ print "lower = $lower\n";
2139
+ print "upper = $upper\n";
2140
+ print "delta = $delta\n";
2141
+ print "\n";
2142
+ }
2143
+
2144
+ $delta = $c -> _div($delta, $two);
2145
+ my $middle = $c -> _add($c -> _copy($lower), $delta);
2146
+
2147
+ $acmp = $c -> _acmp($c -> _pow($c -> _copy($middle), $n), $x);
2148
+ if ($acmp < 0) {
2149
+ $lower = $middle;
2150
+ } elsif ($acmp > 0) {
2151
+ $upper = $middle;
2152
+ } else {
2153
+ @$x = @$middle;
2154
+ return $x;
2155
+ }
2156
+
2157
+ redo;
2158
+ }
2159
+
2160
+ $x;
2161
+ }
2162
+
2163
+ ##############################################################################
2164
+ # binary stuff
2165
+
2166
+ sub _and {
2167
+ my ($c, $x, $y) = @_;
2168
+
2169
+ # the shortcut makes equal, large numbers _really_ fast, and makes only a
2170
+ # very small performance drop for small numbers (e.g. something with less
2171
+ # than 32 bit) Since we optimize for large numbers, this is enabled.
2172
+ return $x if $c->_acmp($x, $y) == 0; # shortcut
2173
+
2174
+ my $m = $c->_one();
2175
+ my ($xr, $yr);
2176
+ my $mask = $AND_MASK;
2177
+
2178
+ my $x1 = $c->_copy($x);
2179
+ my $y1 = $c->_copy($y);
2180
+ my $z = $c->_zero();
2181
+
2182
+ use integer;
2183
+ until ($c->_is_zero($x1) || $c->_is_zero($y1)) {
2184
+ ($x1, $xr) = $c->_div($x1, $mask);
2185
+ ($y1, $yr) = $c->_div($y1, $mask);
2186
+
2187
+ $c->_add($z, $c->_mul([ 0 + $xr->[0] & 0 + $yr->[0] ], $m));
2188
+ $c->_mul($m, $mask);
2189
+ }
2190
+
2191
+ @$x = @$z;
2192
+ return $x;
2193
+ }
2194
+
2195
+ sub _xor {
2196
+ my ($c, $x, $y) = @_;
2197
+
2198
+ return $c->_zero() if $c->_acmp($x, $y) == 0; # shortcut (see -and)
2199
+
2200
+ my $m = $c->_one();
2201
+ my ($xr, $yr);
2202
+ my $mask = $XOR_MASK;
2203
+
2204
+ my $x1 = $c->_copy($x);
2205
+ my $y1 = $c->_copy($y); # make copy
2206
+ my $z = $c->_zero();
2207
+
2208
+ use integer;
2209
+ until ($c->_is_zero($x1) || $c->_is_zero($y1)) {
2210
+ ($x1, $xr) = $c->_div($x1, $mask);
2211
+ ($y1, $yr) = $c->_div($y1, $mask);
2212
+ # make ints() from $xr, $yr (see _and())
2213
+ #$b = 1; $xrr = 0; foreach (@$xr) { $xrr += $_ * $b; $b *= $BASE; }
2214
+ #$b = 1; $yrr = 0; foreach (@$yr) { $yrr += $_ * $b; $b *= $BASE; }
2215
+ #$c->_add($x, $c->_mul($c->_new($xrr ^ $yrr)), $m) );
2216
+
2217
+ $c->_add($z, $c->_mul([ 0 + $xr->[0] ^ 0 + $yr->[0] ], $m));
2218
+ $c->_mul($m, $mask);
2219
+ }
2220
+ # the loop stops when the shorter of the two numbers is exhausted
2221
+ # the remainder of the longer one will survive bit-by-bit, so we simple
2222
+ # multiply-add it in
2223
+ $c->_add($z, $c->_mul($x1, $m) ) if !$c->_is_zero($x1);
2224
+ $c->_add($z, $c->_mul($y1, $m) ) if !$c->_is_zero($y1);
2225
+
2226
+ @$x = @$z;
2227
+ return $x;
2228
+ }
2229
+
2230
+ sub _or {
2231
+ my ($c, $x, $y) = @_;
2232
+
2233
+ return $x if $c->_acmp($x, $y) == 0; # shortcut (see _and)
2234
+
2235
+ my $m = $c->_one();
2236
+ my ($xr, $yr);
2237
+ my $mask = $OR_MASK;
2238
+
2239
+ my $x1 = $c->_copy($x);
2240
+ my $y1 = $c->_copy($y); # make copy
2241
+ my $z = $c->_zero();
2242
+
2243
+ use integer;
2244
+ until ($c->_is_zero($x1) || $c->_is_zero($y1)) {
2245
+ ($x1, $xr) = $c->_div($x1, $mask);
2246
+ ($y1, $yr) = $c->_div($y1, $mask);
2247
+ # make ints() from $xr, $yr (see _and())
2248
+ # $b = 1; $xrr = 0; foreach (@$xr) { $xrr += $_ * $b; $b *= $BASE; }
2249
+ # $b = 1; $yrr = 0; foreach (@$yr) { $yrr += $_ * $b; $b *= $BASE; }
2250
+ # $c->_add($x, $c->_mul(_new( $c, ($xrr | $yrr) ), $m) );
2251
+ $c->_add($z, $c->_mul([ 0 + $xr->[0] | 0 + $yr->[0] ], $m));
2252
+ $c->_mul($m, $mask);
2253
+ }
2254
+ # the loop stops when the shorter of the two numbers is exhausted
2255
+ # the remainder of the longer one will survive bit-by-bit, so we simple
2256
+ # multiply-add it in
2257
+ $c->_add($z, $c->_mul($x1, $m) ) if !$c->_is_zero($x1);
2258
+ $c->_add($z, $c->_mul($y1, $m) ) if !$c->_is_zero($y1);
2259
+
2260
+ @$x = @$z;
2261
+ return $x;
2262
+ }
2263
+
2264
+ sub _as_hex {
2265
+ # convert a decimal number to hex (ref to array, return ref to string)
2266
+ my ($c, $x) = @_;
2267
+
2268
+ return "0x0" if @$x == 1 && $x->[0] == 0;
2269
+
2270
+ my $x1 = $c->_copy($x);
2271
+
2272
+ my $x10000 = [ 0x10000 ];
2273
+
2274
+ my $es = '';
2275
+ my $xr;
2276
+ until (@$x1 == 1 && $x1->[0] == 0) { # _is_zero()
2277
+ ($x1, $xr) = $c->_div($x1, $x10000);
2278
+ $es = sprintf('%04x', $xr->[0]) . $es;
2279
+ }
2280
+ #$es = reverse $es;
2281
+ $es =~ s/^0*/0x/;
2282
+ return $es;
2283
+ }
2284
+
2285
+ sub _as_bin {
2286
+ # convert a decimal number to bin (ref to array, return ref to string)
2287
+ my ($c, $x) = @_;
2288
+
2289
+ return "0b0" if @$x == 1 && $x->[0] == 0;
2290
+
2291
+ my $x1 = $c->_copy($x);
2292
+
2293
+ my $x10000 = [ 0x10000 ];
2294
+
2295
+ my $es = '';
2296
+ my $xr;
2297
+
2298
+ until (@$x1 == 1 && $x1->[0] == 0) { # _is_zero()
2299
+ ($x1, $xr) = $c->_div($x1, $x10000);
2300
+ $es = sprintf('%016b', $xr->[0]) . $es;
2301
+ }
2302
+ $es =~ s/^0*/0b/;
2303
+ return $es;
2304
+ }
2305
+
2306
+ sub _as_oct {
2307
+ # convert a decimal number to octal (ref to array, return ref to string)
2308
+ my ($c, $x) = @_;
2309
+
2310
+ return "00" if @$x == 1 && $x->[0] == 0;
2311
+
2312
+ my $x1 = $c->_copy($x);
2313
+
2314
+ my $x1000 = [ 1 << 15 ]; # 15 bits = 32768 = 0100000
2315
+
2316
+ my $es = '';
2317
+ my $xr;
2318
+ until (@$x1 == 1 && $x1->[0] == 0) { # _is_zero()
2319
+ ($x1, $xr) = $c->_div($x1, $x1000);
2320
+ $es = sprintf("%05o", $xr->[0]) . $es;
2321
+ }
2322
+ $es =~ s/^0*/0/; # excactly one leading zero
2323
+ return $es;
2324
+ }
2325
+
2326
+ sub _from_oct {
2327
+ # convert a octal number to decimal (string, return ref to array)
2328
+ my ($c, $os) = @_;
2329
+
2330
+ my $m = $c->_new(1 << 30); # 30 bits at a time (<32 bits!)
2331
+ my $d = 10; # 10 octal digits at a time
2332
+
2333
+ my $mul = $c->_one();
2334
+ my $x = $c->_zero();
2335
+
2336
+ my $len = int((length($os) - 1) / $d); # $d digit parts, w/o the '0'
2337
+ my $val;
2338
+ my $i = -$d;
2339
+ while ($len >= 0) {
2340
+ $val = substr($os, $i, $d); # get oct digits
2341
+ $val = CORE::oct($val);
2342
+ $i -= $d;
2343
+ $len --;
2344
+ my $adder = $c -> _new($val);
2345
+ $c->_add($x, $c->_mul($adder, $mul)) if $val != 0;
2346
+ $c->_mul($mul, $m) if $len >= 0; # skip last mul
2347
+ }
2348
+ $x;
2349
+ }
2350
+
2351
+ sub _from_hex {
2352
+ # convert a hex number to decimal (string, return ref to array)
2353
+ my ($c, $hs) = @_;
2354
+
2355
+ my $m = $c->_new(0x10000000); # 28 bit at a time (<32 bit!)
2356
+ my $d = 7; # 7 hexadecimal digits at a time
2357
+ my $mul = $c->_one();
2358
+ my $x = $c->_zero();
2359
+
2360
+ my $len = int((length($hs) - 2) / $d); # $d digit parts, w/o the '0x'
2361
+ my $val;
2362
+ my $i = -$d;
2363
+ while ($len >= 0) {
2364
+ $val = substr($hs, $i, $d); # get hex digits
2365
+ $val =~ s/^0x// if $len == 0; # for last part only because
2366
+ $val = CORE::hex($val); # hex does not like wrong chars
2367
+ $i -= $d;
2368
+ $len --;
2369
+ my $adder = $c->_new($val);
2370
+ # if the resulting number was to big to fit into one element, create a
2371
+ # two-element version (bug found by Mark Lakata - Thanx!)
2372
+ if (CORE::length($val) > $BASE_LEN) {
2373
+ $adder = $c->_new($val);
2374
+ }
2375
+ $c->_add($x, $c->_mul($adder, $mul)) if $val != 0;
2376
+ $c->_mul($mul, $m) if $len >= 0; # skip last mul
2377
+ }
2378
+ $x;
2379
+ }
2380
+
2381
+ sub _from_bin {
2382
+ # convert a hex number to decimal (string, return ref to array)
2383
+ my ($c, $bs) = @_;
2384
+
2385
+ # instead of converting X (8) bit at a time, it is faster to "convert" the
2386
+ # number to hex, and then call _from_hex.
2387
+
2388
+ my $hs = $bs;
2389
+ $hs =~ s/^[+-]?0b//; # remove sign and 0b
2390
+ my $l = length($hs); # bits
2391
+ $hs = '0' x (8 - ($l % 8)) . $hs if ($l % 8) != 0; # padd left side w/ 0
2392
+ my $h = '0x' . unpack('H*', pack ('B*', $hs)); # repack as hex
2393
+
2394
+ $c->_from_hex($h);
2395
+ }
2396
+
2397
+ ##############################################################################
2398
+ # special modulus functions
2399
+
2400
+ sub _modinv {
2401
+
2402
+ # modular multiplicative inverse
2403
+ my ($c, $x, $y) = @_;
2404
+
2405
+ # modulo zero
2406
+ if ($c->_is_zero($y)) {
2407
+ return;
2408
+ }
2409
+
2410
+ # modulo one
2411
+ if ($c->_is_one($y)) {
2412
+ return $c->_zero(), '+';
2413
+ }
2414
+
2415
+ my $u = $c->_zero();
2416
+ my $v = $c->_one();
2417
+ my $a = $c->_copy($y);
2418
+ my $b = $c->_copy($x);
2419
+
2420
+ # Euclid's Algorithm for bgcd(), only that we calc bgcd() ($a) and the result
2421
+ # ($u) at the same time. See comments in BigInt for why this works.
2422
+ my $q;
2423
+ my $sign = 1;
2424
+ {
2425
+ ($a, $q, $b) = ($b, $c->_div($a, $b)); # step 1
2426
+ last if $c->_is_zero($b);
2427
+
2428
+ my $t = $c->_add( # step 2:
2429
+ $c->_mul($c->_copy($v), $q), # t = v * q
2430
+ $u); # + u
2431
+ $u = $v; # u = v
2432
+ $v = $t; # v = t
2433
+ $sign = -$sign;
2434
+ redo;
2435
+ }
2436
+
2437
+ # if the gcd is not 1, then return NaN
2438
+ return unless $c->_is_one($a);
2439
+
2440
+ ($v, $sign == 1 ? '+' : '-');
2441
+ }
2442
+
2443
+ sub _modpow {
2444
+ # modulus of power ($x ** $y) % $z
2445
+ my ($c, $num, $exp, $mod) = @_;
2446
+
2447
+ # a^b (mod 1) = 0 for all a and b
2448
+ if ($c->_is_one($mod)) {
2449
+ @$num = 0;
2450
+ return $num;
2451
+ }
2452
+
2453
+ # 0^a (mod m) = 0 if m != 0, a != 0
2454
+ # 0^0 (mod m) = 1 if m != 0
2455
+ if ($c->_is_zero($num)) {
2456
+ if ($c->_is_zero($exp)) {
2457
+ @$num = 1;
2458
+ } else {
2459
+ @$num = 0;
2460
+ }
2461
+ return $num;
2462
+ }
2463
+
2464
+ # We could do the following, but it doesn't actually save any time. The
2465
+ # _copy() is needed in case $num and $mod are the same object.
2466
+ #$num = $c->_mod($c->_copy($num), $mod);
2467
+
2468
+ my $acc = $c->_copy($num);
2469
+ my $t = $c->_one();
2470
+
2471
+ my $expbin = $c->_to_bin($exp);
2472
+ my $len = length($expbin);
2473
+ while ($len--) {
2474
+ if (substr($expbin, $len, 1) eq '1') { # if odd
2475
+ $t = $c->_mul($t, $acc);
2476
+ $t = $c->_mod($t, $mod);
2477
+ }
2478
+ $acc = $c->_mul($acc, $acc);
2479
+ $acc = $c->_mod($acc, $mod);
2480
+ }
2481
+ @$num = @$t;
2482
+ $num;
2483
+ }
2484
+
2485
+ sub _gcd {
2486
+ # Greatest common divisor.
2487
+
2488
+ my ($c, $x, $y) = @_;
2489
+
2490
+ # gcd(0, 0) = 0
2491
+ # gcd(0, a) = a, if a != 0
2492
+
2493
+ if (@$x == 1 && $x->[0] == 0) {
2494
+ if (@$y == 1 && $y->[0] == 0) {
2495
+ @$x = 0;
2496
+ } else {
2497
+ @$x = @$y;
2498
+ }
2499
+ return $x;
2500
+ }
2501
+
2502
+ # Until $y is zero ...
2503
+
2504
+ until (@$y == 1 && $y->[0] == 0) {
2505
+
2506
+ # Compute remainder.
2507
+
2508
+ $c->_mod($x, $y);
2509
+
2510
+ # Swap $x and $y.
2511
+
2512
+ my $tmp = $c->_copy($x);
2513
+ @$x = @$y;
2514
+ $y = $tmp; # no deref here; that would modify input $y
2515
+ }
2516
+
2517
+ return $x;
2518
+ }
2519
+
2520
+ 1;
2521
+
2522
+ =pod
2523
+
2524
+ =head1 NAME
2525
+
2526
+ Math::BigInt::Calc - pure Perl module to support Math::BigInt
2527
+
2528
+ =head1 SYNOPSIS
2529
+
2530
+ # to use it with Math::BigInt
2531
+ use Math::BigInt lib => 'Calc';
2532
+
2533
+ # to use it with Math::BigFloat
2534
+ use Math::BigFloat lib => 'Calc';
2535
+
2536
+ # to use it with Math::BigRat
2537
+ use Math::BigRat lib => 'Calc';
2538
+
2539
+ # explicitly set base length and whether to "use integer"
2540
+ use Math::BigInt::Calc base_len => 4, use_int => 1;
2541
+ use Math::BigInt lib => 'Calc';
2542
+
2543
+ =head1 DESCRIPTION
2544
+
2545
+ Math::BigInt::Calc inherits from Math::BigInt::Lib.
2546
+
2547
+ In this library, the numbers are represented interenally in base B = 10**N,
2548
+ where N is the largest possible integer that does not cause overflow in the
2549
+ intermediate computations. The base B elements are stored in an array, with the
2550
+ least significant element stored in array element zero. There are no leading
2551
+ zero elements, except a single zero element when the number is zero. For
2552
+ instance, if B = 10000, the number 1234567890 is represented internally as
2553
+ [7890, 3456, 12].
2554
+
2555
+ =head1 OPTIONS
2556
+
2557
+ When the module is loaded, it computes the maximum exponent, i.e., power of 10,
2558
+ that can be used with and without "use integer" in the computations. The default
2559
+ is to use this maximum exponent. If the combination of the 'base_len' value and
2560
+ the 'use_int' value exceeds the maximum value, an error is thrown.
2561
+
2562
+ =over 4
2563
+
2564
+ =item base_len
2565
+
2566
+ The base length can be specified explicitly with the 'base_len' option. The
2567
+ value must be a positive integer.
2568
+
2569
+ use Math::BigInt::Calc base_len => 4; # use 10000 as internal base
2570
+
2571
+ =item use_int
2572
+
2573
+ This option is used to specify whether "use integer" should be used in the
2574
+ internal computations. The value is interpreted as a boolean value, so use 0 or
2575
+ "" for false and anything else for true. If the 'base_len' is not specified
2576
+ together with 'use_int', the current value for the base length is used.
2577
+
2578
+ use Math::BigInt::Calc use_int => 1; # use "use integer" internally
2579
+
2580
+ =back
2581
+
2582
+ =head1 METHODS
2583
+
2584
+ This overview constains only the methods that are specific to
2585
+ C<Math::BigInt::Calc>. For the other methods, see L<Math::BigInt::Lib>.
2586
+
2587
+ =over 4
2588
+
2589
+ =item _base_len()
2590
+
2591
+ Specify the desired base length and whether to enable "use integer" in the
2592
+ computations.
2593
+
2594
+ Math::BigInt::Calc -> _base_len($base_len, $use_int);
2595
+
2596
+ Note that it is better to specify the base length and whether to use integers as
2597
+ options when the module is loaded, for example like this
2598
+
2599
+ use Math::BigInt::Calc base_len => 6, use_int => 1;
2600
+
2601
+ =back
2602
+
2603
+ =head1 SEE ALSO
2604
+
2605
+ L<Math::BigInt::Lib> for a description of the API.
2606
+
2607
+ Alternative libraries L<Math::BigInt::FastCalc>, L<Math::BigInt::GMP>,
2608
+ L<Math::BigInt::Pari>, L<Math::BigInt::GMPz>, and L<Math::BigInt::BitVect>.
2609
+
2610
+ Some of the modules that use these libraries L<Math::BigInt>,
2611
+ L<Math::BigFloat>, and L<Math::BigRat>.
2612
+
2613
+ =cut
git/usr/share/perl5/core_perl/Math/BigInt/Lib.pm ADDED
@@ -0,0 +1,2773 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package Math::BigInt::Lib;
2
+
3
+ use 5.006001;
4
+ use strict;
5
+ use warnings;
6
+
7
+ our $VERSION = '2.005002';
8
+ $VERSION =~ tr/_//d;
9
+
10
+ use Carp;
11
+
12
+ use overload
13
+
14
+ # overload key: with_assign
15
+
16
+ '+' => sub {
17
+ my $class = ref $_[0];
18
+ my $x = $class -> _copy($_[0]);
19
+ my $y = ref($_[1]) ? $_[1] : $class -> _new($_[1]);
20
+ return $class -> _add($x, $y);
21
+ },
22
+
23
+ '-' => sub {
24
+ my $class = ref $_[0];
25
+ my ($x, $y);
26
+ if ($_[2]) { # if swapped
27
+ $y = $_[0];
28
+ $x = ref($_[1]) ? $_[1] : $class -> _new($_[1]);
29
+ } else {
30
+ $x = $class -> _copy($_[0]);
31
+ $y = ref($_[1]) ? $_[1] : $class -> _new($_[1]);
32
+ }
33
+ return $class -> _sub($x, $y);
34
+ },
35
+
36
+ '*' => sub {
37
+ my $class = ref $_[0];
38
+ my $x = $class -> _copy($_[0]);
39
+ my $y = ref($_[1]) ? $_[1] : $class -> _new($_[1]);
40
+ return $class -> _mul($x, $y);
41
+ },
42
+
43
+ '/' => sub {
44
+ my $class = ref $_[0];
45
+ my ($x, $y);
46
+ if ($_[2]) { # if swapped
47
+ $y = $_[0];
48
+ $x = ref($_[1]) ? $_[1] : $class -> _new($_[1]);
49
+ } else {
50
+ $x = $class -> _copy($_[0]);
51
+ $y = ref($_[1]) ? $_[1] : $class -> _new($_[1]);
52
+ }
53
+ return $class -> _div($x, $y);
54
+ },
55
+
56
+ '%' => sub {
57
+ my $class = ref $_[0];
58
+ my ($x, $y);
59
+ if ($_[2]) { # if swapped
60
+ $y = $_[0];
61
+ $x = ref($_[1]) ? $_[1] : $class -> _new($_[1]);
62
+ } else {
63
+ $x = $class -> _copy($_[0]);
64
+ $y = ref($_[1]) ? $_[1] : $class -> _new($_[1]);
65
+ }
66
+ return $class -> _mod($x, $y);
67
+ },
68
+
69
+ '**' => sub {
70
+ my $class = ref $_[0];
71
+ my ($x, $y);
72
+ if ($_[2]) { # if swapped
73
+ $y = $_[0];
74
+ $x = ref($_[1]) ? $_[1] : $class -> _new($_[1]);
75
+ } else {
76
+ $x = $class -> _copy($_[0]);
77
+ $y = ref($_[1]) ? $_[1] : $class -> _new($_[1]);
78
+ }
79
+ return $class -> _pow($x, $y);
80
+ },
81
+
82
+ '<<' => sub {
83
+ my $class = ref $_[0];
84
+ my ($x, $y);
85
+ if ($_[2]) { # if swapped
86
+ $y = $class -> _num($_[0]);
87
+ $x = ref($_[1]) ? $_[1] : $class -> _new($_[1]);
88
+ } else {
89
+ $x = $_[0];
90
+ $y = ref($_[1]) ? $class -> _num($_[1]) : $_[1];
91
+ }
92
+ return $class -> _lsft($x, $y);
93
+ },
94
+
95
+ '>>' => sub {
96
+ my $class = ref $_[0];
97
+ my ($x, $y);
98
+ if ($_[2]) { # if swapped
99
+ $y = $_[0];
100
+ $x = ref($_[1]) ? $_[1] : $class -> _new($_[1]);
101
+ } else {
102
+ $x = $class -> _copy($_[0]);
103
+ $y = ref($_[1]) ? $_[1] : $class -> _new($_[1]);
104
+ }
105
+ return $class -> _rsft($x, $y);
106
+ },
107
+
108
+ # overload key: num_comparison
109
+
110
+ '<' => sub {
111
+ my $class = ref $_[0];
112
+ my ($x, $y);
113
+ if ($_[2]) { # if swapped
114
+ $y = $_[0];
115
+ $x = ref($_[1]) ? $_[1] : $class -> _new($_[1]);
116
+ } else {
117
+ $x = $class -> _copy($_[0]);
118
+ $y = ref($_[1]) ? $_[1] : $class -> _new($_[1]);
119
+ }
120
+ return $class -> _acmp($x, $y) < 0;
121
+ },
122
+
123
+ '<=' => sub {
124
+ my $class = ref $_[0];
125
+ my ($x, $y);
126
+ if ($_[2]) { # if swapped
127
+ $y = $_[0];
128
+ $x = ref($_[1]) ? $_[1] : $class -> _new($_[1]);
129
+ } else {
130
+ $x = $class -> _copy($_[0]);
131
+ $y = ref($_[1]) ? $_[1] : $class -> _new($_[1]);
132
+ }
133
+ return $class -> _acmp($x, $y) <= 0;
134
+ },
135
+
136
+ '>' => sub {
137
+ my $class = ref $_[0];
138
+ my ($x, $y);
139
+ if ($_[2]) { # if swapped
140
+ $y = $_[0];
141
+ $x = ref($_[1]) ? $_[1] : $class -> _new($_[1]);
142
+ } else {
143
+ $x = $class -> _copy($_[0]);
144
+ $y = ref($_[1]) ? $_[1] : $class -> _new($_[1]);
145
+ }
146
+ return $class -> _acmp($x, $y) > 0;
147
+ },
148
+
149
+ '>=' => sub {
150
+ my $class = ref $_[0];
151
+ my ($x, $y);
152
+ if ($_[2]) { # if swapped
153
+ $y = $_[0];
154
+ $x = ref($_[1]) ? $_[1] : $class -> _new($_[1]);
155
+ } else {
156
+ $x = $class -> _copy($_[0]);
157
+ $y = ref($_[1]) ? $_[1] : $class -> _new($_[1]);
158
+ }
159
+ return $class -> _acmp($x, $y) >= 0;
160
+ },
161
+
162
+ '==' => sub {
163
+ my $class = ref $_[0];
164
+ my $x = $class -> _copy($_[0]);
165
+ my $y = ref($_[1]) ? $_[1] : $class -> _new($_[1]);
166
+ return $class -> _acmp($x, $y) == 0;
167
+ },
168
+
169
+ '!=' => sub {
170
+ my $class = ref $_[0];
171
+ my $x = $class -> _copy($_[0]);
172
+ my $y = ref($_[1]) ? $_[1] : $class -> _new($_[1]);
173
+ return $class -> _acmp($x, $y) != 0;
174
+ },
175
+
176
+ # overload key: 3way_comparison
177
+
178
+ '<=>' => sub {
179
+ my $class = ref $_[0];
180
+ my ($x, $y);
181
+ if ($_[2]) { # if swapped
182
+ $y = $_[0];
183
+ $x = ref($_[1]) ? $_[1] : $class -> _new($_[1]);
184
+ } else {
185
+ $x = $class -> _copy($_[0]);
186
+ $y = ref($_[1]) ? $_[1] : $class -> _new($_[1]);
187
+ }
188
+ return $class -> _acmp($x, $y);
189
+ },
190
+
191
+ # overload key: binary
192
+
193
+ '&' => sub {
194
+ my $class = ref $_[0];
195
+ my ($x, $y);
196
+ if ($_[2]) { # if swapped
197
+ $y = $_[0];
198
+ $x = ref($_[1]) ? $_[1] : $class -> _new($_[1]);
199
+ } else {
200
+ $x = $class -> _copy($_[0]);
201
+ $y = ref($_[1]) ? $_[1] : $class -> _new($_[1]);
202
+ }
203
+ return $class -> _and($x, $y);
204
+ },
205
+
206
+ '|' => sub {
207
+ my $class = ref $_[0];
208
+ my ($x, $y);
209
+ if ($_[2]) { # if swapped
210
+ $y = $_[0];
211
+ $x = ref($_[1]) ? $_[1] : $class -> _new($_[1]);
212
+ } else {
213
+ $x = $class -> _copy($_[0]);
214
+ $y = ref($_[1]) ? $_[1] : $class -> _new($_[1]);
215
+ }
216
+ return $class -> _or($x, $y);
217
+ },
218
+
219
+ '^' => sub {
220
+ my $class = ref $_[0];
221
+ my ($x, $y);
222
+ if ($_[2]) { # if swapped
223
+ $y = $_[0];
224
+ $x = ref($_[1]) ? $_[1] : $class -> _new($_[1]);
225
+ } else {
226
+ $x = $class -> _copy($_[0]);
227
+ $y = ref($_[1]) ? $_[1] : $class -> _new($_[1]);
228
+ }
229
+ return $class -> _xor($x, $y);
230
+ },
231
+
232
+ # overload key: func
233
+
234
+ 'abs' => sub { $_[0] },
235
+
236
+ 'sqrt' => sub {
237
+ my $class = ref $_[0];
238
+ return $class -> _sqrt($class -> _copy($_[0]));
239
+ },
240
+
241
+ 'int' => sub { $_[0] },
242
+
243
+ # overload key: conversion
244
+
245
+ 'bool' => sub { ref($_[0]) -> _is_zero($_[0]) ? '' : 1; },
246
+
247
+ '""' => sub { ref($_[0]) -> _str($_[0]); },
248
+
249
+ '0+' => sub { ref($_[0]) -> _num($_[0]); },
250
+
251
+ '=' => sub { ref($_[0]) -> _copy($_[0]); },
252
+
253
+ ;
254
+
255
+ sub _new {
256
+ croak "@{[(caller 0)[3]]} method not implemented";
257
+ }
258
+
259
+ sub _zero {
260
+ my $class = shift;
261
+ return $class -> _new("0");
262
+ }
263
+
264
+ sub _one {
265
+ my $class = shift;
266
+ return $class -> _new("1");
267
+ }
268
+
269
+ sub _two {
270
+ my $class = shift;
271
+ return $class -> _new("2");
272
+
273
+ }
274
+ sub _ten {
275
+ my $class = shift;
276
+ return $class -> _new("10");
277
+ }
278
+
279
+ sub _1ex {
280
+ my ($class, $exp) = @_;
281
+ $exp = $class -> _num($exp) if ref($exp);
282
+ return $class -> _new("1" . ("0" x $exp));
283
+ }
284
+
285
+ sub _copy {
286
+ my ($class, $x) = @_;
287
+ return $class -> _new($class -> _str($x));
288
+ }
289
+
290
+ # catch and throw away
291
+ sub import { }
292
+
293
+ ##############################################################################
294
+ # convert back to string and number
295
+
296
+ sub _str {
297
+ # Convert number from internal base 1eN format to string format. Internal
298
+ # format is always normalized, i.e., no leading zeros.
299
+ croak "@{[(caller 0)[3]]} method not implemented";
300
+ }
301
+
302
+ sub _num {
303
+ my ($class, $x) = @_;
304
+ 0 + $class -> _str($x);
305
+ }
306
+
307
+ ##############################################################################
308
+ # actual math code
309
+
310
+ sub _add {
311
+ croak "@{[(caller 0)[3]]} method not implemented";
312
+ }
313
+
314
+ sub _sub {
315
+ croak "@{[(caller 0)[3]]} method not implemented";
316
+ }
317
+
318
+ sub _mul {
319
+ my ($class, $x, $y) = @_;
320
+ my $sum = $class -> _zero();
321
+ my $i = $class -> _zero();
322
+ while ($class -> _acmp($i, $y) < 0) {
323
+ $sum = $class -> _add($sum, $x);
324
+ $i = $class -> _inc($i);
325
+ }
326
+ return $sum;
327
+ }
328
+
329
+ sub _div {
330
+ my ($class, $x, $y) = @_;
331
+
332
+ croak "@{[(caller 0)[3]]} requires non-zero divisor"
333
+ if $class -> _is_zero($y);
334
+
335
+ my $r = $class -> _copy($x);
336
+ my $q = $class -> _zero();
337
+ while ($class -> _acmp($r, $y) >= 0) {
338
+ $q = $class -> _inc($q);
339
+ $r = $class -> _sub($r, $y);
340
+ }
341
+
342
+ return $q, $r if wantarray;
343
+ return $q;
344
+ }
345
+
346
+ sub _inc {
347
+ my ($class, $x) = @_;
348
+ $class -> _add($x, $class -> _one());
349
+ }
350
+
351
+ sub _dec {
352
+ my ($class, $x) = @_;
353
+ $class -> _sub($x, $class -> _one());
354
+ }
355
+
356
+ # Signed addition. If the flag is false, $xa might be modified, but not $ya. If
357
+ # the false is true, $ya might be modified, but not $xa.
358
+
359
+ sub _sadd {
360
+ my $class = shift;
361
+ my ($xa, $xs, $ya, $ys, $flag) = @_;
362
+ my ($za, $zs);
363
+
364
+ # If the signs are equal we can add them (-5 + -3 => -(5 + 3) => -8)
365
+
366
+ if ($xs eq $ys) {
367
+ if ($flag) {
368
+ $za = $class -> _add($ya, $xa);
369
+ } else {
370
+ $za = $class -> _add($xa, $ya);
371
+ }
372
+ $zs = $class -> _is_zero($za) ? '+' : $xs;
373
+ return $za, $zs;
374
+ }
375
+
376
+ my $acmp = $class -> _acmp($xa, $ya); # abs(x) = abs(y)
377
+
378
+ if ($acmp == 0) { # x = -y or -x = y
379
+ $za = $class -> _zero();
380
+ $zs = '+';
381
+ return $za, $zs;
382
+ }
383
+
384
+ if ($acmp > 0) { # abs(x) > abs(y)
385
+ $za = $class -> _sub($xa, $ya, $flag);
386
+ $zs = $xs;
387
+ } else { # abs(x) < abs(y)
388
+ $za = $class -> _sub($ya, $xa, !$flag);
389
+ $zs = $ys;
390
+ }
391
+ return $za, $zs;
392
+ }
393
+
394
+ # Signed subtraction. If the flag is false, $xa might be modified, but not $ya.
395
+ # If the false is true, $ya might be modified, but not $xa.
396
+
397
+ sub _ssub {
398
+ my $class = shift;
399
+ my ($xa, $xs, $ya, $ys, $flag) = @_;
400
+
401
+ # Swap sign of second operand and let _sadd() do the job.
402
+ $ys = $ys eq '+' ? '-' : '+';
403
+ $class -> _sadd($xa, $xs, $ya, $ys, $flag);
404
+ }
405
+
406
+ ##############################################################################
407
+ # testing
408
+
409
+ sub _acmp {
410
+ # Compare two (absolute) values. Return -1, 0, or 1.
411
+ my ($class, $x, $y) = @_;
412
+ my $xstr = $class -> _str($x);
413
+ my $ystr = $class -> _str($y);
414
+
415
+ length($xstr) <=> length($ystr) || $xstr cmp $ystr;
416
+ }
417
+
418
+ sub _scmp {
419
+ # Compare two signed values. Return -1, 0, or 1.
420
+ my ($class, $xa, $xs, $ya, $ys) = @_;
421
+ if ($xs eq '+') {
422
+ if ($ys eq '+') {
423
+ return $class -> _acmp($xa, $ya);
424
+ } else {
425
+ return 1;
426
+ }
427
+ } else {
428
+ if ($ys eq '+') {
429
+ return -1;
430
+ } else {
431
+ return $class -> _acmp($ya, $xa);
432
+ }
433
+ }
434
+ }
435
+
436
+ sub _len {
437
+ my ($class, $x) = @_;
438
+ CORE::length($class -> _str($x));
439
+ }
440
+
441
+ sub _alen {
442
+ my ($class, $x) = @_;
443
+ $class -> _len($x);
444
+ }
445
+
446
+ sub _digit {
447
+ my ($class, $x, $n) = @_;
448
+ substr($class ->_str($x), -($n+1), 1);
449
+ }
450
+
451
+ sub _digitsum {
452
+ my ($class, $x) = @_;
453
+
454
+ my $len = $class -> _len($x);
455
+ my $sum = $class -> _zero();
456
+ for (my $i = 0 ; $i < $len ; ++$i) {
457
+ my $digit = $class -> _digit($x, $i);
458
+ $digit = $class -> _new($digit);
459
+ $sum = $class -> _add($sum, $digit);
460
+ }
461
+
462
+ return $sum;
463
+ }
464
+
465
+ sub _zeros {
466
+ my ($class, $x) = @_;
467
+ my $str = $class -> _str($x);
468
+ $str =~ /[^0](0*)\z/ ? CORE::length($1) : 0;
469
+ }
470
+
471
+ ##############################################################################
472
+ # _is_* routines
473
+
474
+ sub _is_zero {
475
+ # return true if arg is zero
476
+ my ($class, $x) = @_;
477
+ $class -> _str($x) == 0;
478
+ }
479
+
480
+ sub _is_even {
481
+ # return true if arg is even
482
+ my ($class, $x) = @_;
483
+ substr($class -> _str($x), -1, 1) % 2 == 0;
484
+ }
485
+
486
+ sub _is_odd {
487
+ # return true if arg is odd
488
+ my ($class, $x) = @_;
489
+ substr($class -> _str($x), -1, 1) % 2 != 0;
490
+ }
491
+
492
+ sub _is_one {
493
+ # return true if arg is one
494
+ my ($class, $x) = @_;
495
+ $class -> _str($x) == 1;
496
+ }
497
+
498
+ sub _is_two {
499
+ # return true if arg is two
500
+ my ($class, $x) = @_;
501
+ $class -> _str($x) == 2;
502
+ }
503
+
504
+ sub _is_ten {
505
+ # return true if arg is ten
506
+ my ($class, $x) = @_;
507
+ $class -> _str($x) == 10;
508
+ }
509
+
510
+ ###############################################################################
511
+ # check routine to test internal state for corruptions
512
+
513
+ sub _check {
514
+ # used by the test suite
515
+ my ($class, $x) = @_;
516
+ return "Input is undefined" unless defined $x;
517
+ return "$x is not a reference" unless ref($x);
518
+ return 0;
519
+ }
520
+
521
+ ###############################################################################
522
+
523
+ sub _mod {
524
+ # modulus
525
+ my ($class, $x, $y) = @_;
526
+
527
+ croak "@{[(caller 0)[3]]} requires non-zero second operand"
528
+ if $class -> _is_zero($y);
529
+
530
+ if ($class -> can('_div')) {
531
+ $x = $class -> _copy($x);
532
+ my ($q, $r) = $class -> _div($x, $y);
533
+ return $r;
534
+ } else {
535
+ my $r = $class -> _copy($x);
536
+ while ($class -> _acmp($r, $y) >= 0) {
537
+ $r = $class -> _sub($r, $y);
538
+ }
539
+ return $r;
540
+ }
541
+ }
542
+
543
+ ##############################################################################
544
+ # shifts
545
+
546
+ sub _rsft {
547
+ my ($class, $x, $n, $b) = @_;
548
+ $b = $class -> _new($b) unless ref $b;
549
+ return scalar $class -> _div($x, $class -> _pow($class -> _copy($b), $n));
550
+ }
551
+
552
+ sub _lsft {
553
+ my ($class, $x, $n, $b) = @_;
554
+ $b = $class -> _new($b) unless ref $b;
555
+ return $class -> _mul($x, $class -> _pow($class -> _copy($b), $n));
556
+ }
557
+
558
+ sub _pow {
559
+ # power of $x to $y
560
+ my ($class, $x, $y) = @_;
561
+
562
+ if ($class -> _is_zero($y)) {
563
+ return $class -> _one(); # y == 0 => x => 1
564
+ }
565
+
566
+ if (($class -> _is_one($x)) || # x == 1
567
+ ($class -> _is_one($y))) # or y == 1
568
+ {
569
+ return $x;
570
+ }
571
+
572
+ if ($class -> _is_zero($x)) {
573
+ return $class -> _zero(); # 0 ** y => 0 (if not y <= 0)
574
+ }
575
+
576
+ my $pow2 = $class -> _one();
577
+
578
+ my $y_bin = $class -> _as_bin($y);
579
+ $y_bin =~ s/^0b//;
580
+ my $len = length($y_bin);
581
+
582
+ while (--$len > 0) {
583
+ $pow2 = $class -> _mul($pow2, $x) if substr($y_bin, $len, 1) eq '1';
584
+ $x = $class -> _mul($x, $x);
585
+ }
586
+
587
+ $x = $class -> _mul($x, $pow2);
588
+ return $x;
589
+ }
590
+
591
+ sub _nok {
592
+ # Return binomial coefficient (n over k).
593
+ my ($class, $n, $k) = @_;
594
+
595
+ # If k > n/2, or, equivalently, 2*k > n, compute nok(n, k) as
596
+ # nok(n, n-k), to minimize the number if iterations in the loop.
597
+
598
+ {
599
+ my $twok = $class -> _mul($class -> _two(), $class -> _copy($k));
600
+ if ($class -> _acmp($twok, $n) > 0) {
601
+ $k = $class -> _sub($class -> _copy($n), $k);
602
+ }
603
+ }
604
+
605
+ # Example:
606
+ #
607
+ # / 7 \ 7! 1*2*3*4 * 5*6*7 5 * 6 * 7
608
+ # | | = --------- = --------------- = --------- = ((5 * 6) / 2 * 7) / 3
609
+ # \ 3 / (7-3)! 3! 1*2*3*4 * 1*2*3 1 * 2 * 3
610
+ #
611
+ # Equivalently, _nok(11, 5) is computed as
612
+ #
613
+ # (((((((7 * 8) / 2) * 9) / 3) * 10) / 4) * 11) / 5
614
+
615
+ if ($class -> _is_zero($k)) {
616
+ return $class -> _one();
617
+ }
618
+
619
+ # Make a copy of the original n, in case the subclass modifies n in-place.
620
+
621
+ my $n_orig = $class -> _copy($n);
622
+
623
+ # n = 5, f = 6, d = 2 (cf. example above)
624
+
625
+ $n = $class -> _sub($n, $k);
626
+ $n = $class -> _inc($n);
627
+
628
+ my $f = $class -> _copy($n);
629
+ $f = $class -> _inc($f);
630
+
631
+ my $d = $class -> _two();
632
+
633
+ # while f <= n (the original n, that is) ...
634
+
635
+ while ($class -> _acmp($f, $n_orig) <= 0) {
636
+ $n = $class -> _mul($n, $f);
637
+ $n = $class -> _div($n, $d);
638
+ $f = $class -> _inc($f);
639
+ $d = $class -> _inc($d);
640
+ }
641
+
642
+ return $n;
643
+ }
644
+
645
+ #sub _fac {
646
+ # # factorial
647
+ # my ($class, $x) = @_;
648
+ #
649
+ # my $two = $class -> _two();
650
+ #
651
+ # if ($class -> _acmp($x, $two) < 0) {
652
+ # return $class -> _one();
653
+ # }
654
+ #
655
+ # my $i = $class -> _copy($x);
656
+ # while ($class -> _acmp($i, $two) > 0) {
657
+ # $i = $class -> _dec($i);
658
+ # $x = $class -> _mul($x, $i);
659
+ # }
660
+ #
661
+ # return $x;
662
+ #}
663
+
664
+ sub _fac {
665
+ # factorial
666
+ my ($class, $x) = @_;
667
+
668
+ # This is an implementation of the split recursive algorithm. See
669
+ # http://www.luschny.de/math/factorial/csharp/FactorialSplit.cs.html
670
+
671
+ my $p = $class -> _one();
672
+ my $r = $class -> _one();
673
+ my $two = $class -> _two();
674
+
675
+ my ($log2n) = $class -> _log_int($class -> _copy($x), $two);
676
+ my $h = $class -> _zero();
677
+ my $shift = $class -> _zero();
678
+ my $k = $class -> _one();
679
+
680
+ while ($class -> _acmp($h, $x)) {
681
+ $shift = $class -> _add($shift, $h);
682
+ $h = $class -> _rsft($class -> _copy($x), $log2n, $two);
683
+ $log2n = $class -> _dec($log2n) if !$class -> _is_zero($log2n);
684
+ my $high = $class -> _copy($h);
685
+ $high = $class -> _dec($high) if $class -> _is_even($h);
686
+ while ($class -> _acmp($k, $high)) {
687
+ $k = $class -> _add($k, $two);
688
+ $p = $class -> _mul($p, $k);
689
+ }
690
+ $r = $class -> _mul($r, $p);
691
+ }
692
+ return $class -> _lsft($r, $shift, $two);
693
+ }
694
+
695
+ sub _dfac {
696
+ # double factorial
697
+ my ($class, $x) = @_;
698
+
699
+ my $two = $class -> _two();
700
+
701
+ if ($class -> _acmp($x, $two) < 0) {
702
+ return $class -> _one();
703
+ }
704
+
705
+ my $i = $class -> _copy($x);
706
+ while ($class -> _acmp($i, $two) > 0) {
707
+ $i = $class -> _sub($i, $two);
708
+ $x = $class -> _mul($x, $i);
709
+ }
710
+
711
+ return $x;
712
+ }
713
+
714
+ sub _log_int {
715
+ # calculate integer log of $x to base $base
716
+ # calculate integer log of $x to base $base
717
+ # ref to array, ref to array - return ref to array
718
+ my ($class, $x, $base) = @_;
719
+
720
+ # X == 0 => NaN
721
+ return if $class -> _is_zero($x);
722
+
723
+ $base = $class -> _new(2) unless defined($base);
724
+ $base = $class -> _new($base) unless ref($base);
725
+
726
+ # BASE 0 or 1 => NaN
727
+ return if $class -> _is_zero($base) || $class -> _is_one($base);
728
+
729
+ # X == 1 => 0 (is exact)
730
+ if ($class -> _is_one($x)) {
731
+ return $class -> _zero(), 1 if wantarray;
732
+ return $class -> _zero();
733
+ }
734
+
735
+ my $cmp = $class -> _acmp($x, $base);
736
+
737
+ # X == BASE => 1 (is exact)
738
+ if ($cmp == 0) {
739
+ return $class -> _one(), 1 if wantarray;
740
+ return $class -> _one();
741
+ }
742
+
743
+ # 1 < X < BASE => 0 (is truncated)
744
+ if ($cmp < 0) {
745
+ return $class -> _zero(), 0 if wantarray;
746
+ return $class -> _zero();
747
+ }
748
+
749
+ my $y;
750
+
751
+ # log(x) / log(b) = log(xm * 10^xe) / log(bm * 10^be)
752
+ # = (log(xm) + xe*(log(10))) / (log(bm) + be*log(10))
753
+
754
+ {
755
+ my $x_str = $class -> _str($x);
756
+ my $b_str = $class -> _str($base);
757
+ my $xm = "." . $x_str;
758
+ my $bm = "." . $b_str;
759
+ my $xe = length($x_str);
760
+ my $be = length($b_str);
761
+ my $log10 = log(10);
762
+ my $guess = int((log($xm) + $xe * $log10) / (log($bm) + $be * $log10));
763
+ $y = $class -> _new($guess);
764
+ }
765
+
766
+ my $trial = $class -> _pow($class -> _copy($base), $y);
767
+ my $acmp = $class -> _acmp($trial, $x);
768
+
769
+ # Too small?
770
+
771
+ while ($acmp < 0) {
772
+ $trial = $class -> _mul($trial, $base);
773
+ $y = $class -> _inc($y);
774
+ $acmp = $class -> _acmp($trial, $x);
775
+ }
776
+
777
+ # Too big?
778
+
779
+ while ($acmp > 0) {
780
+ $trial = $class -> _div($trial, $base);
781
+ $y = $class -> _dec($y);
782
+ $acmp = $class -> _acmp($trial, $x);
783
+ }
784
+
785
+ return wantarray ? ($y, 1) : $y if $acmp == 0; # result is exact
786
+ return wantarray ? ($y, 0) : $y; # result is too small
787
+ }
788
+
789
+ sub _ilog2 {
790
+ my ($class, $x) = @_;
791
+
792
+ return if $class -> _is_zero($x);
793
+
794
+ my $str = $class -> _to_hex($x);
795
+
796
+ # First do the bits in all but the most significant hex digit.
797
+
798
+ my $y = $class -> _new(length($str) - 1);
799
+ $y = $class -> _mul($y, $class -> _new(4));
800
+
801
+ # Now add the number of bits in the most significant hex digit.
802
+
803
+ my $n = int log(hex(substr($str, 0, 1))) / log(2);
804
+ $y = $class -> _add($y, $class -> _new($n));
805
+ return $y unless wantarray;
806
+
807
+ my $pow2 = $class -> _lsft($class -> _one(), $y, 2);
808
+ my $is_exact = $class -> _acmp($x, $pow2) == 0 ? 1 : 0;
809
+ return $y, $is_exact;
810
+ }
811
+
812
+ sub _ilog10 {
813
+ my ($class, $x) = @_;
814
+
815
+ return if $class -> _is_zero($x);
816
+
817
+ my $str = $class -> _str($x);
818
+ my $len = length($str);
819
+ my $y = $class -> _new($len - 1);
820
+ return $y unless wantarray;
821
+
822
+ #my $pow10 = $class -> _1ex($y);
823
+ #my $is_exact = $class -> _acmp($x, $pow10) ? 1 : 0;
824
+
825
+ my $is_exact = $str =~ /^10*$/ ? 1 : 0;
826
+ return $y, $is_exact;
827
+ }
828
+
829
+ sub _clog2 {
830
+ my ($class, $x) = @_;
831
+
832
+ return if $class -> _is_zero($x);
833
+
834
+ my $str = $class -> _to_hex($x);
835
+
836
+ # First do the bits in all but the most significant hex digit.
837
+
838
+ my $y = $class -> _new(length($str) - 1);
839
+ $y = $class -> _mul($y, $class -> _new(4));
840
+
841
+ # Now add the number of bits in the most significant hex digit.
842
+
843
+ my $n = int log(hex(substr($str, 0, 1))) / log(2);
844
+ $y = $class -> _add($y, $class -> _new($n));
845
+
846
+ # $y is now 1 too small unless $y is an exact power of 2.
847
+
848
+ my $pow2 = $class -> _lsft($class -> _one(), $y, 2);
849
+ my $is_exact = $class -> _acmp($x, $pow2) == 0 ? 1 : 0;
850
+ $y = $class -> _inc($y) if $is_exact == 0;
851
+ return $y, $is_exact if wantarray;
852
+ return $y;
853
+ }
854
+
855
+ sub _clog10 {
856
+ my ($class, $x) = @_;
857
+
858
+ return if $class -> _is_zero($x);
859
+
860
+ my $str = $class -> _str($x);
861
+ my $len = length($str);
862
+
863
+ if ($str =~ /^10*$/) {
864
+ my $y = $class -> _new($len - 1);
865
+ return $y, 1 if wantarray;
866
+ return $y;
867
+ }
868
+
869
+ my $y = $class -> _new($len);
870
+ return $y, 0 if wantarray;
871
+ return $y;
872
+ }
873
+
874
+ sub _sqrt {
875
+ # square-root of $y in place
876
+ my ($class, $y) = @_;
877
+
878
+ return $y if $class -> _is_zero($y);
879
+
880
+ my $y_str = $class -> _str($y);
881
+ my $y_len = length($y_str);
882
+
883
+ # Compute the guess $x.
884
+
885
+ my $xm;
886
+ my $xe;
887
+ if ($y_len % 2 == 0) {
888
+ $xm = sqrt("." . $y_str);
889
+ $xe = $y_len / 2;
890
+ $xm = sprintf "%.0f", int($xm * 1e15);
891
+ $xe -= 15;
892
+ } else {
893
+ $xm = sqrt(".0" . $y_str);
894
+ $xe = ($y_len + 1) / 2;
895
+ $xm = sprintf "%.0f", int($xm * 1e16);
896
+ $xe -= 16;
897
+ }
898
+
899
+ my $x;
900
+ if ($xe < 0) {
901
+ $x = substr $xm, 0, length($xm) + $xe;
902
+ } else {
903
+ $x = $xm . ("0" x $xe);
904
+ }
905
+
906
+ $x = $class -> _new($x);
907
+
908
+ # Newton's method for computing square root of y
909
+ #
910
+ # x(i+1) = x(i) - f(x(i)) / f'(x(i))
911
+ # = x(i) - (x(i)^2 - y) / (2 * x(i)) # use if x(i)^2 > y
912
+ # = x(i) + (y - x(i)^2) / (2 * x(i)) # use if x(i)^2 < y
913
+
914
+ # Determine if x, our guess, is too small, correct, or too large.
915
+
916
+ my $xsq = $class -> _mul($class -> _copy($x), $x); # x(i)^2
917
+ my $acmp = $class -> _acmp($xsq, $y); # x(i)^2 <=> y
918
+
919
+ # Only assign a value to this variable if we will be using it.
920
+
921
+ my $two;
922
+ $two = $class -> _two() if $acmp != 0;
923
+
924
+ # If x is too small, do one iteration of Newton's method. Since the
925
+ # function f(x) = x^2 - y is concave and monotonically increasing, the next
926
+ # guess for x will either be correct or too large.
927
+
928
+ if ($acmp < 0) {
929
+
930
+ # x(i+1) = x(i) + (y - x(i)^2) / (2 * x(i))
931
+
932
+ my $numer = $class -> _sub($class -> _copy($y), $xsq); # y - x(i)^2
933
+ my $denom = $class -> _mul($class -> _copy($two), $x); # 2 * x(i)
934
+ my $delta = $class -> _div($numer, $denom);
935
+
936
+ unless ($class -> _is_zero($delta)) {
937
+ $x = $class -> _add($x, $delta);
938
+ $xsq = $class -> _mul($class -> _copy($x), $x); # x(i)^2
939
+ $acmp = $class -> _acmp($xsq, $y); # x(i)^2 <=> y
940
+ }
941
+ }
942
+
943
+ # If our guess for x is too large, apply Newton's method repeatedly until
944
+ # we either have got the correct value, or the delta is zero.
945
+
946
+ while ($acmp > 0) {
947
+
948
+ # x(i+1) = x(i) - (x(i)^2 - y) / (2 * x(i))
949
+
950
+ my $numer = $class -> _sub($xsq, $y); # x(i)^2 - y
951
+ my $denom = $class -> _mul($class -> _copy($two), $x); # 2 * x(i)
952
+ my $delta = $class -> _div($numer, $denom);
953
+ last if $class -> _is_zero($delta);
954
+
955
+ $x = $class -> _sub($x, $delta);
956
+ $xsq = $class -> _mul($class -> _copy($x), $x); # x(i)^2
957
+ $acmp = $class -> _acmp($xsq, $y); # x(i)^2 <=> y
958
+ }
959
+
960
+ # When the delta is zero, our value for x might still be too large. We
961
+ # require that the outout is either exact or too small (i.e., rounded down
962
+ # to the nearest integer), so do a final check.
963
+
964
+ while ($acmp > 0) {
965
+ $x = $class -> _dec($x);
966
+ $xsq = $class -> _mul($class -> _copy($x), $x); # x(i)^2
967
+ $acmp = $class -> _acmp($xsq, $y); # x(i)^2 <=> y
968
+ }
969
+
970
+ return $x;
971
+ }
972
+
973
+ sub _root {
974
+ my ($class, $y, $n) = @_;
975
+
976
+ return $y if $class -> _is_zero($y) || $class -> _is_one($y) ||
977
+ $class -> _is_one($n);
978
+
979
+ # If y <= n, the result is always (truncated to) 1.
980
+
981
+ return $class -> _one() if $class -> _acmp($y, $n) <= 0;
982
+
983
+ # Compute the initial guess x of y^(1/n). When n is large, Newton's method
984
+ # converges slowly if the "guess" (initial value) is poor, so we need a
985
+ # good guess. It the guess is too small, the next guess will be too large,
986
+ # and from then on all guesses are too large.
987
+
988
+ my $DEBUG = 0;
989
+
990
+ # Split y into mantissa and exponent in base 10, so that
991
+ #
992
+ # y = xm * 10^xe, where 0 < xm < 1 and xe is an integer
993
+
994
+ my $y_str = $class -> _str($y);
995
+ my $ym = "." . $y_str;
996
+ my $ye = length($y_str);
997
+
998
+ # From this compute the approximate base 10 logarithm of y
999
+ #
1000
+ # log_10(y) = log_10(ym) + log_10(ye^10)
1001
+ # = log(ym)/log(10) + ye
1002
+
1003
+ my $log10y = log($ym) / log(10) + $ye;
1004
+
1005
+ # And from this compute the approximate base 10 logarithm of x, where
1006
+ # x = y^(1/n)
1007
+ #
1008
+ # log_10(x) = log_10(y)/n
1009
+
1010
+ my $log10x = $log10y / $class -> _num($n);
1011
+
1012
+ # From this compute xm and xe, the mantissa and exponent (in base 10) of x,
1013
+ # where 1 < xm <= 10 and xe is an integer.
1014
+
1015
+ my $xe = int $log10x;
1016
+ my $xm = 10 ** ($log10x - $xe);
1017
+
1018
+ # Scale the mantissa and exponent to increase the integer part of ym, which
1019
+ # gives us better accuracy.
1020
+
1021
+ if ($DEBUG) {
1022
+ print "\n";
1023
+ print "y_str = $y_str\n";
1024
+ print "ym = $ym\n";
1025
+ print "ye = $ye\n";
1026
+ print "log10y = $log10y\n";
1027
+ print "log10x = $log10x\n";
1028
+ print "xm = $xm\n";
1029
+ print "xe = $xe\n";
1030
+ }
1031
+
1032
+ my $d = $xe < 15 ? $xe : 15;
1033
+ $xm *= 10 ** $d;
1034
+ $xe -= $d;
1035
+
1036
+ if ($DEBUG) {
1037
+ print "\n";
1038
+ print "xm = $xm\n";
1039
+ print "xe = $xe\n";
1040
+ }
1041
+
1042
+ # If the mantissa is not an integer, round up to nearest integer, and then
1043
+ # convert the number to a string. It is important to always round up due to
1044
+ # how Newton's method behaves in this case. If the initial guess is too
1045
+ # small, the next guess will be too large, after which every succeeding
1046
+ # guess converges the correct value from above. Now, if the initial guess
1047
+ # is too small and n is large, the next guess will be much too large and
1048
+ # require a large number of iterations to get close to the solution.
1049
+ # Because of this, we are likely to find the solution faster if we make
1050
+ # sure the initial guess is not too small.
1051
+
1052
+ my $xm_int = int($xm);
1053
+ my $x_str = sprintf '%.0f', $xm > $xm_int ? $xm_int + 1 : $xm_int;
1054
+ $x_str .= "0" x $xe;
1055
+
1056
+ my $x = $class -> _new($x_str);
1057
+
1058
+ if ($DEBUG) {
1059
+ print "xm = $xm\n";
1060
+ print "xe = $xe\n";
1061
+ print "\n";
1062
+ print "x_str = $x_str (initial guess)\n";
1063
+ print "\n";
1064
+ }
1065
+
1066
+ # Use Newton's method for computing n'th root of y.
1067
+ #
1068
+ # x(i+1) = x(i) - f(x(i)) / f'(x(i))
1069
+ # = x(i) - (x(i)^n - y) / (n * x(i)^(n-1)) # use if x(i)^n > y
1070
+ # = x(i) + (y - x(i)^n) / (n * x(i)^(n-1)) # use if x(i)^n < y
1071
+
1072
+ # Determine if x, our guess, is too small, correct, or too large. Rather
1073
+ # than computing x(i)^n and x(i)^(n-1) directly, compute x(i)^(n-1) and
1074
+ # then the same value multiplied by x.
1075
+
1076
+ my $nm1 = $class -> _dec($class -> _copy($n)); # n-1
1077
+ my $xpownm1 = $class -> _pow($class -> _copy($x), $nm1); # x(i)^(n-1)
1078
+ my $xpown = $class -> _mul($class -> _copy($xpownm1), $x); # x(i)^n
1079
+ my $acmp = $class -> _acmp($xpown, $y); # x(i)^n <=> y
1080
+
1081
+ if ($DEBUG) {
1082
+ print "\n";
1083
+ print "x = ", $class -> _str($x), "\n";
1084
+ print "x^n = ", $class -> _str($xpown), "\n";
1085
+ print "y = ", $class -> _str($y), "\n";
1086
+ print "acmp = $acmp\n";
1087
+ }
1088
+
1089
+ # If x is too small, do one iteration of Newton's method. Since the
1090
+ # function f(x) = x^n - y is concave and monotonically increasing, the next
1091
+ # guess for x will either be correct or too large.
1092
+
1093
+ if ($acmp < 0) {
1094
+
1095
+ # x(i+1) = x(i) + (y - x(i)^n) / (n * x(i)^(n-1))
1096
+
1097
+ my $numer = $class -> _sub($class -> _copy($y), $xpown); # y - x(i)^n
1098
+ my $denom = $class -> _mul($class -> _copy($n), $xpownm1); # n * x(i)^(n-1)
1099
+ my $delta = $class -> _div($numer, $denom);
1100
+
1101
+ if ($DEBUG) {
1102
+ print "\n";
1103
+ print "numer = ", $class -> _str($numer), "\n";
1104
+ print "denom = ", $class -> _str($denom), "\n";
1105
+ print "delta = ", $class -> _str($delta), "\n";
1106
+ }
1107
+
1108
+ unless ($class -> _is_zero($delta)) {
1109
+ $x = $class -> _add($x, $delta);
1110
+ $xpownm1 = $class -> _pow($class -> _copy($x), $nm1); # x(i)^(n-1)
1111
+ $xpown = $class -> _mul($class -> _copy($xpownm1), $x); # x(i)^n
1112
+ $acmp = $class -> _acmp($xpown, $y); # x(i)^n <=> y
1113
+
1114
+ if ($DEBUG) {
1115
+ print "\n";
1116
+ print "x = ", $class -> _str($x), "\n";
1117
+ print "x^n = ", $class -> _str($xpown), "\n";
1118
+ print "y = ", $class -> _str($y), "\n";
1119
+ print "acmp = $acmp\n";
1120
+ }
1121
+ }
1122
+ }
1123
+
1124
+ # If our guess for x is too large, apply Newton's method repeatedly until
1125
+ # we either have got the correct value, or the delta is zero.
1126
+
1127
+ while ($acmp > 0) {
1128
+
1129
+ # x(i+1) = x(i) - (x(i)^n - y) / (n * x(i)^(n-1))
1130
+
1131
+ my $numer = $class -> _sub($class -> _copy($xpown), $y); # x(i)^n - y
1132
+ my $denom = $class -> _mul($class -> _copy($n), $xpownm1); # n * x(i)^(n-1)
1133
+
1134
+ if ($DEBUG) {
1135
+ print "numer = ", $class -> _str($numer), "\n";
1136
+ print "denom = ", $class -> _str($denom), "\n";
1137
+ }
1138
+
1139
+ my $delta = $class -> _div($numer, $denom);
1140
+
1141
+ if ($DEBUG) {
1142
+ print "delta = ", $class -> _str($delta), "\n";
1143
+ }
1144
+
1145
+ last if $class -> _is_zero($delta);
1146
+
1147
+ $x = $class -> _sub($x, $delta);
1148
+ $xpownm1 = $class -> _pow($class -> _copy($x), $nm1); # x(i)^(n-1)
1149
+ $xpown = $class -> _mul($class -> _copy($xpownm1), $x); # x(i)^n
1150
+ $acmp = $class -> _acmp($xpown, $y); # x(i)^n <=> y
1151
+
1152
+ if ($DEBUG) {
1153
+ print "\n";
1154
+ print "x = ", $class -> _str($x), "\n";
1155
+ print "x^n = ", $class -> _str($xpown), "\n";
1156
+ print "y = ", $class -> _str($y), "\n";
1157
+ print "acmp = $acmp\n";
1158
+ }
1159
+ }
1160
+
1161
+ # When the delta is zero, our value for x might still be too large. We
1162
+ # require that the outout is either exact or too small (i.e., rounded down
1163
+ # to the nearest integer), so do a final check.
1164
+
1165
+ while ($acmp > 0) {
1166
+ $x = $class -> _dec($x);
1167
+ $xpown = $class -> _pow($class -> _copy($x), $n); # x(i)^n
1168
+ $acmp = $class -> _acmp($xpown, $y); # x(i)^n <=> y
1169
+ }
1170
+
1171
+ return $x;
1172
+ }
1173
+
1174
+ ##############################################################################
1175
+ # binary stuff
1176
+
1177
+ sub _and {
1178
+ my ($class, $x, $y) = @_;
1179
+
1180
+ return $x if $class -> _acmp($x, $y) == 0;
1181
+
1182
+ my $m = $class -> _one();
1183
+ my $mask = $class -> _new("32768");
1184
+
1185
+ my ($xr, $yr); # remainders after division
1186
+
1187
+ my $xc = $class -> _copy($x);
1188
+ my $yc = $class -> _copy($y);
1189
+ my $z = $class -> _zero();
1190
+
1191
+ until ($class -> _is_zero($xc) || $class -> _is_zero($yc)) {
1192
+ ($xc, $xr) = $class -> _div($xc, $mask);
1193
+ ($yc, $yr) = $class -> _div($yc, $mask);
1194
+ my $bits = $class -> _new($class -> _num($xr) & $class -> _num($yr));
1195
+ $z = $class -> _add($z, $class -> _mul($bits, $m));
1196
+ $m = $class -> _mul($m, $mask);
1197
+ }
1198
+
1199
+ return $z;
1200
+ }
1201
+
1202
+ sub _xor {
1203
+ my ($class, $x, $y) = @_;
1204
+
1205
+ return $class -> _zero() if $class -> _acmp($x, $y) == 0;
1206
+
1207
+ my $m = $class -> _one();
1208
+ my $mask = $class -> _new("32768");
1209
+
1210
+ my ($xr, $yr); # remainders after division
1211
+
1212
+ my $xc = $class -> _copy($x);
1213
+ my $yc = $class -> _copy($y);
1214
+ my $z = $class -> _zero();
1215
+
1216
+ until ($class -> _is_zero($xc) || $class -> _is_zero($yc)) {
1217
+ ($xc, $xr) = $class -> _div($xc, $mask);
1218
+ ($yc, $yr) = $class -> _div($yc, $mask);
1219
+ my $bits = $class -> _new($class -> _num($xr) ^ $class -> _num($yr));
1220
+ $z = $class -> _add($z, $class -> _mul($bits, $m));
1221
+ $m = $class -> _mul($m, $mask);
1222
+ }
1223
+
1224
+ # The loop above stops when the smallest of the two numbers is exhausted.
1225
+ # The remainder of the longer one will survive bit-by-bit, so we simple
1226
+ # multiply-add it in.
1227
+
1228
+ $z = $class -> _add($z, $class -> _mul($xc, $m))
1229
+ unless $class -> _is_zero($xc);
1230
+ $z = $class -> _add($z, $class -> _mul($yc, $m))
1231
+ unless $class -> _is_zero($yc);
1232
+
1233
+ return $z;
1234
+ }
1235
+
1236
+ sub _or {
1237
+ my ($class, $x, $y) = @_;
1238
+
1239
+ return $x if $class -> _acmp($x, $y) == 0; # shortcut (see _and)
1240
+
1241
+ my $m = $class -> _one();
1242
+ my $mask = $class -> _new("32768");
1243
+
1244
+ my ($xr, $yr); # remainders after division
1245
+
1246
+ my $xc = $class -> _copy($x);
1247
+ my $yc = $class -> _copy($y);
1248
+ my $z = $class -> _zero();
1249
+
1250
+ until ($class -> _is_zero($xc) || $class -> _is_zero($yc)) {
1251
+ ($xc, $xr) = $class -> _div($xc, $mask);
1252
+ ($yc, $yr) = $class -> _div($yc, $mask);
1253
+ my $bits = $class -> _new($class -> _num($xr) | $class -> _num($yr));
1254
+ $z = $class -> _add($z, $class -> _mul($bits, $m));
1255
+ $m = $class -> _mul($m, $mask);
1256
+ }
1257
+
1258
+ # The loop above stops when the smallest of the two numbers is exhausted.
1259
+ # The remainder of the longer one will survive bit-by-bit, so we simple
1260
+ # multiply-add it in.
1261
+
1262
+ $z = $class -> _add($z, $class -> _mul($xc, $m))
1263
+ unless $class -> _is_zero($xc);
1264
+ $z = $class -> _add($z, $class -> _mul($yc, $m))
1265
+ unless $class -> _is_zero($yc);
1266
+
1267
+ return $z;
1268
+ }
1269
+
1270
+ sub _sand {
1271
+ my ($class, $x, $sx, $y, $sy) = @_;
1272
+
1273
+ return ($class -> _zero(), '+')
1274
+ if $class -> _is_zero($x) || $class -> _is_zero($y);
1275
+
1276
+ my $sign = $sx eq '-' && $sy eq '-' ? '-' : '+';
1277
+
1278
+ my ($bx, $by);
1279
+
1280
+ if ($sx eq '-') { # if x is negative
1281
+ # two's complement: inc (dec unsigned value) and flip all "bits" in $bx
1282
+ $bx = $class -> _copy($x);
1283
+ $bx = $class -> _dec($bx);
1284
+ $bx = $class -> _as_hex($bx);
1285
+ $bx =~ s/^-?0x//;
1286
+ $bx =~ tr<0123456789abcdef>
1287
+ <\x0f\x0e\x0d\x0c\x0b\x0a\x09\x08\x07\x06\x05\x04\x03\x02\x01\x00>;
1288
+ } else { # if x is positive
1289
+ $bx = $class -> _as_hex($x); # get binary representation
1290
+ $bx =~ s/^-?0x//;
1291
+ $bx =~ tr<fedcba9876543210>
1292
+ <\x0f\x0e\x0d\x0c\x0b\x0a\x09\x08\x07\x06\x05\x04\x03\x02\x01\x00>;
1293
+ }
1294
+
1295
+ if ($sy eq '-') { # if y is negative
1296
+ # two's complement: inc (dec unsigned value) and flip all "bits" in $by
1297
+ $by = $class -> _copy($y);
1298
+ $by = $class -> _dec($by);
1299
+ $by = $class -> _as_hex($by);
1300
+ $by =~ s/^-?0x//;
1301
+ $by =~ tr<0123456789abcdef>
1302
+ <\x0f\x0e\x0d\x0c\x0b\x0a\x09\x08\x07\x06\x05\x04\x03\x02\x01\x00>;
1303
+ } else {
1304
+ $by = $class -> _as_hex($y); # get binary representation
1305
+ $by =~ s/^-?0x//;
1306
+ $by =~ tr<fedcba9876543210>
1307
+ <\x0f\x0e\x0d\x0c\x0b\x0a\x09\x08\x07\x06\x05\x04\x03\x02\x01\x00>;
1308
+ }
1309
+
1310
+ # now we have bit-strings from X and Y, reverse them for padding
1311
+ $bx = reverse $bx;
1312
+ $by = reverse $by;
1313
+
1314
+ # padd the shorter string
1315
+ my $xx = "\x00"; $xx = "\x0f" if $sx eq '-';
1316
+ my $yy = "\x00"; $yy = "\x0f" if $sy eq '-';
1317
+ my $diff = CORE::length($bx) - CORE::length($by);
1318
+ if ($diff > 0) {
1319
+ # if $yy eq "\x00", we can cut $bx, otherwise we need to padd $by
1320
+ $by .= $yy x $diff;
1321
+ } elsif ($diff < 0) {
1322
+ # if $xx eq "\x00", we can cut $by, otherwise we need to padd $bx
1323
+ $bx .= $xx x abs($diff);
1324
+ }
1325
+
1326
+ # and the strings together
1327
+ my $r = $bx & $by;
1328
+
1329
+ # and reverse the result again
1330
+ $bx = reverse $r;
1331
+
1332
+ # One of $bx or $by was negative, so need to flip bits in the result. In both
1333
+ # cases (one or two of them negative, or both positive) we need to get the
1334
+ # characters back.
1335
+ if ($sign eq '-') {
1336
+ $bx =~ tr<\x0f\x0e\x0d\x0c\x0b\x0a\x09\x08\x07\x06\x05\x04\x03\x02\x01\x00>
1337
+ <0123456789abcdef>;
1338
+ } else {
1339
+ $bx =~ tr<\x0f\x0e\x0d\x0c\x0b\x0a\x09\x08\x07\x06\x05\x04\x03\x02\x01\x00>
1340
+ <fedcba9876543210>;
1341
+ }
1342
+
1343
+ # leading zeros will be stripped by _from_hex()
1344
+ $bx = '0x' . $bx;
1345
+ $bx = $class -> _from_hex($bx);
1346
+
1347
+ $bx = $class -> _inc($bx) if $sign eq '-';
1348
+
1349
+ # avoid negative zero
1350
+ $sign = '+' if $class -> _is_zero($bx);
1351
+
1352
+ return $bx, $sign;
1353
+ }
1354
+
1355
+ sub _sxor {
1356
+ my ($class, $x, $sx, $y, $sy) = @_;
1357
+
1358
+ return ($class -> _zero(), '+')
1359
+ if $class -> _is_zero($x) && $class -> _is_zero($y);
1360
+
1361
+ my $sign = $sx ne $sy ? '-' : '+';
1362
+
1363
+ my ($bx, $by);
1364
+
1365
+ if ($sx eq '-') { # if x is negative
1366
+ # two's complement: inc (dec unsigned value) and flip all "bits" in $bx
1367
+ $bx = $class -> _copy($x);
1368
+ $bx = $class -> _dec($bx);
1369
+ $bx = $class -> _as_hex($bx);
1370
+ $bx =~ s/^-?0x//;
1371
+ $bx =~ tr<0123456789abcdef>
1372
+ <\x0f\x0e\x0d\x0c\x0b\x0a\x09\x08\x07\x06\x05\x04\x03\x02\x01\x00>;
1373
+ } else { # if x is positive
1374
+ $bx = $class -> _as_hex($x); # get binary representation
1375
+ $bx =~ s/^-?0x//;
1376
+ $bx =~ tr<fedcba9876543210>
1377
+ <\x0f\x0e\x0d\x0c\x0b\x0a\x09\x08\x07\x06\x05\x04\x03\x02\x01\x00>;
1378
+ }
1379
+
1380
+ if ($sy eq '-') { # if y is negative
1381
+ # two's complement: inc (dec unsigned value) and flip all "bits" in $by
1382
+ $by = $class -> _copy($y);
1383
+ $by = $class -> _dec($by);
1384
+ $by = $class -> _as_hex($by);
1385
+ $by =~ s/^-?0x//;
1386
+ $by =~ tr<0123456789abcdef>
1387
+ <\x0f\x0e\x0d\x0c\x0b\x0a\x09\x08\x07\x06\x05\x04\x03\x02\x01\x00>;
1388
+ } else {
1389
+ $by = $class -> _as_hex($y); # get binary representation
1390
+ $by =~ s/^-?0x//;
1391
+ $by =~ tr<fedcba9876543210>
1392
+ <\x0f\x0e\x0d\x0c\x0b\x0a\x09\x08\x07\x06\x05\x04\x03\x02\x01\x00>;
1393
+ }
1394
+
1395
+ # now we have bit-strings from X and Y, reverse them for padding
1396
+ $bx = reverse $bx;
1397
+ $by = reverse $by;
1398
+
1399
+ # padd the shorter string
1400
+ my $xx = "\x00"; $xx = "\x0f" if $sx eq '-';
1401
+ my $yy = "\x00"; $yy = "\x0f" if $sy eq '-';
1402
+ my $diff = CORE::length($bx) - CORE::length($by);
1403
+ if ($diff > 0) {
1404
+ # if $yy eq "\x00", we can cut $bx, otherwise we need to padd $by
1405
+ $by .= $yy x $diff;
1406
+ } elsif ($diff < 0) {
1407
+ # if $xx eq "\x00", we can cut $by, otherwise we need to padd $bx
1408
+ $bx .= $xx x abs($diff);
1409
+ }
1410
+
1411
+ # xor the strings together
1412
+ my $r = $bx ^ $by;
1413
+
1414
+ # and reverse the result again
1415
+ $bx = reverse $r;
1416
+
1417
+ # One of $bx or $by was negative, so need to flip bits in the result. In both
1418
+ # cases (one or two of them negative, or both positive) we need to get the
1419
+ # characters back.
1420
+ if ($sign eq '-') {
1421
+ $bx =~ tr<\x0f\x0e\x0d\x0c\x0b\x0a\x09\x08\x07\x06\x05\x04\x03\x02\x01\x00>
1422
+ <0123456789abcdef>;
1423
+ } else {
1424
+ $bx =~ tr<\x0f\x0e\x0d\x0c\x0b\x0a\x09\x08\x07\x06\x05\x04\x03\x02\x01\x00>
1425
+ <fedcba9876543210>;
1426
+ }
1427
+
1428
+ # leading zeros will be stripped by _from_hex()
1429
+ $bx = '0x' . $bx;
1430
+ $bx = $class -> _from_hex($bx);
1431
+
1432
+ $bx = $class -> _inc($bx) if $sign eq '-';
1433
+
1434
+ # avoid negative zero
1435
+ $sign = '+' if $class -> _is_zero($bx);
1436
+
1437
+ return $bx, $sign;
1438
+ }
1439
+
1440
+ sub _sor {
1441
+ my ($class, $x, $sx, $y, $sy) = @_;
1442
+
1443
+ return ($class -> _zero(), '+')
1444
+ if $class -> _is_zero($x) && $class -> _is_zero($y);
1445
+
1446
+ my $sign = $sx eq '-' || $sy eq '-' ? '-' : '+';
1447
+
1448
+ my ($bx, $by);
1449
+
1450
+ if ($sx eq '-') { # if x is negative
1451
+ # two's complement: inc (dec unsigned value) and flip all "bits" in $bx
1452
+ $bx = $class -> _copy($x);
1453
+ $bx = $class -> _dec($bx);
1454
+ $bx = $class -> _as_hex($bx);
1455
+ $bx =~ s/^-?0x//;
1456
+ $bx =~ tr<0123456789abcdef>
1457
+ <\x0f\x0e\x0d\x0c\x0b\x0a\x09\x08\x07\x06\x05\x04\x03\x02\x01\x00>;
1458
+ } else { # if x is positive
1459
+ $bx = $class -> _as_hex($x); # get binary representation
1460
+ $bx =~ s/^-?0x//;
1461
+ $bx =~ tr<fedcba9876543210>
1462
+ <\x0f\x0e\x0d\x0c\x0b\x0a\x09\x08\x07\x06\x05\x04\x03\x02\x01\x00>;
1463
+ }
1464
+
1465
+ if ($sy eq '-') { # if y is negative
1466
+ # two's complement: inc (dec unsigned value) and flip all "bits" in $by
1467
+ $by = $class -> _copy($y);
1468
+ $by = $class -> _dec($by);
1469
+ $by = $class -> _as_hex($by);
1470
+ $by =~ s/^-?0x//;
1471
+ $by =~ tr<0123456789abcdef>
1472
+ <\x0f\x0e\x0d\x0c\x0b\x0a\x09\x08\x07\x06\x05\x04\x03\x02\x01\x00>;
1473
+ } else {
1474
+ $by = $class -> _as_hex($y); # get binary representation
1475
+ $by =~ s/^-?0x//;
1476
+ $by =~ tr<fedcba9876543210>
1477
+ <\x0f\x0e\x0d\x0c\x0b\x0a\x09\x08\x07\x06\x05\x04\x03\x02\x01\x00>;
1478
+ }
1479
+
1480
+ # now we have bit-strings from X and Y, reverse them for padding
1481
+ $bx = reverse $bx;
1482
+ $by = reverse $by;
1483
+
1484
+ # padd the shorter string
1485
+ my $xx = "\x00"; $xx = "\x0f" if $sx eq '-';
1486
+ my $yy = "\x00"; $yy = "\x0f" if $sy eq '-';
1487
+ my $diff = CORE::length($bx) - CORE::length($by);
1488
+ if ($diff > 0) {
1489
+ # if $yy eq "\x00", we can cut $bx, otherwise we need to padd $by
1490
+ $by .= $yy x $diff;
1491
+ } elsif ($diff < 0) {
1492
+ # if $xx eq "\x00", we can cut $by, otherwise we need to padd $bx
1493
+ $bx .= $xx x abs($diff);
1494
+ }
1495
+
1496
+ # or the strings together
1497
+ my $r = $bx | $by;
1498
+
1499
+ # and reverse the result again
1500
+ $bx = reverse $r;
1501
+
1502
+ # One of $bx or $by was negative, so need to flip bits in the result. In both
1503
+ # cases (one or two of them negative, or both positive) we need to get the
1504
+ # characters back.
1505
+ if ($sign eq '-') {
1506
+ $bx =~ tr<\x0f\x0e\x0d\x0c\x0b\x0a\x09\x08\x07\x06\x05\x04\x03\x02\x01\x00>
1507
+ <0123456789abcdef>;
1508
+ } else {
1509
+ $bx =~ tr<\x0f\x0e\x0d\x0c\x0b\x0a\x09\x08\x07\x06\x05\x04\x03\x02\x01\x00>
1510
+ <fedcba9876543210>;
1511
+ }
1512
+
1513
+ # leading zeros will be stripped by _from_hex()
1514
+ $bx = '0x' . $bx;
1515
+ $bx = $class -> _from_hex($bx);
1516
+
1517
+ $bx = $class -> _inc($bx) if $sign eq '-';
1518
+
1519
+ # avoid negative zero
1520
+ $sign = '+' if $class -> _is_zero($bx);
1521
+
1522
+ return $bx, $sign;
1523
+ }
1524
+
1525
+ sub _to_bin {
1526
+ # convert the number to a string of binary digits without prefix
1527
+ my ($class, $x) = @_;
1528
+ my $str = '';
1529
+ my $tmp = $class -> _copy($x);
1530
+ my $chunk = $class -> _new("16777216"); # 2^24 = 24 binary digits
1531
+ my $rem;
1532
+ until ($class -> _acmp($tmp, $chunk) < 0) {
1533
+ ($tmp, $rem) = $class -> _div($tmp, $chunk);
1534
+ $str = sprintf("%024b", $class -> _num($rem)) . $str;
1535
+ }
1536
+ unless ($class -> _is_zero($tmp)) {
1537
+ $str = sprintf("%b", $class -> _num($tmp)) . $str;
1538
+ }
1539
+ return length($str) ? $str : '0';
1540
+ }
1541
+
1542
+ sub _to_oct {
1543
+ # convert the number to a string of octal digits without prefix
1544
+ my ($class, $x) = @_;
1545
+ my $str = '';
1546
+ my $tmp = $class -> _copy($x);
1547
+ my $chunk = $class -> _new("16777216"); # 2^24 = 8 octal digits
1548
+ my $rem;
1549
+ until ($class -> _acmp($tmp, $chunk) < 0) {
1550
+ ($tmp, $rem) = $class -> _div($tmp, $chunk);
1551
+ $str = sprintf("%08o", $class -> _num($rem)) . $str;
1552
+ }
1553
+ unless ($class -> _is_zero($tmp)) {
1554
+ $str = sprintf("%o", $class -> _num($tmp)) . $str;
1555
+ }
1556
+ return length($str) ? $str : '0';
1557
+ }
1558
+
1559
+ sub _to_hex {
1560
+ # convert the number to a string of hexadecimal digits without prefix
1561
+ my ($class, $x) = @_;
1562
+ my $str = '';
1563
+ my $tmp = $class -> _copy($x);
1564
+ my $chunk = $class -> _new("16777216"); # 2^24 = 6 hexadecimal digits
1565
+ my $rem;
1566
+ until ($class -> _acmp($tmp, $chunk) < 0) {
1567
+ ($tmp, $rem) = $class -> _div($tmp, $chunk);
1568
+ $str = sprintf("%06x", $class -> _num($rem)) . $str;
1569
+ }
1570
+ unless ($class -> _is_zero($tmp)) {
1571
+ $str = sprintf("%x", $class -> _num($tmp)) . $str;
1572
+ }
1573
+ return length($str) ? $str : '0';
1574
+ }
1575
+
1576
+ sub _as_bin {
1577
+ # convert the number to a string of binary digits with prefix
1578
+ my ($class, $x) = @_;
1579
+ return '0b' . $class -> _to_bin($x);
1580
+ }
1581
+
1582
+ sub _as_oct {
1583
+ # convert the number to a string of octal digits with prefix
1584
+ my ($class, $x) = @_;
1585
+ return '0' . $class -> _to_oct($x); # yes, 0 becomes "00"
1586
+ }
1587
+
1588
+ sub _as_hex {
1589
+ # convert the number to a string of hexadecimal digits with prefix
1590
+ my ($class, $x) = @_;
1591
+ return '0x' . $class -> _to_hex($x);
1592
+ }
1593
+
1594
+ sub _to_bytes {
1595
+ # convert the number to a string of bytes
1596
+ my ($class, $x) = @_;
1597
+ my $str = '';
1598
+ my $tmp = $class -> _copy($x);
1599
+ my $chunk = $class -> _new("65536");
1600
+ my $rem;
1601
+ until ($class -> _is_zero($tmp)) {
1602
+ ($tmp, $rem) = $class -> _div($tmp, $chunk);
1603
+ $str = pack('n', $class -> _num($rem)) . $str;
1604
+ }
1605
+ $str =~ s/^\0+//;
1606
+ return length($str) ? $str : "\x00";
1607
+ }
1608
+
1609
+ *_as_bytes = \&_to_bytes;
1610
+
1611
+ sub _to_base {
1612
+ # convert the number to a string of digits in various bases
1613
+ my $class = shift;
1614
+ my $x = shift;
1615
+ my $base = shift;
1616
+ $base = $class -> _new($base) unless ref($base);
1617
+
1618
+ my $collseq;
1619
+ if (@_) {
1620
+ $collseq = shift;
1621
+ croak "The collation sequence must be a non-empty string"
1622
+ unless defined($collseq) && length($collseq);
1623
+ } else {
1624
+ if ($class -> _acmp($base, $class -> _new("94")) <= 0) {
1625
+ $collseq = '0123456789' # 48 .. 57
1626
+ . 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' # 65 .. 90
1627
+ . 'abcdefghijklmnopqrstuvwxyz' # 97 .. 122
1628
+ . '!"#$%&\'()*+,-./' # 33 .. 47
1629
+ . ':;<=>?@' # 58 .. 64
1630
+ . '[\\]^_`' # 91 .. 96
1631
+ . '{|}~'; # 123 .. 126
1632
+ } else {
1633
+ croak "When base > 94, a collation sequence must be given";
1634
+ }
1635
+ }
1636
+
1637
+ my @collseq = split '', $collseq;
1638
+
1639
+ my $str = '';
1640
+ my $tmp = $class -> _copy($x);
1641
+ my $rem;
1642
+ until ($class -> _is_zero($tmp)) {
1643
+ ($tmp, $rem) = $class -> _div($tmp, $base);
1644
+ my $num = $class -> _num($rem);
1645
+ croak "no character to represent '$num' in collation sequence",
1646
+ " (collation sequence is too short)" if $num > $#collseq;
1647
+ my $chr = $collseq[$num];
1648
+ $str = $chr . $str;
1649
+ }
1650
+ return $collseq[0] unless length $str;
1651
+ return $str;
1652
+ }
1653
+
1654
+ sub _to_base_num {
1655
+ # Convert the number to an array of integers in any base.
1656
+ my ($class, $x, $base) = @_;
1657
+
1658
+ # Make sure the base is an object and >= 2.
1659
+ $base = $class -> _new($base) unless ref($base);
1660
+ my $two = $class -> _two();
1661
+ croak "base must be >= 2" unless $class -> _acmp($base, $two) >= 0;
1662
+
1663
+ my $out = [];
1664
+ my $xcopy = $class -> _copy($x);
1665
+ my $rem;
1666
+
1667
+ # Do all except the last (most significant) element.
1668
+ until ($class -> _acmp($xcopy, $base) < 0) {
1669
+ ($xcopy, $rem) = $class -> _div($xcopy, $base);
1670
+ unshift @$out, $rem;
1671
+ }
1672
+
1673
+ # Do the last (most significant element).
1674
+ unless ($class -> _is_zero($xcopy)) {
1675
+ unshift @$out, $xcopy;
1676
+ }
1677
+
1678
+ # $out is empty if $x is zero.
1679
+ unshift @$out, $class -> _zero() unless @$out;
1680
+
1681
+ return $out;
1682
+ }
1683
+
1684
+ sub _from_hex {
1685
+ # Convert a string of hexadecimal digits to a number.
1686
+
1687
+ my ($class, $hex) = @_;
1688
+ $hex =~ s/^0[xX]//;
1689
+
1690
+ # Find the largest number of hexadecimal digits that we can safely use with
1691
+ # 32 bit integers. There are 4 bits pr hexadecimal digit, and we use only
1692
+ # 31 bits to play safe. This gives us int(31 / 4) = 7.
1693
+
1694
+ my $len = length $hex;
1695
+ my $rem = 1 + ($len - 1) % 7;
1696
+
1697
+ # Do the first chunk.
1698
+
1699
+ my $ret = $class -> _new(int hex substr $hex, 0, $rem);
1700
+ return $ret if $rem == $len;
1701
+
1702
+ # Do the remaining chunks, if any.
1703
+
1704
+ my $shift = $class -> _new(1 << (4 * 7));
1705
+ for (my $offset = $rem ; $offset < $len ; $offset += 7) {
1706
+ my $part = int hex substr $hex, $offset, 7;
1707
+ $ret = $class -> _mul($ret, $shift);
1708
+ $ret = $class -> _add($ret, $class -> _new($part));
1709
+ }
1710
+
1711
+ return $ret;
1712
+ }
1713
+
1714
+ sub _from_oct {
1715
+ # Convert a string of octal digits to a number.
1716
+
1717
+ my ($class, $oct) = @_;
1718
+
1719
+ # Find the largest number of octal digits that we can safely use with 32
1720
+ # bit integers. There are 3 bits pr octal digit, and we use only 31 bits to
1721
+ # play safe. This gives us int(31 / 3) = 10.
1722
+
1723
+ my $len = length $oct;
1724
+ my $rem = 1 + ($len - 1) % 10;
1725
+
1726
+ # Do the first chunk.
1727
+
1728
+ my $ret = $class -> _new(int oct substr $oct, 0, $rem);
1729
+ return $ret if $rem == $len;
1730
+
1731
+ # Do the remaining chunks, if any.
1732
+
1733
+ my $shift = $class -> _new(1 << (3 * 10));
1734
+ for (my $offset = $rem ; $offset < $len ; $offset += 10) {
1735
+ my $part = int oct substr $oct, $offset, 10;
1736
+ $ret = $class -> _mul($ret, $shift);
1737
+ $ret = $class -> _add($ret, $class -> _new($part));
1738
+ }
1739
+
1740
+ return $ret;
1741
+ }
1742
+
1743
+ sub _from_bin {
1744
+ # Convert a string of binary digits to a number.
1745
+
1746
+ my ($class, $bin) = @_;
1747
+ $bin =~ s/^0[bB]//;
1748
+
1749
+ # The largest number of binary digits that we can safely use with 32 bit
1750
+ # integers is 31. We use only 31 bits to play safe.
1751
+
1752
+ my $len = length $bin;
1753
+ my $rem = 1 + ($len - 1) % 31;
1754
+
1755
+ # Do the first chunk.
1756
+
1757
+ my $ret = $class -> _new(int oct '0b' . substr $bin, 0, $rem);
1758
+ return $ret if $rem == $len;
1759
+
1760
+ # Do the remaining chunks, if any.
1761
+
1762
+ my $shift = $class -> _new(1 << 31);
1763
+ for (my $offset = $rem ; $offset < $len ; $offset += 31) {
1764
+ my $part = int oct '0b' . substr $bin, $offset, 31;
1765
+ $ret = $class -> _mul($ret, $shift);
1766
+ $ret = $class -> _add($ret, $class -> _new($part));
1767
+ }
1768
+
1769
+ return $ret;
1770
+ }
1771
+
1772
+ sub _from_bytes {
1773
+ # convert string of bytes to a number
1774
+ my ($class, $str) = @_;
1775
+ my $x = $class -> _zero();
1776
+ my $base = $class -> _new("256");
1777
+ my $n = length($str);
1778
+ for (my $i = 0 ; $i < $n ; ++$i) {
1779
+ $x = $class -> _mul($x, $base);
1780
+ my $byteval = $class -> _new(unpack 'C', substr($str, $i, 1));
1781
+ $x = $class -> _add($x, $byteval);
1782
+ }
1783
+ return $x;
1784
+ }
1785
+
1786
+ sub _from_base {
1787
+ # convert a string to a decimal number
1788
+ my $class = shift;
1789
+ my $str = shift;
1790
+ my $base = shift;
1791
+ $base = $class -> _new($base) unless ref($base);
1792
+
1793
+ my $n = length($str);
1794
+ my $x = $class -> _zero();
1795
+
1796
+ my $collseq;
1797
+ if (@_) {
1798
+ $collseq = shift();
1799
+ } else {
1800
+ if ($class -> _acmp($base, $class -> _new("36")) <= 0) {
1801
+ $str = uc $str;
1802
+ $collseq = '0123456789' . 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
1803
+ } elsif ($class -> _acmp($base, $class -> _new("94")) <= 0) {
1804
+ $collseq = '0123456789' # 48 .. 57
1805
+ . 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' # 65 .. 90
1806
+ . 'abcdefghijklmnopqrstuvwxyz' # 97 .. 122
1807
+ . '!"#$%&\'()*+,-./' # 33 .. 47
1808
+ . ':;<=>?@' # 58 .. 64
1809
+ . '[\\]^_`' # 91 .. 96
1810
+ . '{|}~'; # 123 .. 126
1811
+ } else {
1812
+ croak "When base > 94, a collation sequence must be given";
1813
+ }
1814
+ $collseq = substr $collseq, 0, $class -> _num($base);
1815
+ }
1816
+
1817
+ # Create a mapping from each character in the collation sequence to the
1818
+ # corresponding integer. Check for duplicates in the collation sequence.
1819
+
1820
+ my @collseq = split '', $collseq;
1821
+ my %collseq;
1822
+ for my $num (0 .. $#collseq) {
1823
+ my $chr = $collseq[$num];
1824
+ die "duplicate character '$chr' in collation sequence"
1825
+ if exists $collseq{$chr};
1826
+ $collseq{$chr} = $num;
1827
+ }
1828
+
1829
+ for (my $i = 0 ; $i < $n ; ++$i) {
1830
+ my $chr = substr($str, $i, 1);
1831
+ die "input character '$chr' does not exist in collation sequence"
1832
+ unless exists $collseq{$chr};
1833
+ $x = $class -> _mul($x, $base);
1834
+ my $num = $class -> _new($collseq{$chr});
1835
+ $x = $class -> _add($x, $num);
1836
+ }
1837
+
1838
+ return $x;
1839
+ }
1840
+
1841
+ sub _from_base_num {
1842
+ # Convert an array in the given base to a number.
1843
+ my ($class, $in, $base) = @_;
1844
+
1845
+ # Make sure the base is an object and >= 2.
1846
+ $base = $class -> _new($base) unless ref($base);
1847
+ my $two = $class -> _two();
1848
+ croak "base must be >= 2" unless $class -> _acmp($base, $two) >= 0;
1849
+
1850
+ # @$in = map { ref($_) ? $_ : $class -> _new($_) } @$in;
1851
+
1852
+ my $ele = $in -> [0];
1853
+
1854
+ $ele = $class -> _new($ele) unless ref($ele);
1855
+ my $x = $class -> _copy($ele);
1856
+
1857
+ for my $i (1 .. $#$in) {
1858
+ $x = $class -> _mul($x, $base);
1859
+ $ele = $in -> [$i];
1860
+ $ele = $class -> _new($ele) unless ref($ele);
1861
+ $x = $class -> _add($x, $ele);
1862
+ }
1863
+
1864
+ return $x;
1865
+ }
1866
+
1867
+ ##############################################################################
1868
+ # special modulus functions
1869
+
1870
+ sub _modinv {
1871
+ # modular multiplicative inverse
1872
+ my ($class, $x, $y) = @_;
1873
+
1874
+ # modulo zero
1875
+ if ($class -> _is_zero($y)) {
1876
+ return;
1877
+ }
1878
+
1879
+ # modulo one
1880
+ if ($class -> _is_one($y)) {
1881
+ return ($class -> _zero(), '+');
1882
+ }
1883
+
1884
+ my $u = $class -> _zero();
1885
+ my $v = $class -> _one();
1886
+ my $a = $class -> _copy($y);
1887
+ my $b = $class -> _copy($x);
1888
+
1889
+ # Euclid's Algorithm for bgcd().
1890
+
1891
+ my $q;
1892
+ my $sign = 1;
1893
+ {
1894
+ ($a, $q, $b) = ($b, $class -> _div($a, $b));
1895
+ last if $class -> _is_zero($b);
1896
+
1897
+ my $vq = $class -> _mul($class -> _copy($v), $q);
1898
+ my $t = $class -> _add($vq, $u);
1899
+ $u = $v;
1900
+ $v = $t;
1901
+ $sign = -$sign;
1902
+ redo;
1903
+ }
1904
+
1905
+ # if the gcd is not 1, there exists no modular multiplicative inverse
1906
+ return unless $class -> _is_one($a);
1907
+
1908
+ ($v, $sign == 1 ? '+' : '-');
1909
+ }
1910
+
1911
+ sub _modpow {
1912
+ # modulus of power ($x ** $y) % $z
1913
+ my ($class, $num, $exp, $mod) = @_;
1914
+
1915
+ # a^b (mod 1) = 0 for all a and b
1916
+ if ($class -> _is_one($mod)) {
1917
+ return $class -> _zero();
1918
+ }
1919
+
1920
+ # 0^a (mod m) = 0 if m != 0, a != 0
1921
+ # 0^0 (mod m) = 1 if m != 0
1922
+ if ($class -> _is_zero($num)) {
1923
+ return $class -> _is_zero($exp) ? $class -> _one()
1924
+ : $class -> _zero();
1925
+ }
1926
+
1927
+ # We could do the following, but it doesn't actually save any time. The
1928
+ # _copy() is needed in case $num and $mod are the same object.
1929
+
1930
+ $num = $class -> _mod($class -> _copy($num), $mod);
1931
+
1932
+ my $acc = $class -> _copy($num);
1933
+ my $t = $class -> _one();
1934
+
1935
+ my $expbin = $class -> _to_bin($exp);
1936
+ my $len = length($expbin);
1937
+
1938
+ while ($len--) {
1939
+ if (substr($expbin, $len, 1) eq '1') { # if odd
1940
+ $t = $class -> _mul($t, $acc);
1941
+ $t = $class -> _mod($t, $mod);
1942
+ }
1943
+ $acc = $class -> _mul($acc, $acc);
1944
+ $acc = $class -> _mod($acc, $mod);
1945
+ }
1946
+ return $t;
1947
+ }
1948
+
1949
+ sub _gcd {
1950
+ # Greatest common divisor.
1951
+
1952
+ my ($class, $x, $y) = @_;
1953
+
1954
+ # gcd(0, 0) = 0
1955
+ # gcd(0, a) = a, if a != 0
1956
+
1957
+ if ($class -> _acmp($x, $y) == 0) {
1958
+ return $class -> _copy($x);
1959
+ }
1960
+
1961
+ if ($class -> _is_zero($x)) {
1962
+ if ($class -> _is_zero($y)) {
1963
+ return $class -> _zero();
1964
+ } else {
1965
+ return $class -> _copy($y);
1966
+ }
1967
+ } else {
1968
+ if ($class -> _is_zero($y)) {
1969
+ return $class -> _copy($x);
1970
+ } else {
1971
+
1972
+ # Until $y is zero ...
1973
+
1974
+ $x = $class -> _copy($x);
1975
+ until ($class -> _is_zero($y)) {
1976
+
1977
+ # Compute remainder.
1978
+
1979
+ $x = $class -> _mod($x, $y);
1980
+
1981
+ # Swap $x and $y.
1982
+
1983
+ my $tmp = $x;
1984
+ $x = $class -> _copy($y);
1985
+ $y = $tmp;
1986
+ }
1987
+
1988
+ return $x;
1989
+ }
1990
+ }
1991
+ }
1992
+
1993
+ sub _lcm {
1994
+ # Least common multiple.
1995
+
1996
+ my ($class, $x, $y) = @_;
1997
+
1998
+ # lcm(0, x) = 0 for all x
1999
+
2000
+ return $class -> _zero()
2001
+ if ($class -> _is_zero($x) ||
2002
+ $class -> _is_zero($y));
2003
+
2004
+ my $gcd = $class -> _gcd($class -> _copy($x), $y);
2005
+ $x = $class -> _div($x, $gcd);
2006
+ $x = $class -> _mul($x, $y);
2007
+ return $x;
2008
+ }
2009
+
2010
+ sub _lucas {
2011
+ my ($class, $n) = @_;
2012
+
2013
+ $n = $class -> _num($n) if ref $n;
2014
+
2015
+ # In list context, use lucas(n) = lucas(n-1) + lucas(n-2)
2016
+
2017
+ if (wantarray) {
2018
+ my @y;
2019
+
2020
+ push @y, $class -> _two();
2021
+ return @y if $n == 0;
2022
+
2023
+ push @y, $class -> _one();
2024
+ return @y if $n == 1;
2025
+
2026
+ for (my $i = 2 ; $i <= $n ; ++ $i) {
2027
+ $y[$i] = $class -> _add($class -> _copy($y[$i - 1]), $y[$i - 2]);
2028
+ }
2029
+
2030
+ return @y;
2031
+ }
2032
+
2033
+ # In scalar context use that lucas(n) = fib(n-1) + fib(n+1).
2034
+ #
2035
+ # Remember that _fib() behaves differently in scalar context and list
2036
+ # context, so we must add scalar() to get the desired behaviour.
2037
+
2038
+ return $class -> _two() if $n == 0;
2039
+
2040
+ return $class -> _add(scalar($class -> _fib($n - 1)),
2041
+ scalar($class -> _fib($n + 1)));
2042
+ }
2043
+
2044
+ sub _fib {
2045
+ my ($class, $n) = @_;
2046
+
2047
+ $n = $class -> _num($n) if ref $n;
2048
+
2049
+ # In list context, use fib(n) = fib(n-1) + fib(n-2)
2050
+
2051
+ if (wantarray) {
2052
+ my @y;
2053
+
2054
+ push @y, $class -> _zero();
2055
+ return @y if $n == 0;
2056
+
2057
+ push @y, $class -> _one();
2058
+ return @y if $n == 1;
2059
+
2060
+ for (my $i = 2 ; $i <= $n ; ++ $i) {
2061
+ $y[$i] = $class -> _add($class -> _copy($y[$i - 1]), $y[$i - 2]);
2062
+ }
2063
+
2064
+ return @y;
2065
+ }
2066
+
2067
+ # In scalar context use a fast algorithm that is much faster than the
2068
+ # recursive algorith used in list context.
2069
+
2070
+ my $cache = {};
2071
+ my $two = $class -> _two();
2072
+ my $fib;
2073
+
2074
+ $fib = sub {
2075
+ my $n = shift;
2076
+ return $class -> _zero() if $n <= 0;
2077
+ return $class -> _one() if $n <= 2;
2078
+ return $cache -> {$n} if exists $cache -> {$n};
2079
+
2080
+ my $k = int($n / 2);
2081
+ my $a = $fib -> ($k + 1);
2082
+ my $b = $fib -> ($k);
2083
+ my $y;
2084
+
2085
+ if ($n % 2 == 1) {
2086
+ # a*a + b*b
2087
+ $y = $class -> _add($class -> _mul($class -> _copy($a), $a),
2088
+ $class -> _mul($class -> _copy($b), $b));
2089
+ } else {
2090
+ # (2*a - b)*b
2091
+ $y = $class -> _mul($class -> _sub($class -> _mul(
2092
+ $class -> _copy($two), $a), $b), $b);
2093
+ }
2094
+
2095
+ $cache -> {$n} = $y;
2096
+ return $y;
2097
+ };
2098
+
2099
+ return $fib -> ($n);
2100
+ }
2101
+
2102
+ ##############################################################################
2103
+ ##############################################################################
2104
+
2105
+ 1;
2106
+
2107
+ __END__
2108
+
2109
+ =pod
2110
+
2111
+ =head1 NAME
2112
+
2113
+ Math::BigInt::Lib - virtual parent class for Math::BigInt libraries
2114
+
2115
+ =head1 SYNOPSIS
2116
+
2117
+ # In the backend library for Math::BigInt et al.
2118
+
2119
+ package Math::BigInt::MyBackend;
2120
+
2121
+ use Math::BigInt::Lib;
2122
+ our @ISA = qw< Math::BigInt::Lib >;
2123
+
2124
+ sub _new { ... }
2125
+ sub _str { ... }
2126
+ sub _add { ... }
2127
+ str _sub { ... }
2128
+ ...
2129
+
2130
+ # In your main program.
2131
+
2132
+ use Math::BigInt lib => 'MyBackend';
2133
+
2134
+ =head1 DESCRIPTION
2135
+
2136
+ This module provides support for big integer calculations. It is not intended
2137
+ to be used directly, but rather as a parent class for backend libraries used by
2138
+ Math::BigInt, Math::BigFloat, Math::BigRat, and related modules.
2139
+
2140
+ Other backend libraries include Math::BigInt::Calc, Math::BigInt::FastCalc,
2141
+ Math::BigInt::GMP, and Math::BigInt::Pari.
2142
+
2143
+ In order to allow for multiple big integer libraries, Math::BigInt was
2144
+ rewritten to use a plug-in library for core math routines. Any module which
2145
+ conforms to the API can be used by Math::BigInt by using this in your program:
2146
+
2147
+ use Math::BigInt lib => 'libname';
2148
+
2149
+ 'libname' is either the long name, like 'Math::BigInt::Pari', or only the short
2150
+ version, like 'Pari'.
2151
+
2152
+ =head2 General Notes
2153
+
2154
+ A library only needs to deal with unsigned big integers. Testing of input
2155
+ parameter validity is done by the caller, so there is no need to worry about
2156
+ underflow (e.g., in C<_sub()> and C<_dec()>) or about division by zero (e.g.,
2157
+ in C<_div()> and C<_mod()>)) or similar cases.
2158
+
2159
+ Some libraries use methods that don't modify their argument, and some libraries
2160
+ don't even use objects, but rather unblessed references. Because of this,
2161
+ liberary methods are always called as class methods, not instance methods:
2162
+
2163
+ $x = Class -> method($x, $y); # like this
2164
+ $x = $x -> method($y); # not like this ...
2165
+ $x -> method($y); # ... or like this
2166
+
2167
+ And with boolean methods
2168
+
2169
+ $bool = Class -> method($x, $y); # like this
2170
+ $bool = $x -> method($y); # not like this
2171
+
2172
+ Return values are always objects, strings, Perl scalars, or true/false for
2173
+ comparison routines.
2174
+
2175
+ =head3 API version
2176
+
2177
+ =over 4
2178
+
2179
+ =item CLASS-E<gt>api_version()
2180
+
2181
+ This method is no longer used and can be omitted. Methods that are not
2182
+ implemented by a subclass will be inherited from this class.
2183
+
2184
+ =back
2185
+
2186
+ =head3 Constructors
2187
+
2188
+ The following methods are mandatory: _new(), _str(), _add(), and _sub().
2189
+ However, computations will be very slow without _mul() and _div().
2190
+
2191
+ =over 4
2192
+
2193
+ =item CLASS-E<gt>_new(STR)
2194
+
2195
+ Convert a string representing an unsigned decimal number to an object
2196
+ representing the same number. The input is normalized, i.e., it matches
2197
+ C<^(0|[1-9]\d*)$>.
2198
+
2199
+ =item CLASS-E<gt>_zero()
2200
+
2201
+ Return an object representing the number zero.
2202
+
2203
+ =item CLASS-E<gt>_one()
2204
+
2205
+ Return an object representing the number one.
2206
+
2207
+ =item CLASS-E<gt>_two()
2208
+
2209
+ Return an object representing the number two.
2210
+
2211
+ =item CLASS-E<gt>_ten()
2212
+
2213
+ Return an object representing the number ten.
2214
+
2215
+ =item CLASS-E<gt>_from_bin(STR)
2216
+
2217
+ Return an object given a string representing a binary number. The input has a
2218
+ '0b' prefix and matches the regular expression C<^0[bB](0|1[01]*)$>.
2219
+
2220
+ =item CLASS-E<gt>_from_oct(STR)
2221
+
2222
+ Return an object given a string representing an octal number. The input has a
2223
+ '0' prefix and matches the regular expression C<^0[1-7]*$>.
2224
+
2225
+ =item CLASS-E<gt>_from_hex(STR)
2226
+
2227
+ Return an object given a string representing a hexadecimal number. The input
2228
+ has a '0x' prefix and matches the regular expression
2229
+ C<^0x(0|[1-9a-fA-F][\da-fA-F]*)$>.
2230
+
2231
+ =item CLASS-E<gt>_from_bytes(STR)
2232
+
2233
+ Returns an object given a byte string representing the number. The byte string
2234
+ is in big endian byte order, so the two-byte input string "\x01\x00" should
2235
+ give an output value representing the number 256.
2236
+
2237
+ =item CLASS-E<gt>_from_base(STR, BASE, COLLSEQ)
2238
+
2239
+ Returns an object given a string STR, a base BASE, and a collation sequence
2240
+ COLLSEQ. Each character in STR represents a numerical value identical to the
2241
+ character's position in COLLSEQ. All characters in STR must be present in
2242
+ COLLSEQ.
2243
+
2244
+ If BASE is less than or equal to 94, and a collation sequence is not specified,
2245
+ the following default collation sequence is used. It contains of all the 94
2246
+ printable ASCII characters except space/blank:
2247
+
2248
+ 0123456789 # ASCII 48 to 57
2249
+ ABCDEFGHIJKLMNOPQRSTUVWXYZ # ASCII 65 to 90
2250
+ abcdefghijklmnopqrstuvwxyz # ASCII 97 to 122
2251
+ !"#$%&'()*+,-./ # ASCII 33 to 47
2252
+ :;<=>?@ # ASCII 58 to 64
2253
+ [\]^_` # ASCII 91 to 96
2254
+ {|}~ # ASCII 123 to 126
2255
+
2256
+ If the default collation sequence is used, and the BASE is less than or equal
2257
+ to 36, the letter case in STR is ignored.
2258
+
2259
+ For instance, with base 3 and collation sequence "-/|", the character "-"
2260
+ represents 0, "/" represents 1, and "|" represents 2. So if STR is "/|-", the
2261
+ output is 1 * 3**2 + 2 * 3**1 + 0 * 3**0 = 15.
2262
+
2263
+ The following examples show standard binary, octal, decimal, and hexadecimal
2264
+ conversion. All examples return 250.
2265
+
2266
+ $x = $class -> _from_base("11111010", 2)
2267
+ $x = $class -> _from_base("372", 8)
2268
+ $x = $class -> _from_base("250", 10)
2269
+ $x = $class -> _from_base("FA", 16)
2270
+
2271
+ Some more examples, all returning 250:
2272
+
2273
+ $x = $class -> _from_base("100021", 3)
2274
+ $x = $class -> _from_base("3322", 4)
2275
+ $x = $class -> _from_base("2000", 5)
2276
+ $x = $class -> _from_base("caaa", 5, "abcde")
2277
+ $x = $class -> _from_base("42", 62)
2278
+ $x = $class -> _from_base("2!", 94)
2279
+
2280
+ =item CLASS-E<gt>_from_base_num(ARRAY, BASE)
2281
+
2282
+ Returns an object given an array of values and a base. This method is
2283
+ equivalent to C<_from_base()>, but works on numbers in an array rather than
2284
+ characters in a string. Unlike C<_from_base()>, all input values may be
2285
+ arbitrarily large.
2286
+
2287
+ $x = $class -> _from_base_num([1, 1, 0, 1], 2) # $x is 13
2288
+ $x = $class -> _from_base_num([3, 125, 39], 128) # $x is 65191
2289
+
2290
+ =back
2291
+
2292
+ =head3 Mathematical functions
2293
+
2294
+ =over 4
2295
+
2296
+ =item CLASS-E<gt>_add(OBJ1, OBJ2)
2297
+
2298
+ Addition. Returns the result of adding OBJ2 to OBJ1.
2299
+
2300
+ =item CLASS-E<gt>_mul(OBJ1, OBJ2)
2301
+
2302
+ Multiplication. Returns the result of multiplying OBJ2 and OBJ1.
2303
+
2304
+ =item CLASS-E<gt>_div(OBJ1, OBJ2)
2305
+
2306
+ Division. In scalar context, returns the quotient after dividing OBJ1 by OBJ2
2307
+ and truncating the result to an integer. In list context, return the quotient
2308
+ and the remainder.
2309
+
2310
+ =item CLASS-E<gt>_sub(OBJ1, OBJ2, FLAG)
2311
+
2312
+ =item CLASS-E<gt>_sub(OBJ1, OBJ2)
2313
+
2314
+ Subtraction. Returns the result of subtracting OBJ2 by OBJ1. If C<flag> is false
2315
+ or omitted, OBJ1 might be modified. If C<flag> is true, OBJ2 might be modified.
2316
+
2317
+ =item CLASS-E<gt>_sadd(OBJ1, SIGN1, OBJ2, SIGN2)
2318
+
2319
+ Signed addition. Returns the result of adding OBJ2 with sign SIGN2 to OBJ1 with
2320
+ sign SIGN1.
2321
+
2322
+ ($obj3, $sign3) = $class -> _sadd($obj1, $sign1, $obj2, $sign2);
2323
+
2324
+ =item CLASS-E<gt>_ssub(OBJ1, SIGN1, OBJ2, SIGN2)
2325
+
2326
+ Signed subtraction. Returns the result of subtracting OBJ2 with sign SIGN2 to
2327
+ OBJ1 with sign SIGN1.
2328
+
2329
+ ($obj3, $sign3) = $class -> _sadd($obj1, $sign1, $obj2, $sign2);
2330
+
2331
+ =item CLASS-E<gt>_dec(OBJ)
2332
+
2333
+ Returns the result after decrementing OBJ by one.
2334
+
2335
+ =item CLASS-E<gt>_inc(OBJ)
2336
+
2337
+ Returns the result after incrementing OBJ by one.
2338
+
2339
+ =item CLASS-E<gt>_mod(OBJ1, OBJ2)
2340
+
2341
+ Returns OBJ1 modulo OBJ2, i.e., the remainder after dividing OBJ1 by OBJ2.
2342
+
2343
+ =item CLASS-E<gt>_sqrt(OBJ)
2344
+
2345
+ Returns the square root of OBJ, truncated to an integer.
2346
+
2347
+ =item CLASS-E<gt>_root(OBJ, N)
2348
+
2349
+ Returns the Nth root of OBJ, truncated to an integer.
2350
+
2351
+ =item CLASS-E<gt>_fac(OBJ)
2352
+
2353
+ Returns the factorial of OBJ, i.e., the product of all positive integers up to
2354
+ and including OBJ.
2355
+
2356
+ =item CLASS-E<gt>_dfac(OBJ)
2357
+
2358
+ Returns the double factorial of OBJ. If OBJ is an even integer, returns the
2359
+ product of all positive, even integers up to and including OBJ, i.e.,
2360
+ 2*4*6*...*OBJ. If OBJ is an odd integer, returns the product of all positive,
2361
+ odd integers, i.e., 1*3*5*...*OBJ.
2362
+
2363
+ =item CLASS-E<gt>_pow(OBJ1, OBJ2)
2364
+
2365
+ Returns OBJ1 raised to the power of OBJ2. By convention, 0**0 = 1.
2366
+
2367
+ =item CLASS-E<gt>_modinv(OBJ1, OBJ2)
2368
+
2369
+ Returns the modular multiplicative inverse, i.e., return OBJ3 so that
2370
+
2371
+ (OBJ3 * OBJ1) % OBJ2 = 1 % OBJ2
2372
+
2373
+ The result is returned as two arguments. If the modular multiplicative inverse
2374
+ does not exist, both arguments are undefined. Otherwise, the arguments are a
2375
+ number (object) and its sign ("+" or "-").
2376
+
2377
+ The output value, with its sign, must either be a positive value in the range
2378
+ 1,2,...,OBJ2-1 or the same value subtracted OBJ2. For instance, if the input
2379
+ arguments are objects representing the numbers 7 and 5, the method must either
2380
+ return an object representing the number 3 and a "+" sign, since (3*7) % 5 = 1
2381
+ % 5, or an object representing the number 2 and a "-" sign, since (-2*7) % 5 = 1
2382
+ % 5.
2383
+
2384
+ =item CLASS-E<gt>_modpow(OBJ1, OBJ2, OBJ3)
2385
+
2386
+ Returns the modular exponentiation, i.e., (OBJ1 ** OBJ2) % OBJ3.
2387
+
2388
+ =item CLASS-E<gt>_rsft(OBJ, N, B)
2389
+
2390
+ Returns the result after shifting OBJ N digits to thee right in base B. This is
2391
+ equivalent to performing integer division by B**N and discarding the remainder,
2392
+ except that it might be much faster.
2393
+
2394
+ For instance, if the object $obj represents the hexadecimal number 0xabcde,
2395
+ then C<_rsft($obj, 2, 16)> returns an object representing the number 0xabc. The
2396
+ "remainer", 0xde, is discarded and not returned.
2397
+
2398
+ =item CLASS-E<gt>_lsft(OBJ, N, B)
2399
+
2400
+ Returns the result after shifting OBJ N digits to the left in base B. This is
2401
+ equivalent to multiplying by B**N, except that it might be much faster.
2402
+
2403
+ =item CLASS-E<gt>_log_int(OBJ, B)
2404
+
2405
+ Returns the logarithm of OBJ to base BASE truncted to an integer. This method
2406
+ has two output arguments, the OBJECT and a STATUS. The STATUS is Perl scalar;
2407
+ it is 1 if OBJ is the exact result, 0 if the result was truncted to give OBJ,
2408
+ and undef if it is unknown whether OBJ is the exact result.
2409
+
2410
+ =item CLASS-E<gt>_ilog2(OBJ)
2411
+
2412
+ Returns the base 2 logarithm of OBJ rounded downwards to the nearest integer,
2413
+ i.e., C<int(log2(OBJ))>. In list context, this method returns two output
2414
+ arguments, the OBJECT and a STATUS. The STATUS is Perl scalar; it is 1 if OBJ
2415
+ is the exact result, 0 if the result was truncted to give OBJ, and undef if it
2416
+ is unknown whether OBJ is the exact result.
2417
+
2418
+ This method is equivalent to the more general method _log_int() when it is used
2419
+ with base 2 argument, but _ilog2() method might be faster.
2420
+
2421
+ =item CLASS-E<gt>_ilog10(OBJ)
2422
+
2423
+ Returns the base 10 logarithm of OBJ rounded downwards to the nearest integer,
2424
+ i.e., C<int(log2(OBJ))>. In list context, this method returns two output
2425
+ arguments, the OBJECT and a STATUS. The STATUS is Perl scalar; it is 1 if OBJ
2426
+ is the exact result, 0 if the result was truncted to give OBJ, and undef if it
2427
+ is unknown whether OBJ is the exact result.
2428
+
2429
+ This method is equivalent to the more general method _log_int() when it is used
2430
+ with base 10 argument, but _ilog10() method might be faster.
2431
+
2432
+ Also, the output from _ilog10() is always 1 smaller than the output from
2433
+ _len().
2434
+
2435
+ =item CLASS-E<gt>_clog2(OBJ)
2436
+
2437
+ Returns the base 2 logarithm of OBJ rounded upwards to the nearest integer,
2438
+ i.e., C<ceil(log2(OBJ))>. In list context, this method returns two output
2439
+ arguments, the OBJECT and a STATUS. The STATUS is Perl scalar; it is 1 if OBJ
2440
+ is the exact result, 0 if the result was truncted to give OBJ, and undef if it
2441
+ is unknown whether OBJ is the exact result.
2442
+
2443
+ =item CLASS-E<gt>_clog10(OBJ)
2444
+
2445
+ Returns the base 10 logarithm of OBJ rounded upnwards to the nearest integer,
2446
+ i.e., C<ceil(log2(OBJ))>. In list context, this method returns two output
2447
+ arguments, the OBJECT and a STATUS. The STATUS is Perl scalar; it is 1 if OBJ
2448
+ is the exact result, 0 if the result was truncted to give OBJ, and undef if it
2449
+ is unknown whether OBJ is the exact result.
2450
+
2451
+ =item CLASS-E<gt>_gcd(OBJ1, OBJ2)
2452
+
2453
+ Returns the greatest common divisor of OBJ1 and OBJ2.
2454
+
2455
+ =item CLASS-E<gt>_lcm(OBJ1, OBJ2)
2456
+
2457
+ Return the least common multiple of OBJ1 and OBJ2.
2458
+
2459
+ =item CLASS-E<gt>_fib(OBJ)
2460
+
2461
+ In scalar context, returns the nth Fibonacci number: _fib(0) returns 0, _fib(1)
2462
+ returns 1, _fib(2) returns 1, _fib(3) returns 2 etc. In list context, returns
2463
+ the Fibonacci numbers from F(0) to F(n): 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ...
2464
+
2465
+ =item CLASS-E<gt>_lucas(OBJ)
2466
+
2467
+ In scalar context, returns the nth Lucas number: _lucas(0) returns 2, _lucas(1)
2468
+ returns 1, _lucas(2) returns 3, etc. In list context, returns the Lucas numbers
2469
+ from L(0) to L(n): 2, 1, 3, 4, 7, 11, 18, 29,47, 76, ...
2470
+
2471
+ =back
2472
+
2473
+ =head3 Bitwise operators
2474
+
2475
+ =over 4
2476
+
2477
+ =item CLASS-E<gt>_and(OBJ1, OBJ2)
2478
+
2479
+ Returns bitwise and.
2480
+
2481
+ =item CLASS-E<gt>_or(OBJ1, OBJ2)
2482
+
2483
+ Returns bitwise or.
2484
+
2485
+ =item CLASS-E<gt>_xor(OBJ1, OBJ2)
2486
+
2487
+ Returns bitwise exclusive or.
2488
+
2489
+ =item CLASS-E<gt>_sand(OBJ1, OBJ2, SIGN1, SIGN2)
2490
+
2491
+ Returns bitwise signed and.
2492
+
2493
+ =item CLASS-E<gt>_sor(OBJ1, OBJ2, SIGN1, SIGN2)
2494
+
2495
+ Returns bitwise signed or.
2496
+
2497
+ =item CLASS-E<gt>_sxor(OBJ1, OBJ2, SIGN1, SIGN2)
2498
+
2499
+ Returns bitwise signed exclusive or.
2500
+
2501
+ =back
2502
+
2503
+ =head3 Boolean operators
2504
+
2505
+ =over 4
2506
+
2507
+ =item CLASS-E<gt>_is_zero(OBJ)
2508
+
2509
+ Returns a true value if OBJ is zero, and false value otherwise.
2510
+
2511
+ =item CLASS-E<gt>_is_one(OBJ)
2512
+
2513
+ Returns a true value if OBJ is one, and false value otherwise.
2514
+
2515
+ =item CLASS-E<gt>_is_two(OBJ)
2516
+
2517
+ Returns a true value if OBJ is two, and false value otherwise.
2518
+
2519
+ =item CLASS-E<gt>_is_ten(OBJ)
2520
+
2521
+ Returns a true value if OBJ is ten, and false value otherwise.
2522
+
2523
+ =item CLASS-E<gt>_is_even(OBJ)
2524
+
2525
+ Return a true value if OBJ is an even integer, and a false value otherwise.
2526
+
2527
+ =item CLASS-E<gt>_is_odd(OBJ)
2528
+
2529
+ Return a true value if OBJ is an even integer, and a false value otherwise.
2530
+
2531
+ =item CLASS-E<gt>_acmp(OBJ1, OBJ2)
2532
+
2533
+ Compare OBJ1 and OBJ2 and return -1, 0, or 1, if OBJ1 is numerically less than,
2534
+ equal to, or larger than OBJ2, respectively.
2535
+
2536
+ =item CLASS-E<gt>_scmp(OBJ1, SIGN1, OBJ2, SIGN2)
2537
+
2538
+ Compare OBJ1 and OBJ2 and return -1, 0, or 1, if OBJ1 is numerically less than,
2539
+ equal to, or larger than OBJ2, respectively.
2540
+
2541
+ =back
2542
+
2543
+ =head3 String conversion
2544
+
2545
+ =over 4
2546
+
2547
+ =item CLASS-E<gt>_str(OBJ)
2548
+
2549
+ Returns a string representing OBJ in decimal notation. The returned string
2550
+ should have no leading zeros, i.e., it should match C<^(0|[1-9]\d*)$>.
2551
+
2552
+ =item CLASS-E<gt>_to_bin(OBJ)
2553
+
2554
+ Returns the binary string representation of OBJ.
2555
+
2556
+ =item CLASS-E<gt>_to_oct(OBJ)
2557
+
2558
+ Returns the octal string representation of the number.
2559
+
2560
+ =item CLASS-E<gt>_to_hex(OBJ)
2561
+
2562
+ Returns the hexadecimal string representation of the number.
2563
+
2564
+ =item CLASS-E<gt>_to_bytes(OBJ)
2565
+
2566
+ Returns a byte string representation of OBJ. The byte string is in big endian
2567
+ byte order, so if OBJ represents the number 256, the output should be the
2568
+ two-byte string "\x01\x00".
2569
+
2570
+ =item CLASS-E<gt>_to_base(OBJ, BASE, COLLSEQ)
2571
+
2572
+ Returns a string representation of OBJ in base BASE with collation sequence
2573
+ COLLSEQ.
2574
+
2575
+ $val = $class -> _new("210");
2576
+ $str = $class -> _to_base($val, 10, "xyz") # $str is "zyx"
2577
+
2578
+ $val = $class -> _new("32");
2579
+ $str = $class -> _to_base($val, 2, "-|") # $str is "|-----"
2580
+
2581
+ See _from_base() for more information.
2582
+
2583
+ =item CLASS-E<gt>_to_base_num(OBJ, BASE)
2584
+
2585
+ Converts the given number to the given base. This method is equivalent to
2586
+ C<_to_base()>, but returns numbers in an array rather than characters in a
2587
+ string. In the output, the first element is the most significant. Unlike
2588
+ C<_to_base()>, all input values may be arbitrarily large.
2589
+
2590
+ $x = $class -> _to_base_num(13, 2) # $x is [1, 1, 0, 1]
2591
+ $x = $class -> _to_base_num(65191, 128) # $x is [3, 125, 39]
2592
+
2593
+ =item CLASS-E<gt>_as_bin(OBJ)
2594
+
2595
+ Like C<_to_bin()> but with a '0b' prefix.
2596
+
2597
+ =item CLASS-E<gt>_as_oct(OBJ)
2598
+
2599
+ Like C<_to_oct()> but with a '0' prefix.
2600
+
2601
+ =item CLASS-E<gt>_as_hex(OBJ)
2602
+
2603
+ Like C<_to_hex()> but with a '0x' prefix.
2604
+
2605
+ =item CLASS-E<gt>_as_bytes(OBJ)
2606
+
2607
+ This is an alias to C<_to_bytes()>.
2608
+
2609
+ =back
2610
+
2611
+ =head3 Numeric conversion
2612
+
2613
+ =over 4
2614
+
2615
+ =item CLASS-E<gt>_num(OBJ)
2616
+
2617
+ Returns a Perl scalar number representing the number OBJ as close as
2618
+ possible. Since Perl scalars have limited precision, the returned value might
2619
+ not be exactly the same as OBJ.
2620
+
2621
+ =back
2622
+
2623
+ =head3 Miscellaneous
2624
+
2625
+ =over 4
2626
+
2627
+ =item CLASS-E<gt>_copy(OBJ)
2628
+
2629
+ Returns a true copy OBJ.
2630
+
2631
+ =item CLASS-E<gt>_len(OBJ)
2632
+
2633
+ Returns the number of the decimal digits in OBJ. The output is a Perl scalar.
2634
+
2635
+ =item CLASS-E<gt>_zeros(OBJ)
2636
+
2637
+ Returns the number of trailing decimal zeros. The output is a Perl scalar. The
2638
+ number zero has no trailing decimal zeros.
2639
+
2640
+ =item CLASS-E<gt>_digit(OBJ, N)
2641
+
2642
+ Returns the Nth digit in OBJ as a Perl scalar. N is a Perl scalar, where zero
2643
+ refers to the rightmost (least significant) digit, and negative values count
2644
+ from the left (most significant digit). If $obj represents the number 123, then
2645
+
2646
+ CLASS->_digit($obj, 0) # returns 3
2647
+ CLASS->_digit($obj, 1) # returns 2
2648
+ CLASS->_digit($obj, 2) # returns 1
2649
+ CLASS->_digit($obj, -1) # returns 1
2650
+
2651
+ =item CLASS-E<gt>_digitsum(OBJ)
2652
+
2653
+ Returns the sum of the base 10 digits.
2654
+
2655
+ =item CLASS-E<gt>_check(OBJ)
2656
+
2657
+ Returns true if the object is invalid and false otherwise. Preferably, the true
2658
+ value is a string describing the problem with the object. This is a check
2659
+ routine to test the internal state of the object for corruption.
2660
+
2661
+ =item CLASS-E<gt>_set(OBJ)
2662
+
2663
+ xxx
2664
+
2665
+ =back
2666
+
2667
+ =head2 API version 2
2668
+
2669
+ The following methods are required for an API version of 2 or greater.
2670
+
2671
+ =head3 Constructors
2672
+
2673
+ =over 4
2674
+
2675
+ =item CLASS-E<gt>_1ex(N)
2676
+
2677
+ Return an object representing the number 10**N where N E<gt>= 0 is a Perl
2678
+ scalar.
2679
+
2680
+ =back
2681
+
2682
+ =head3 Mathematical functions
2683
+
2684
+ =over 4
2685
+
2686
+ =item CLASS-E<gt>_nok(OBJ1, OBJ2)
2687
+
2688
+ Return the binomial coefficient OBJ1 over OBJ1.
2689
+
2690
+ =back
2691
+
2692
+ =head3 Miscellaneous
2693
+
2694
+ =over 4
2695
+
2696
+ =item CLASS-E<gt>_alen(OBJ)
2697
+
2698
+ Return the approximate number of decimal digits of the object. The output is a
2699
+ Perl scalar.
2700
+
2701
+ =back
2702
+
2703
+ =head1 WRAP YOUR OWN
2704
+
2705
+ If you want to port your own favourite C library for big numbers to the
2706
+ Math::BigInt interface, you can take any of the already existing modules as a
2707
+ rough guideline. You should really wrap up the latest Math::BigInt and
2708
+ Math::BigFloat testsuites with your module, and replace in them any of the
2709
+ following:
2710
+
2711
+ use Math::BigInt;
2712
+
2713
+ by this:
2714
+
2715
+ use Math::BigInt lib => 'yourlib';
2716
+
2717
+ This way you ensure that your library really works 100% within Math::BigInt.
2718
+
2719
+ =head1 BUGS
2720
+
2721
+ Please report any bugs or feature requests to
2722
+ C<bug-math-bigint at rt.cpan.org>, or through the web interface at
2723
+ L<https://rt.cpan.org/Ticket/Create.html?Queue=Math-BigInt>
2724
+ (requires login).
2725
+ We will be notified, and then you'll automatically be notified of progress on
2726
+ your bug as I make changes.
2727
+
2728
+ =head1 SUPPORT
2729
+
2730
+ You can find documentation for this module with the perldoc command.
2731
+
2732
+ perldoc Math::BigInt::Calc
2733
+
2734
+ You can also look for information at:
2735
+
2736
+ =over 4
2737
+
2738
+ =item * GitHub Source Repository
2739
+
2740
+ L<https://github.com/pjacklam/p5-Math-BigInt>
2741
+
2742
+ =item * RT: CPAN's request tracker
2743
+
2744
+ L<https://rt.cpan.org/Public/Dist/Display.html?Name=Math-BigInt>
2745
+
2746
+ =item * MetaCPAN
2747
+
2748
+ L<https://metacpan.org/release/Math-BigInt>
2749
+
2750
+ =item * CPAN Testers Matrix
2751
+
2752
+ L<http://matrix.cpantesters.org/?dist=Math-BigInt>
2753
+
2754
+ =back
2755
+
2756
+ =head1 LICENSE
2757
+
2758
+ This program is free software; you may redistribute it and/or modify it under
2759
+ the same terms as Perl itself.
2760
+
2761
+ =head1 AUTHOR
2762
+
2763
+ Peter John Acklam, E<lt>pjacklam@gmail.comE<gt>
2764
+
2765
+ Code and documentation based on the Math::BigInt::Calc module by Tels
2766
+ E<lt>nospam-abuse@bloodgate.comE<gt>
2767
+
2768
+ =head1 SEE ALSO
2769
+
2770
+ L<Math::BigInt>, L<Math::BigInt::Calc>, L<Math::BigInt::GMP>,
2771
+ L<Math::BigInt::FastCalc> and L<Math::BigInt::Pari>.
2772
+
2773
+ =cut
git/usr/share/perl5/core_perl/Math/BigInt/Trace.pm ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- mode: perl; -*-
2
+
3
+ package Math::BigInt::Trace;
4
+
5
+ use strict;
6
+ use warnings;
7
+
8
+ use Exporter;
9
+ use Math::BigInt;
10
+
11
+ our @ISA = qw(Exporter Math::BigInt);
12
+
13
+ our $VERSION = '0.67';
14
+
15
+ use overload; # inherit overload from Math::BigInt
16
+
17
+ # Globals
18
+ our $accuracy = undef;
19
+ our $precision = undef;
20
+ our $round_mode = 'even';
21
+ our $div_scale = 40;
22
+
23
+ sub new {
24
+ my $proto = shift;
25
+ my $class = ref($proto) || $proto;
26
+
27
+ my $value = shift;
28
+
29
+ my $a = $accuracy;
30
+ $a = $_[0] if defined $_[0];
31
+
32
+ my $p = $precision;
33
+ $p = $_[1] if defined $_[1];
34
+
35
+ my $self = $class -> SUPER::new($value, $a, $p, $round_mode);
36
+
37
+ printf "Math::BigInt new '%s' => '%s' (%s)\n",
38
+ $value, $self, ref($self);
39
+
40
+ return $self;
41
+ }
42
+
43
+ sub import {
44
+ my $class = shift;
45
+
46
+ printf "%s -> import(%s)\n", $class, join(", ", @_);
47
+
48
+ # we catch the constants, the rest goes to parent
49
+
50
+ my $constant = grep { $_ eq ':constant' } @_;
51
+ my @a = grep { $_ ne ':constant' } @_;
52
+
53
+ if ($constant) {
54
+ overload::constant
55
+
56
+ integer => sub {
57
+ $class -> new(shift);
58
+ },
59
+
60
+ float => sub {
61
+ $class -> new(shift);
62
+ },
63
+
64
+ binary => sub {
65
+ # E.g., a literal 0377 shall result in an object whose value
66
+ # is decimal 255, but new("0377") returns decimal 377.
67
+ return $class -> from_oct($_[0]) if $_[0] =~ /^0_*[0-7]/;
68
+ $class -> new(shift);
69
+ };
70
+ }
71
+
72
+ $class -> SUPER::import(@a); # need it for subclasses
73
+ #$self -> export_to_level(1, $class, @_); # need this ?
74
+ }
75
+
76
+ 1;
git/usr/share/perl5/core_perl/Math/BigRat/Trace.pm ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- mode: perl; -*-
2
+
3
+ package Math::BigRat::Trace;
4
+
5
+ use strict;
6
+ use warnings;
7
+
8
+ use Exporter;
9
+ use Math::BigRat;
10
+
11
+ our @ISA = qw(Exporter Math::BigRat);
12
+
13
+ our $VERSION = '0.67';
14
+
15
+ use overload; # inherit overload from Math::BigRat
16
+
17
+ # Globals
18
+ our $accuracy = undef;
19
+ our $precision = undef;
20
+ our $round_mode = 'even';
21
+ our $div_scale = 40;
22
+
23
+ sub new {
24
+ my $proto = shift;
25
+ my $class = ref($proto) || $proto;
26
+
27
+ my $value = shift;
28
+
29
+ my $a = $accuracy;
30
+ $a = $_[0] if defined $_[0];
31
+
32
+ my $p = $precision;
33
+ $p = $_[1] if defined $_[1];
34
+
35
+ my $self = $class -> SUPER::new($value, $a, $p, $round_mode);
36
+
37
+ printf "Math::BigRat new '%s' => '%s' (%s)\n",
38
+ $value, $self, ref($self);
39
+
40
+ return $self;
41
+ }
42
+
43
+ sub import {
44
+ my $class = shift;
45
+
46
+ printf "%s -> import(%s)\n", $class, join(", ", @_);
47
+
48
+ # we catch the constants, the rest goes to parent
49
+
50
+ my $constant = grep { $_ eq ':constant' } @_;
51
+ my @a = grep { $_ ne ':constant' } @_;
52
+
53
+ if ($constant) {
54
+ overload::constant
55
+
56
+ integer => sub {
57
+ $class -> new(shift);
58
+ },
59
+
60
+ float => sub {
61
+ $class -> new(shift);
62
+ },
63
+
64
+ binary => sub {
65
+ # E.g., a literal 0377 shall result in an object whose value
66
+ # is decimal 255, but new("0377") returns decimal 377.
67
+ return $class -> from_oct($_[0]) if $_[0] =~ /^0_*[0-7]/;
68
+ $class -> new(shift);
69
+ };
70
+ }
71
+
72
+ $class -> SUPER::import(@a); # need it for subclasses
73
+ #$self -> export_to_level(1, $class, @_); # need this ?
74
+ }
75
+
76
+ 1;
git/usr/share/perl5/core_perl/Module/CoreList/Utils.pm ADDED
@@ -0,0 +1,2388 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package Module::CoreList::Utils;
2
+
3
+ use strict;
4
+ use warnings;
5
+ use Module::CoreList;
6
+
7
+ our $VERSION = '5.20260329_42';
8
+ our %utilities;
9
+
10
+ sub utilities {
11
+ my $perl = shift;
12
+ $perl = shift if eval { $perl->isa(__PACKAGE__) };
13
+ return unless $perl or exists $utilities{$perl};
14
+ return sort keys %{ $utilities{$perl} };
15
+ }
16
+
17
+ sub _released_order { # Sort helper, to make '?' sort after everything else
18
+ (substr($Module::CoreList::released{$a}, 0, 1) eq "?")
19
+ ? ((substr($Module::CoreList::released{$b}, 0, 1) eq "?")
20
+ ? 0
21
+ : 1)
22
+ : ((substr($Module::CoreList::released{$b}, 0, 1) eq "?")
23
+ ? -1
24
+ : $Module::CoreList::released{$a} cmp $Module::CoreList::released{$b} )
25
+ }
26
+
27
+ sub first_release_raw {
28
+ my $util = shift;
29
+ $util = shift if eval { $util->isa(__PACKAGE__) };
30
+ #and scalar @_ and $_[0] =~ m#\A[a-zA-Z_][0-9a-zA-Z_]*(?:(::|')[0-9a-zA-Z_]+)*\z#;
31
+ my $version = shift;
32
+
33
+ my @perls = $version
34
+ ? grep { exists $utilities{$_}{ $util } &&
35
+ $utilities{$_}{ $util } ge $version } keys %utilities
36
+ : grep { exists $utilities{$_}{ $util } } keys %utilities;
37
+
38
+ return grep { exists $Module::CoreList::released{$_} } @perls;
39
+ }
40
+
41
+ sub first_release_by_date {
42
+ my @perls = &first_release_raw;
43
+ return unless @perls;
44
+ return (sort _released_order @perls)[0];
45
+ }
46
+
47
+ sub first_release {
48
+ my @perls = &first_release_raw;
49
+ return unless @perls;
50
+ return (sort { $a cmp $b } @perls)[0];
51
+ }
52
+
53
+ sub removed_from {
54
+ my @perls = &removed_raw;
55
+ return shift @perls;
56
+ }
57
+
58
+ sub removed_from_by_date {
59
+ my @perls = sort _released_order &removed_raw;
60
+ return shift @perls;
61
+ }
62
+
63
+ sub removed_raw {
64
+ my $util = shift;
65
+ $util = shift if eval { $util->isa(__PACKAGE__) };
66
+ return unless my @perls = sort { $a cmp $b } first_release_raw($util);
67
+ @perls = grep { exists $Module::CoreList::released{$_} } @perls;
68
+ my $last = pop @perls;
69
+ my @removed = grep { $_ > $last } sort { $a cmp $b } keys %utilities;
70
+ return @removed;
71
+ }
72
+
73
+ my %delta = (
74
+ 5 => {
75
+ changed => {
76
+ 'a2p' => '1',
77
+ 'c2ph' => '1',
78
+ 'cppstdin' => '1',
79
+ 'find2perl' => '1',
80
+ 'pstruct' => '1',
81
+ 's2p' => '1',
82
+ },
83
+ removed => {
84
+ }
85
+ },
86
+
87
+ 5.001 => {
88
+ delta_from => 5,
89
+ changed => {
90
+ 'h2xs' => '1',
91
+ },
92
+ removed => {
93
+ }
94
+ },
95
+
96
+ 5.002 => {
97
+ delta_from => 5.001,
98
+ changed => {
99
+ 'h2ph' => '1',
100
+ 'perlbug' => '1',
101
+ 'perldoc' => '1',
102
+ 'pod2html' => '1',
103
+ 'pod2latex' => '1',
104
+ 'pod2man' => '1',
105
+ 'pod2text' => '1',
106
+ },
107
+ removed => {
108
+ }
109
+ },
110
+
111
+ 5.00307 => {
112
+ delta_from => 5.002,
113
+ changed => {
114
+ 'pl2pm' => '1',
115
+ },
116
+ removed => {
117
+ 'cppstdin' => 1,
118
+ 'pstruct' => 1,
119
+ }
120
+ },
121
+
122
+ 5.004 => {
123
+ delta_from => 5.00307,
124
+ changed => {
125
+ 'splain' => '1',
126
+ },
127
+ removed => {
128
+ }
129
+ },
130
+
131
+ 5.005 => {
132
+ delta_from => 5.00405,
133
+ changed => {
134
+ 'perlcc' => '1',
135
+ },
136
+ removed => {
137
+ }
138
+ },
139
+
140
+ 5.00503 => {
141
+ delta_from => 5.005,
142
+ changed => {
143
+ },
144
+ removed => {
145
+ }
146
+ },
147
+
148
+ 5.00405 => {
149
+ delta_from => 5.004,
150
+ changed => {
151
+ },
152
+ removed => {
153
+ }
154
+ },
155
+
156
+ 5.006 => {
157
+ delta_from => 5.00504,
158
+ changed => {
159
+ 'dprofpp' => '1',
160
+ 'pod2usage' => '1',
161
+ 'podchecker' => '1',
162
+ 'podselect' => '1',
163
+ 'pstruct' => '1',
164
+ },
165
+ removed => {
166
+ }
167
+ },
168
+
169
+ 5.006001 => {
170
+ delta_from => 5.006,
171
+ changed => {
172
+ },
173
+ removed => {
174
+ }
175
+ },
176
+
177
+ 5.007003 => {
178
+ delta_from => 5.006002,
179
+ changed => {
180
+ 'libnetcfg' => '1',
181
+ 'perlivp' => '1',
182
+ 'psed' => '1',
183
+ 'xsubpp' => '1',
184
+ },
185
+ removed => {
186
+ }
187
+ },
188
+
189
+ 5.008 => {
190
+ delta_from => 5.007003,
191
+ changed => {
192
+ 'enc2xs' => '1',
193
+ 'piconv' => '1',
194
+ },
195
+ removed => {
196
+ }
197
+ },
198
+
199
+ 5.008001 => {
200
+ delta_from => 5.008,
201
+ changed => {
202
+ 'cpan' => '1',
203
+ },
204
+ removed => {
205
+ }
206
+ },
207
+
208
+ 5.009 => {
209
+ delta_from => 5.008009,
210
+ changed => {
211
+ },
212
+ removed => {
213
+ 'corelist' => 1,
214
+ 'instmodsh' => 1,
215
+ 'prove' => 1,
216
+ }
217
+ },
218
+
219
+ 5.008002 => {
220
+ delta_from => 5.008001,
221
+ changed => {
222
+ },
223
+ removed => {
224
+ }
225
+ },
226
+
227
+ 5.006002 => {
228
+ delta_from => 5.006001,
229
+ changed => {
230
+ },
231
+ removed => {
232
+ }
233
+ },
234
+
235
+ 5.008003 => {
236
+ delta_from => 5.008002,
237
+ changed => {
238
+ 'instmodsh' => '1',
239
+ 'prove' => '1',
240
+ },
241
+ removed => {
242
+ }
243
+ },
244
+
245
+ 5.00504 => {
246
+ delta_from => 5.00503,
247
+ changed => {
248
+ },
249
+ removed => {
250
+ }
251
+ },
252
+
253
+ 5.009001 => {
254
+ delta_from => 5.009,
255
+ changed => {
256
+ 'instmodsh' => '1',
257
+ 'prove' => '1',
258
+ },
259
+ removed => {
260
+ }
261
+ },
262
+
263
+ 5.008004 => {
264
+ delta_from => 5.008003,
265
+ changed => {
266
+ },
267
+ removed => {
268
+ }
269
+ },
270
+
271
+ 5.008005 => {
272
+ delta_from => 5.008004,
273
+ changed => {
274
+ },
275
+ removed => {
276
+ }
277
+ },
278
+
279
+ 5.008006 => {
280
+ delta_from => 5.008005,
281
+ changed => {
282
+ },
283
+ removed => {
284
+ }
285
+ },
286
+
287
+ 5.009002 => {
288
+ delta_from => 5.009001,
289
+ changed => {
290
+ 'corelist' => '1',
291
+ },
292
+ removed => {
293
+ }
294
+ },
295
+
296
+ 5.008007 => {
297
+ delta_from => 5.008006,
298
+ changed => {
299
+ },
300
+ removed => {
301
+ }
302
+ },
303
+
304
+ 5.009003 => {
305
+ delta_from => 5.009002,
306
+ changed => {
307
+ 'ptar' => '1',
308
+ 'ptardiff' => '1',
309
+ 'shasum' => '1',
310
+ },
311
+ removed => {
312
+ }
313
+ },
314
+
315
+ 5.008008 => {
316
+ delta_from => 5.008007,
317
+ changed => {
318
+ },
319
+ removed => {
320
+ }
321
+ },
322
+
323
+ 5.009004 => {
324
+ delta_from => 5.009003,
325
+ changed => {
326
+ 'config_data' => '1',
327
+ },
328
+ removed => {
329
+ }
330
+ },
331
+
332
+ 5.009005 => {
333
+ delta_from => 5.009004,
334
+ changed => {
335
+ 'cpan2dist' => '1',
336
+ 'cpanp' => '1',
337
+ 'cpanp-run-perl' => '1',
338
+ },
339
+ removed => {
340
+ 'perlcc' => 1,
341
+ }
342
+ },
343
+
344
+ 5.010000 => {
345
+ delta_from => 5.009005,
346
+ changed => {
347
+ },
348
+ removed => {
349
+ }
350
+ },
351
+
352
+ 5.008009 => {
353
+ delta_from => 5.008008,
354
+ changed => {
355
+ 'corelist' => '1',
356
+ },
357
+ removed => {
358
+ }
359
+ },
360
+
361
+ 5.010001 => {
362
+ delta_from => 5.010000,
363
+ changed => {
364
+ },
365
+ removed => {
366
+ }
367
+ },
368
+
369
+ 5.011 => {
370
+ delta_from => 5.010001,
371
+ changed => {
372
+ },
373
+ removed => {
374
+ }
375
+ },
376
+
377
+ 5.011001 => {
378
+ delta_from => 5.011,
379
+ changed => {
380
+ },
381
+ removed => {
382
+ }
383
+ },
384
+
385
+ 5.011002 => {
386
+ delta_from => 5.011001,
387
+ changed => {
388
+ 'perlthanks' => '1',
389
+ },
390
+ removed => {
391
+ }
392
+ },
393
+
394
+ 5.011003 => {
395
+ delta_from => 5.011002,
396
+ changed => {
397
+ },
398
+ removed => {
399
+ }
400
+ },
401
+
402
+ 5.011004 => {
403
+ delta_from => 5.011003,
404
+ changed => {
405
+ },
406
+ removed => {
407
+ }
408
+ },
409
+
410
+ 5.011005 => {
411
+ delta_from => 5.011004,
412
+ changed => {
413
+ },
414
+ removed => {
415
+ }
416
+ },
417
+
418
+ 5.012 => {
419
+ delta_from => 5.011005,
420
+ changed => {
421
+ },
422
+ removed => {
423
+ }
424
+ },
425
+
426
+ 5.013 => {
427
+ delta_from => 5.012005,
428
+ changed => {
429
+ },
430
+ removed => {
431
+ }
432
+ },
433
+
434
+ 5.012001 => {
435
+ delta_from => 5.012,
436
+ changed => {
437
+ },
438
+ removed => {
439
+ }
440
+ },
441
+
442
+ 5.013001 => {
443
+ delta_from => 5.013,
444
+ changed => {
445
+ },
446
+ removed => {
447
+ }
448
+ },
449
+
450
+ 5.013002 => {
451
+ delta_from => 5.013001,
452
+ changed => {
453
+ },
454
+ removed => {
455
+ }
456
+ },
457
+
458
+ 5.013003 => {
459
+ delta_from => 5.013002,
460
+ changed => {
461
+ },
462
+ removed => {
463
+ }
464
+ },
465
+
466
+ 5.013004 => {
467
+ delta_from => 5.013003,
468
+ changed => {
469
+ },
470
+ removed => {
471
+ }
472
+ },
473
+
474
+ 5.012002 => {
475
+ delta_from => 5.012001,
476
+ changed => {
477
+ },
478
+ removed => {
479
+ }
480
+ },
481
+
482
+ 5.013005 => {
483
+ delta_from => 5.013004,
484
+ changed => {
485
+ },
486
+ removed => {
487
+ }
488
+ },
489
+
490
+ 5.013006 => {
491
+ delta_from => 5.013005,
492
+ changed => {
493
+ },
494
+ removed => {
495
+ }
496
+ },
497
+
498
+ 5.013007 => {
499
+ delta_from => 5.013006,
500
+ changed => {
501
+ 'ptargrep' => '1',
502
+ },
503
+ removed => {
504
+ }
505
+ },
506
+
507
+ 5.013008 => {
508
+ delta_from => 5.013007,
509
+ changed => {
510
+ },
511
+ removed => {
512
+ }
513
+ },
514
+
515
+ 5.013009 => {
516
+ delta_from => 5.013008,
517
+ changed => {
518
+ 'json_pp' => '1',
519
+ },
520
+ removed => {
521
+ }
522
+ },
523
+
524
+ 5.012003 => {
525
+ delta_from => 5.012002,
526
+ changed => {
527
+ },
528
+ removed => {
529
+ }
530
+ },
531
+
532
+ 5.013010 => {
533
+ delta_from => 5.013009,
534
+ changed => {
535
+ },
536
+ removed => {
537
+ }
538
+ },
539
+
540
+ 5.013011 => {
541
+ delta_from => 5.013010,
542
+ changed => {
543
+ },
544
+ removed => {
545
+ }
546
+ },
547
+
548
+ 5.014 => {
549
+ delta_from => 5.013011,
550
+ changed => {
551
+ },
552
+ removed => {
553
+ }
554
+ },
555
+
556
+ 5.014001 => {
557
+ delta_from => 5.014,
558
+ changed => {
559
+ },
560
+ removed => {
561
+ }
562
+ },
563
+
564
+ 5.015 => {
565
+ delta_from => 5.014004,
566
+ changed => {
567
+ },
568
+ removed => {
569
+ 'dprofpp' => 1,
570
+ }
571
+ },
572
+
573
+ 5.012004 => {
574
+ delta_from => 5.012003,
575
+ changed => {
576
+ },
577
+ removed => {
578
+ }
579
+ },
580
+
581
+ 5.015001 => {
582
+ delta_from => 5.015,
583
+ changed => {
584
+ },
585
+ removed => {
586
+ }
587
+ },
588
+
589
+ 5.015002 => {
590
+ delta_from => 5.015001,
591
+ changed => {
592
+ },
593
+ removed => {
594
+ }
595
+ },
596
+
597
+ 5.015003 => {
598
+ delta_from => 5.015002,
599
+ changed => {
600
+ },
601
+ removed => {
602
+ }
603
+ },
604
+
605
+ 5.014002 => {
606
+ delta_from => 5.014001,
607
+ changed => {
608
+ },
609
+ removed => {
610
+ }
611
+ },
612
+
613
+ 5.015004 => {
614
+ delta_from => 5.015003,
615
+ changed => {
616
+ },
617
+ removed => {
618
+ }
619
+ },
620
+
621
+ 5.015005 => {
622
+ delta_from => 5.015004,
623
+ changed => {
624
+ },
625
+ removed => {
626
+ }
627
+ },
628
+
629
+ 5.015006 => {
630
+ delta_from => 5.015005,
631
+ changed => {
632
+ 'zipdetails' => '1',
633
+ },
634
+ removed => {
635
+ }
636
+ },
637
+
638
+ 5.015007 => {
639
+ delta_from => 5.015006,
640
+ changed => {
641
+ },
642
+ removed => {
643
+ }
644
+ },
645
+
646
+ 5.015008 => {
647
+ delta_from => 5.015007,
648
+ changed => {
649
+ },
650
+ removed => {
651
+ }
652
+ },
653
+
654
+ 5.015009 => {
655
+ delta_from => 5.015008,
656
+ changed => {
657
+ },
658
+ removed => {
659
+ }
660
+ },
661
+
662
+ 5.016 => {
663
+ delta_from => 5.015009,
664
+ changed => {
665
+ },
666
+ removed => {
667
+ }
668
+ },
669
+
670
+ 5.017 => {
671
+ delta_from => 5.016003,
672
+ changed => {
673
+ },
674
+ removed => {
675
+ }
676
+ },
677
+
678
+ 5.017001 => {
679
+ delta_from => 5.017,
680
+ changed => {
681
+ },
682
+ removed => {
683
+ }
684
+ },
685
+
686
+ 5.017002 => {
687
+ delta_from => 5.017001,
688
+ changed => {
689
+ },
690
+ removed => {
691
+ }
692
+ },
693
+
694
+ 5.016001 => {
695
+ delta_from => 5.016,
696
+ changed => {
697
+ },
698
+ removed => {
699
+ }
700
+ },
701
+
702
+ 5.017003 => {
703
+ delta_from => 5.017002,
704
+ changed => {
705
+ },
706
+ removed => {
707
+ }
708
+ },
709
+
710
+ 5.017004 => {
711
+ delta_from => 5.017003,
712
+ changed => {
713
+ },
714
+ removed => {
715
+ }
716
+ },
717
+
718
+ 5.014003 => {
719
+ delta_from => 5.014002,
720
+ changed => {
721
+ },
722
+ removed => {
723
+ }
724
+ },
725
+
726
+ 5.017005 => {
727
+ delta_from => 5.017004,
728
+ changed => {
729
+ },
730
+ removed => {
731
+ }
732
+ },
733
+
734
+ 5.016002 => {
735
+ delta_from => 5.016001,
736
+ changed => {
737
+ },
738
+ removed => {
739
+ }
740
+ },
741
+
742
+ 5.012005 => {
743
+ delta_from => 5.012004,
744
+ changed => {
745
+ },
746
+ removed => {
747
+ }
748
+ },
749
+
750
+ 5.017006 => {
751
+ delta_from => 5.017005,
752
+ changed => {
753
+ },
754
+ removed => {
755
+ }
756
+ },
757
+
758
+ 5.017007 => {
759
+ delta_from => 5.017006,
760
+ changed => {
761
+ },
762
+ removed => {
763
+ }
764
+ },
765
+
766
+ 5.017008 => {
767
+ delta_from => 5.017007,
768
+ changed => {
769
+ },
770
+ removed => {
771
+ }
772
+ },
773
+
774
+ 5.017009 => {
775
+ delta_from => 5.017008,
776
+ changed => {
777
+ },
778
+ removed => {
779
+ }
780
+ },
781
+
782
+ 5.014004 => {
783
+ delta_from => 5.014003,
784
+ changed => {
785
+ },
786
+ removed => {
787
+ }
788
+ },
789
+
790
+ 5.016003 => {
791
+ delta_from => 5.016002,
792
+ changed => {
793
+ },
794
+ removed => {
795
+ }
796
+ },
797
+
798
+ 5.017010 => {
799
+ delta_from => 5.017009,
800
+ changed => {
801
+ },
802
+ removed => {
803
+ }
804
+ },
805
+
806
+ 5.017011 => {
807
+ delta_from => 5.017010,
808
+ changed => {
809
+ },
810
+ removed => {
811
+ }
812
+ },
813
+ 5.018000 => {
814
+ delta_from => 5.017011,
815
+ changed => {
816
+ },
817
+ removed => {
818
+ }
819
+ },
820
+ 5.018001 => {
821
+ delta_from => 5.018000,
822
+ changed => {
823
+ },
824
+ removed => {
825
+ }
826
+ },
827
+ 5.018002 => {
828
+ delta_from => 5.018001,
829
+ changed => {
830
+ },
831
+ removed => {
832
+ }
833
+ },
834
+ 5.018003 => {
835
+ delta_from => 5.018000,
836
+ changed => {
837
+ },
838
+ removed => {
839
+ }
840
+ },
841
+ 5.018004 => {
842
+ delta_from => 5.018000,
843
+ changed => {
844
+ },
845
+ removed => {
846
+ }
847
+ },
848
+ 5.019000 => {
849
+ delta_from => 5.018000,
850
+ changed => {
851
+ },
852
+ removed => {
853
+ 'cpan2dist' => '1',
854
+ 'cpanp' => '1',
855
+ 'cpanp-run-perl' => '1',
856
+ 'pod2latex' => '1',
857
+ }
858
+ },
859
+ 5.019001 => {
860
+ delta_from => 5.019000,
861
+ changed => {
862
+ },
863
+ removed => {
864
+ }
865
+ },
866
+ 5.019002 => {
867
+ delta_from => 5.019001,
868
+ changed => {
869
+ },
870
+ removed => {
871
+ }
872
+ },
873
+ 5.019003 => {
874
+ delta_from => 5.019002,
875
+ changed => {
876
+ },
877
+ removed => {
878
+ }
879
+ },
880
+ 5.019004 => {
881
+ delta_from => 5.019003,
882
+ changed => {
883
+ },
884
+ removed => {
885
+ }
886
+ },
887
+ 5.019005 => {
888
+ delta_from => 5.019004,
889
+ changed => {
890
+ },
891
+ removed => {
892
+ }
893
+ },
894
+ 5.019006 => {
895
+ delta_from => 5.019005,
896
+ changed => {
897
+ },
898
+ removed => {
899
+ }
900
+ },
901
+ 5.019007 => {
902
+ delta_from => 5.019006,
903
+ changed => {
904
+ },
905
+ removed => {
906
+ }
907
+ },
908
+ 5.019008 => {
909
+ delta_from => 5.019007,
910
+ changed => {
911
+ },
912
+ removed => {
913
+ }
914
+ },
915
+ 5.019009 => {
916
+ delta_from => 5.019008,
917
+ changed => {
918
+ },
919
+ removed => {
920
+ }
921
+ },
922
+ 5.019010 => {
923
+ delta_from => 5.019009,
924
+ changed => {
925
+ },
926
+ removed => {
927
+ }
928
+ },
929
+ 5.019011 => {
930
+ delta_from => 5.019010,
931
+ changed => {
932
+ },
933
+ removed => {
934
+ }
935
+ },
936
+ 5.020000 => {
937
+ delta_from => 5.019011,
938
+ changed => {
939
+ },
940
+ removed => {
941
+ }
942
+ },
943
+ 5.021000 => {
944
+ delta_from => 5.020000,
945
+ changed => {
946
+ },
947
+ removed => {
948
+ }
949
+ },
950
+ 5.021001 => {
951
+ delta_from => 5.021000,
952
+ changed => {
953
+ },
954
+ removed => {
955
+ 'a2p' => 1,
956
+ 'config_data' => 1,
957
+ 'find2perl' => 1,
958
+ 'psed' => 1,
959
+ 's2p' => 1,
960
+ }
961
+ },
962
+ 5.021002 => {
963
+ delta_from => 5.021001,
964
+ changed => {
965
+ },
966
+ removed => {
967
+ }
968
+ },
969
+ 5.021003 => {
970
+ delta_from => 5.021002,
971
+ changed => {
972
+ },
973
+ removed => {
974
+ }
975
+ },
976
+ 5.020001 => {
977
+ delta_from => 5.02,
978
+ changed => {
979
+ },
980
+ removed => {
981
+ }
982
+ },
983
+ 5.021004 => {
984
+ delta_from => 5.021003,
985
+ changed => {
986
+ },
987
+ removed => {
988
+ }
989
+ },
990
+ 5.021005 => {
991
+ delta_from => 5.021004,
992
+ changed => {
993
+ },
994
+ removed => {
995
+ }
996
+ },
997
+ 5.021006 => {
998
+ delta_from => 5.021005,
999
+ changed => {
1000
+ },
1001
+ removed => {
1002
+ }
1003
+ },
1004
+ 5.021007 => {
1005
+ delta_from => 5.021006,
1006
+ changed => {
1007
+ },
1008
+ removed => {
1009
+ }
1010
+ },
1011
+ 5.021008 => {
1012
+ delta_from => 5.021007,
1013
+ changed => {
1014
+ },
1015
+ removed => {
1016
+ }
1017
+ },
1018
+ 5.020002 => {
1019
+ delta_from => 5.020001,
1020
+ changed => {
1021
+ },
1022
+ removed => {
1023
+ }
1024
+ },
1025
+ 5.021009 => {
1026
+ delta_from => 5.021008,
1027
+ changed => {
1028
+ 'encguess' => '1',
1029
+ },
1030
+ removed => {
1031
+ }
1032
+ },
1033
+ 5.021010 => {
1034
+ delta_from => 5.021009,
1035
+ changed => {
1036
+ },
1037
+ removed => {
1038
+ }
1039
+ },
1040
+ 5.021011 => {
1041
+ delta_from => 5.02101,
1042
+ changed => {
1043
+ },
1044
+ removed => {
1045
+ }
1046
+ },
1047
+ 5.022000 => {
1048
+ delta_from => 5.021011,
1049
+ changed => {
1050
+ },
1051
+ removed => {
1052
+ }
1053
+ },
1054
+ 5.023000 => {
1055
+ delta_from => 5.022000,
1056
+ changed => {
1057
+ },
1058
+ removed => {
1059
+ }
1060
+ },
1061
+ 5.023001 => {
1062
+ delta_from => 5.023,
1063
+ changed => {
1064
+ },
1065
+ removed => {
1066
+ }
1067
+ },
1068
+ 5.023002 => {
1069
+ delta_from => 5.023001,
1070
+ changed => {
1071
+ },
1072
+ removed => {
1073
+ }
1074
+ },
1075
+ 5.020003 => {
1076
+ delta_from => 5.020002,
1077
+ changed => {
1078
+ },
1079
+ removed => {
1080
+ }
1081
+ },
1082
+ 5.023003 => {
1083
+ delta_from => 5.023002,
1084
+ changed => {
1085
+ },
1086
+ removed => {
1087
+ }
1088
+ },
1089
+ 5.023004 => {
1090
+ delta_from => 5.023003,
1091
+ changed => {
1092
+ },
1093
+ removed => {
1094
+ }
1095
+ },
1096
+ 5.023005 => {
1097
+ delta_from => 5.023004,
1098
+ changed => {
1099
+ },
1100
+ removed => {
1101
+ }
1102
+ },
1103
+ 5.022001 => {
1104
+ delta_from => 5.022,
1105
+ changed => {
1106
+ },
1107
+ removed => {
1108
+ }
1109
+ },
1110
+ 5.023006 => {
1111
+ delta_from => 5.023005,
1112
+ changed => {
1113
+ },
1114
+ removed => {
1115
+ }
1116
+ },
1117
+ 5.023007 => {
1118
+ delta_from => 5.023006,
1119
+ changed => {
1120
+ },
1121
+ removed => {
1122
+ }
1123
+ },
1124
+ 5.023008 => {
1125
+ delta_from => 5.023007,
1126
+ changed => {
1127
+ },
1128
+ removed => {
1129
+ }
1130
+ },
1131
+ 5.023009 => {
1132
+ delta_from => 5.023008,
1133
+ changed => {
1134
+ },
1135
+ removed => {
1136
+ }
1137
+ },
1138
+ 5.022002 => {
1139
+ delta_from => 5.022001,
1140
+ changed => {
1141
+ },
1142
+ removed => {
1143
+ }
1144
+ },
1145
+ 5.024000 => {
1146
+ delta_from => 5.023009,
1147
+ changed => {
1148
+ },
1149
+ removed => {
1150
+ }
1151
+ },
1152
+ 5.025000 => {
1153
+ delta_from => 5.024000,
1154
+ changed => {
1155
+ },
1156
+ removed => {
1157
+ }
1158
+ },
1159
+ 5.025001 => {
1160
+ delta_from => 5.025000,
1161
+ changed => {
1162
+ },
1163
+ removed => {
1164
+ }
1165
+ },
1166
+ 5.025002 => {
1167
+ delta_from => 5.025001,
1168
+ changed => {
1169
+ },
1170
+ removed => {
1171
+ }
1172
+ },
1173
+ 5.025003 => {
1174
+ delta_from => 5.025002,
1175
+ changed => {
1176
+ },
1177
+ removed => {
1178
+ }
1179
+ },
1180
+ 5.025004 => {
1181
+ delta_from => 5.025003,
1182
+ changed => {
1183
+ },
1184
+ removed => {
1185
+ }
1186
+ },
1187
+ 5.025005 => {
1188
+ delta_from => 5.025004,
1189
+ changed => {
1190
+ },
1191
+ removed => {
1192
+ }
1193
+ },
1194
+ 5.025006 => {
1195
+ delta_from => 5.025005,
1196
+ changed => {
1197
+ },
1198
+ removed => {
1199
+ }
1200
+ },
1201
+ 5.025007 => {
1202
+ delta_from => 5.025006,
1203
+ changed => {
1204
+ },
1205
+ removed => {
1206
+ }
1207
+ },
1208
+ 5.025008 => {
1209
+ delta_from => 5.025007,
1210
+ changed => {
1211
+ },
1212
+ removed => {
1213
+ }
1214
+ },
1215
+ 5.022003 => {
1216
+ delta_from => 5.022002,
1217
+ changed => {
1218
+ },
1219
+ removed => {
1220
+ }
1221
+ },
1222
+ 5.024001 => {
1223
+ delta_from => 5.024000,
1224
+ changed => {
1225
+ },
1226
+ removed => {
1227
+ }
1228
+ },
1229
+ 5.025009 => {
1230
+ delta_from => 5.025008,
1231
+ changed => {
1232
+ },
1233
+ removed => {
1234
+ 'c2ph' => 1,
1235
+ 'pstruct' => 1,
1236
+ }
1237
+ },
1238
+ 5.025010 => {
1239
+ delta_from => 5.025009,
1240
+ changed => {
1241
+ },
1242
+ removed => {
1243
+ }
1244
+ },
1245
+ 5.025011 => {
1246
+ delta_from => 5.025010,
1247
+ changed => {
1248
+ },
1249
+ removed => {
1250
+ }
1251
+ },
1252
+ 5.025012 => {
1253
+ delta_from => 5.025011,
1254
+ changed => {
1255
+ },
1256
+ removed => {
1257
+ }
1258
+ },
1259
+ 5.026000 => {
1260
+ delta_from => 5.025012,
1261
+ changed => {
1262
+ },
1263
+ removed => {
1264
+ }
1265
+ },
1266
+ 5.027000 => {
1267
+ delta_from => 5.026000,
1268
+ changed => {
1269
+ },
1270
+ removed => {
1271
+ }
1272
+ },
1273
+ 5.027001 => {
1274
+ delta_from => 5.027000,
1275
+ changed => {
1276
+ },
1277
+ removed => {
1278
+ }
1279
+ },
1280
+ 5.022004 => {
1281
+ delta_from => 5.022003,
1282
+ changed => {
1283
+ },
1284
+ removed => {
1285
+ }
1286
+ },
1287
+ 5.024002 => {
1288
+ delta_from => 5.024001,
1289
+ changed => {
1290
+ },
1291
+ removed => {
1292
+ }
1293
+ },
1294
+ 5.027002 => {
1295
+ delta_from => 5.027001,
1296
+ changed => {
1297
+ },
1298
+ removed => {
1299
+ }
1300
+ },
1301
+ 5.027003 => {
1302
+ delta_from => 5.027002,
1303
+ changed => {
1304
+ },
1305
+ removed => {
1306
+ }
1307
+ },
1308
+ 5.027004 => {
1309
+ delta_from => 5.027003,
1310
+ changed => {
1311
+ },
1312
+ removed => {
1313
+ }
1314
+ },
1315
+ 5.024003 => {
1316
+ delta_from => 5.024002,
1317
+ changed => {
1318
+ },
1319
+ removed => {
1320
+ }
1321
+ },
1322
+ 5.026001 => {
1323
+ delta_from => 5.026000,
1324
+ changed => {
1325
+ },
1326
+ removed => {
1327
+ }
1328
+ },
1329
+ 5.027005 => {
1330
+ delta_from => 5.027004,
1331
+ changed => {
1332
+ },
1333
+ removed => {
1334
+ }
1335
+ },
1336
+ 5.027006 => {
1337
+ delta_from => 5.027005,
1338
+ changed => {
1339
+ },
1340
+ removed => {
1341
+ }
1342
+ },
1343
+ 5.027007 => {
1344
+ delta_from => 5.027006,
1345
+ changed => {
1346
+ },
1347
+ removed => {
1348
+ }
1349
+ },
1350
+ 5.027008 => {
1351
+ delta_from => 5.027007,
1352
+ changed => {
1353
+ },
1354
+ removed => {
1355
+ }
1356
+ },
1357
+ 5.027009 => {
1358
+ delta_from => 5.027008,
1359
+ changed => {
1360
+ },
1361
+ removed => {
1362
+ }
1363
+ },
1364
+ 5.027010 => {
1365
+ delta_from => 5.027009,
1366
+ changed => {
1367
+ },
1368
+ removed => {
1369
+ }
1370
+ },
1371
+ 5.024004 => {
1372
+ delta_from => 5.024003,
1373
+ changed => {
1374
+ },
1375
+ removed => {
1376
+ }
1377
+ },
1378
+ 5.026002 => {
1379
+ delta_from => 5.026001,
1380
+ changed => {
1381
+ },
1382
+ removed => {
1383
+ }
1384
+ },
1385
+ 5.027011 => {
1386
+ delta_from => 5.027010,
1387
+ changed => {
1388
+ },
1389
+ removed => {
1390
+ }
1391
+ },
1392
+ 5.028000 => {
1393
+ delta_from => 5.027011,
1394
+ changed => {
1395
+ },
1396
+ removed => {
1397
+ }
1398
+ },
1399
+ 5.029000 => {
1400
+ delta_from => 5.028,
1401
+ changed => {
1402
+ },
1403
+ removed => {
1404
+ }
1405
+ },
1406
+ 5.029001 => {
1407
+ delta_from => 5.029000,
1408
+ changed => {
1409
+ },
1410
+ removed => {
1411
+ }
1412
+ },
1413
+ 5.029002 => {
1414
+ delta_from => 5.029001,
1415
+ changed => {
1416
+ },
1417
+ removed => {
1418
+ }
1419
+ },
1420
+ 5.029003 => {
1421
+ delta_from => 5.029002,
1422
+ changed => {
1423
+ },
1424
+ removed => {
1425
+ }
1426
+ },
1427
+ 5.029004 => {
1428
+ delta_from => 5.029003,
1429
+ changed => {
1430
+ },
1431
+ removed => {
1432
+ }
1433
+ },
1434
+ 5.029005 => {
1435
+ delta_from => 5.029004,
1436
+ changed => {
1437
+ },
1438
+ removed => {
1439
+ }
1440
+ },
1441
+ 5.026003 => {
1442
+ delta_from => 5.026002,
1443
+ changed => {
1444
+ },
1445
+ removed => {
1446
+ }
1447
+ },
1448
+ 5.028001 => {
1449
+ delta_from => 5.028000,
1450
+ changed => {
1451
+ },
1452
+ removed => {
1453
+ }
1454
+ },
1455
+ 5.029006 => {
1456
+ delta_from => 5.029005,
1457
+ changed => {
1458
+ },
1459
+ removed => {
1460
+ }
1461
+ },
1462
+ 5.029007 => {
1463
+ delta_from => 5.029006,
1464
+ changed => {
1465
+ },
1466
+ removed => {
1467
+ }
1468
+ },
1469
+ 5.029008 => {
1470
+ delta_from => 5.029007,
1471
+ changed => {
1472
+ },
1473
+ removed => {
1474
+ }
1475
+ },
1476
+ 5.029009 => {
1477
+ delta_from => 5.029008,
1478
+ changed => {
1479
+ },
1480
+ removed => {
1481
+ }
1482
+ },
1483
+ 5.028002 => {
1484
+ delta_from => 5.028001,
1485
+ changed => {
1486
+ },
1487
+ removed => {
1488
+ }
1489
+ },
1490
+ 5.029010 => {
1491
+ delta_from => 5.029009,
1492
+ changed => {
1493
+ },
1494
+ removed => {
1495
+ }
1496
+ },
1497
+ 5.030000 => {
1498
+ delta_from => 5.029010,
1499
+ changed => {
1500
+ },
1501
+ removed => {
1502
+ }
1503
+ },
1504
+ 5.031000 => {
1505
+ delta_from => 5.03,
1506
+ changed => {
1507
+ },
1508
+ removed => {
1509
+ }
1510
+ },
1511
+ 5.031001 => {
1512
+ delta_from => 5.031,
1513
+ changed => {
1514
+ },
1515
+ removed => {
1516
+ 'podselect' => 1,
1517
+ }
1518
+ },
1519
+ 5.031002 => {
1520
+ delta_from => 5.031001,
1521
+ changed => {
1522
+ },
1523
+ removed => {
1524
+ }
1525
+ },
1526
+ 5.031003 => {
1527
+ delta_from => 5.031002,
1528
+ changed => {
1529
+ },
1530
+ removed => {
1531
+ }
1532
+ },
1533
+ 5.031004 => {
1534
+ delta_from => 5.031003,
1535
+ changed => {
1536
+ },
1537
+ removed => {
1538
+ }
1539
+ },
1540
+ 5.031005 => {
1541
+ delta_from => 5.031004,
1542
+ changed => {
1543
+ },
1544
+ removed => {
1545
+ }
1546
+ },
1547
+ 5.030001 => {
1548
+ delta_from => 5.03,
1549
+ changed => {
1550
+ },
1551
+ removed => {
1552
+ }
1553
+ },
1554
+ 5.031006 => {
1555
+ delta_from => 5.031005,
1556
+ changed => {
1557
+ 'streamzip' => '1',
1558
+ },
1559
+ removed => {
1560
+ }
1561
+ },
1562
+ 5.031007 => {
1563
+ delta_from => 5.031006,
1564
+ changed => {
1565
+ },
1566
+ removed => {
1567
+ }
1568
+ },
1569
+ 5.031008 => {
1570
+ delta_from => 5.031007,
1571
+ changed => {
1572
+ },
1573
+ removed => {
1574
+ }
1575
+ },
1576
+ 5.031009 => {
1577
+ delta_from => 5.031008,
1578
+ changed => {
1579
+ },
1580
+ removed => {
1581
+ }
1582
+ },
1583
+ 5.030002 => {
1584
+ delta_from => 5.030001,
1585
+ changed => {
1586
+ },
1587
+ removed => {
1588
+ }
1589
+ },
1590
+ 5.031010 => {
1591
+ delta_from => 5.031009,
1592
+ changed => {
1593
+ },
1594
+ removed => {
1595
+ }
1596
+ },
1597
+ 5.031011 => {
1598
+ delta_from => 5.031010,
1599
+ changed => {
1600
+ },
1601
+ removed => {
1602
+ }
1603
+ },
1604
+ 5.028003 => {
1605
+ delta_from => 5.028002,
1606
+ changed => {
1607
+ },
1608
+ removed => {
1609
+ }
1610
+ },
1611
+ 5.030003 => {
1612
+ delta_from => 5.030002,
1613
+ changed => {
1614
+ },
1615
+ removed => {
1616
+ }
1617
+ },
1618
+ 5.032000 => {
1619
+ delta_from => 5.031011,
1620
+ changed => {
1621
+ },
1622
+ removed => {
1623
+ }
1624
+ },
1625
+ 5.033000 => {
1626
+ delta_from => 5.032,
1627
+ changed => {
1628
+ },
1629
+ removed => {
1630
+ }
1631
+ },
1632
+ 5.033001 => {
1633
+ delta_from => 5.033000,
1634
+ changed => {
1635
+ },
1636
+ removed => {
1637
+ }
1638
+ },
1639
+ 5.033002 => {
1640
+ delta_from => 5.033001,
1641
+ changed => {
1642
+ },
1643
+ removed => {
1644
+ }
1645
+ },
1646
+ 5.033003 => {
1647
+ delta_from => 5.033002,
1648
+ changed => {
1649
+ },
1650
+ removed => {
1651
+ }
1652
+ },
1653
+ 5.033004 => {
1654
+ delta_from => 5.033003,
1655
+ changed => {
1656
+ },
1657
+ removed => {
1658
+ }
1659
+ },
1660
+ 5.033005 => {
1661
+ delta_from => 5.033004,
1662
+ changed => {
1663
+ },
1664
+ removed => {
1665
+ }
1666
+ },
1667
+ 5.033006 => {
1668
+ delta_from => 5.033005,
1669
+ changed => {
1670
+ },
1671
+ removed => {
1672
+ }
1673
+ },
1674
+ 5.032001 => {
1675
+ delta_from => 5.032000,
1676
+ changed => {
1677
+ },
1678
+ removed => {
1679
+ }
1680
+ },
1681
+ 5.033007 => {
1682
+ delta_from => 5.033006,
1683
+ changed => {
1684
+ },
1685
+ removed => {
1686
+ }
1687
+ },
1688
+ 5.033008 => {
1689
+ delta_from => 5.033007,
1690
+ changed => {
1691
+ },
1692
+ removed => {
1693
+ }
1694
+ },
1695
+ 5.033009 => {
1696
+ delta_from => 5.033008,
1697
+ changed => {
1698
+ },
1699
+ removed => {
1700
+ }
1701
+ },
1702
+ 5.034000 => {
1703
+ delta_from => 5.033009,
1704
+ changed => {
1705
+ },
1706
+ removed => {
1707
+ }
1708
+ },
1709
+ 5.035000 => {
1710
+ delta_from => 5.034000,
1711
+ changed => {
1712
+ },
1713
+ removed => {
1714
+ }
1715
+ },
1716
+ 5.035001 => {
1717
+ delta_from => 5.035,
1718
+ changed => {
1719
+ },
1720
+ removed => {
1721
+ }
1722
+ },
1723
+ 5.035002 => {
1724
+ delta_from => 5.035001,
1725
+ changed => {
1726
+ },
1727
+ removed => {
1728
+ }
1729
+ },
1730
+ 5.035003 => {
1731
+ delta_from => 5.035002,
1732
+ changed => {
1733
+ },
1734
+ removed => {
1735
+ }
1736
+ },
1737
+ 5.035004 => {
1738
+ delta_from => 5.035003,
1739
+ changed => {
1740
+ },
1741
+ removed => {
1742
+ }
1743
+ },
1744
+ 5.035005 => {
1745
+ delta_from => 5.035004,
1746
+ changed => {
1747
+ },
1748
+ removed => {
1749
+ }
1750
+ },
1751
+ 5.035006 => {
1752
+ delta_from => 5.035005,
1753
+ changed => {
1754
+ },
1755
+ removed => {
1756
+ }
1757
+ },
1758
+ 5.035007 => {
1759
+ delta_from => 5.035006,
1760
+ changed => {
1761
+ },
1762
+ removed => {
1763
+ }
1764
+ },
1765
+ 5.035008 => {
1766
+ delta_from => 5.035007,
1767
+ changed => {
1768
+ },
1769
+ removed => {
1770
+ }
1771
+ },
1772
+ 5.035009 => {
1773
+ delta_from => 5.035008,
1774
+ changed => {
1775
+ },
1776
+ removed => {
1777
+ }
1778
+ },
1779
+ 5.034001 => {
1780
+ delta_from => 5.034000,
1781
+ changed => {
1782
+ },
1783
+ removed => {
1784
+ }
1785
+ },
1786
+ 5.035010 => {
1787
+ delta_from => 5.035009,
1788
+ changed => {
1789
+ },
1790
+ removed => {
1791
+ }
1792
+ },
1793
+ 5.035011 => {
1794
+ delta_from => 5.035010,
1795
+ changed => {
1796
+ },
1797
+ removed => {
1798
+ }
1799
+ },
1800
+ 5.036000 => {
1801
+ delta_from => 5.035011,
1802
+ changed => {
1803
+ },
1804
+ removed => {
1805
+ }
1806
+ },
1807
+ 5.037000 => {
1808
+ delta_from => 5.036000,
1809
+ changed => {
1810
+ },
1811
+ removed => {
1812
+ }
1813
+ },
1814
+ 5.037001 => {
1815
+ delta_from => 5.037,
1816
+ changed => {
1817
+ },
1818
+ removed => {
1819
+ }
1820
+ },
1821
+ 5.037002 => {
1822
+ delta_from => 5.037001,
1823
+ changed => {
1824
+ },
1825
+ removed => {
1826
+ }
1827
+ },
1828
+ 5.037003 => {
1829
+ delta_from => 5.037002,
1830
+ changed => {
1831
+ },
1832
+ removed => {
1833
+ }
1834
+ },
1835
+ 5.037004 => {
1836
+ delta_from => 5.037003,
1837
+ changed => {
1838
+ },
1839
+ removed => {
1840
+ }
1841
+ },
1842
+ 5.037005 => {
1843
+ delta_from => 5.037004,
1844
+ changed => {
1845
+ },
1846
+ removed => {
1847
+ }
1848
+ },
1849
+ 5.037006 => {
1850
+ delta_from => 5.037005,
1851
+ changed => {
1852
+ },
1853
+ removed => {
1854
+ }
1855
+ },
1856
+ 5.037007 => {
1857
+ delta_from => 5.037006,
1858
+ changed => {
1859
+ },
1860
+ removed => {
1861
+ }
1862
+ },
1863
+ 5.037008 => {
1864
+ delta_from => 5.037007,
1865
+ changed => {
1866
+ },
1867
+ removed => {
1868
+ }
1869
+ },
1870
+ 5.037009 => {
1871
+ delta_from => 5.037008,
1872
+ changed => {
1873
+ },
1874
+ removed => {
1875
+ }
1876
+ },
1877
+ 5.037010 => {
1878
+ delta_from => 5.037009,
1879
+ changed => {
1880
+ },
1881
+ removed => {
1882
+ }
1883
+ },
1884
+ 5.037011 => {
1885
+ delta_from => 5.03701,
1886
+ changed => {
1887
+ },
1888
+ removed => {
1889
+ }
1890
+ },
1891
+ 5.036001 => {
1892
+ delta_from => 5.036000,
1893
+ changed => {
1894
+ },
1895
+ removed => {
1896
+ }
1897
+ },
1898
+ 5.038000 => {
1899
+ delta_from => 5.037011,
1900
+ changed => {
1901
+ },
1902
+ removed => {
1903
+ }
1904
+ },
1905
+ 5.039001 => {
1906
+ delta_from => 5.038,
1907
+ changed => {
1908
+ },
1909
+ removed => {
1910
+ }
1911
+ },
1912
+ 5.039002 => {
1913
+ delta_from => 5.039001,
1914
+ changed => {
1915
+ },
1916
+ removed => {
1917
+ }
1918
+ },
1919
+ 5.039003 => {
1920
+ delta_from => 5.039002,
1921
+ changed => {
1922
+ },
1923
+ removed => {
1924
+ }
1925
+ },
1926
+ 5.039004 => {
1927
+ delta_from => 5.039003,
1928
+ changed => {
1929
+ },
1930
+ removed => {
1931
+ }
1932
+ },
1933
+ 5.039005 => {
1934
+ delta_from => 5.039004,
1935
+ changed => {
1936
+ },
1937
+ removed => {
1938
+ }
1939
+ },
1940
+ 5.034002 => {
1941
+ delta_from => 5.034001,
1942
+ changed => {
1943
+ },
1944
+ removed => {
1945
+ }
1946
+ },
1947
+ 5.036002 => {
1948
+ delta_from => 5.036001,
1949
+ changed => {
1950
+ },
1951
+ removed => {
1952
+ }
1953
+ },
1954
+ 5.038001 => {
1955
+ delta_from => 5.038000,
1956
+ changed => {
1957
+ },
1958
+ removed => {
1959
+ }
1960
+ },
1961
+ 5.034003 => {
1962
+ delta_from => 5.034002,
1963
+ changed => {
1964
+ },
1965
+ removed => {
1966
+ }
1967
+ },
1968
+ 5.036003 => {
1969
+ delta_from => 5.036002,
1970
+ changed => {
1971
+ },
1972
+ removed => {
1973
+ }
1974
+ },
1975
+ 5.038002 => {
1976
+ delta_from => 5.038001,
1977
+ changed => {
1978
+ },
1979
+ removed => {
1980
+ }
1981
+ },
1982
+ 5.039006 => {
1983
+ delta_from => 5.039005,
1984
+ changed => {
1985
+ },
1986
+ removed => {
1987
+ }
1988
+ },
1989
+ 5.039007 => {
1990
+ delta_from => 5.039006,
1991
+ changed => {
1992
+ },
1993
+ removed => {
1994
+ }
1995
+ },
1996
+ 5.039008 => {
1997
+ delta_from => 5.039007,
1998
+ changed => {
1999
+ },
2000
+ removed => {
2001
+ }
2002
+ },
2003
+ 5.039009 => {
2004
+ delta_from => 5.039008,
2005
+ changed => {
2006
+ },
2007
+ removed => {
2008
+ }
2009
+ },
2010
+ 5.039010 => {
2011
+ delta_from => 5.039009,
2012
+ changed => {
2013
+ },
2014
+ removed => {
2015
+ }
2016
+ },
2017
+ 5.040000 => {
2018
+ delta_from => 5.039010,
2019
+ changed => {
2020
+ },
2021
+ removed => {
2022
+ }
2023
+ },
2024
+ 5.041000 => {
2025
+ delta_from => 5.040000,
2026
+ changed => {
2027
+ },
2028
+ removed => {
2029
+ }
2030
+ },
2031
+ 5.041001 => {
2032
+ delta_from => 5.041000,
2033
+ changed => {
2034
+ },
2035
+ removed => {
2036
+ }
2037
+ },
2038
+ 5.041002 => {
2039
+ delta_from => 5.041001,
2040
+ changed => {
2041
+ },
2042
+ removed => {
2043
+ }
2044
+ },
2045
+ 5.041003 => {
2046
+ delta_from => 5.041002,
2047
+ changed => {
2048
+ },
2049
+ removed => {
2050
+ }
2051
+ },
2052
+ 5.041004 => {
2053
+ delta_from => 5.041003,
2054
+ changed => {
2055
+ },
2056
+ removed => {
2057
+ }
2058
+ },
2059
+ 5.041005 => {
2060
+ delta_from => 5.041004,
2061
+ changed => {
2062
+ },
2063
+ removed => {
2064
+ }
2065
+ },
2066
+ 5.041006 => {
2067
+ delta_from => 5.041005,
2068
+ changed => {
2069
+ },
2070
+ removed => {
2071
+ }
2072
+ },
2073
+ 5.041007 => {
2074
+ delta_from => 5.041006,
2075
+ changed => {
2076
+ },
2077
+ removed => {
2078
+ }
2079
+ },
2080
+ 5.038003 => {
2081
+ delta_from => 5.038002,
2082
+ changed => {
2083
+ },
2084
+ removed => {
2085
+ }
2086
+ },
2087
+ 5.040001 => {
2088
+ delta_from => 5.040000,
2089
+ changed => {
2090
+ },
2091
+ removed => {
2092
+ }
2093
+ },
2094
+ 5.041008 => {
2095
+ delta_from => 5.041007,
2096
+ changed => {
2097
+ },
2098
+ removed => {
2099
+ }
2100
+ },
2101
+ 5.041009 => {
2102
+ delta_from => 5.041008,
2103
+ changed => {
2104
+ },
2105
+ removed => {
2106
+ }
2107
+ },
2108
+ 5.041010 => {
2109
+ delta_from => 5.041009,
2110
+ changed => {
2111
+ },
2112
+ removed => {
2113
+ }
2114
+ },
2115
+ 5.038004 => {
2116
+ delta_from => 5.038003,
2117
+ changed => {
2118
+ },
2119
+ removed => {
2120
+ }
2121
+ },
2122
+ 5.040002 => {
2123
+ delta_from => 5.040001,
2124
+ changed => {
2125
+ },
2126
+ removed => {
2127
+ }
2128
+ },
2129
+ 5.041011 => {
2130
+ delta_from => 5.041010,
2131
+ changed => {
2132
+ },
2133
+ removed => {
2134
+ }
2135
+ },
2136
+ 5.041012 => {
2137
+ delta_from => 5.041011,
2138
+ changed => {
2139
+ },
2140
+ removed => {
2141
+ }
2142
+ },
2143
+ 5.041013 => {
2144
+ delta_from => 5.041012,
2145
+ changed => {
2146
+ },
2147
+ removed => {
2148
+ }
2149
+ },
2150
+ 5.042000 => {
2151
+ delta_from => 5.041013,
2152
+ changed => {
2153
+ },
2154
+ removed => {
2155
+ }
2156
+ },
2157
+ 5.043000 => {
2158
+ delta_from => 5.042000,
2159
+ changed => {
2160
+ },
2161
+ removed => {
2162
+ }
2163
+ },
2164
+ 5.043001 => {
2165
+ delta_from => 5.043,
2166
+ changed => {
2167
+ },
2168
+ removed => {
2169
+ }
2170
+ },
2171
+ 5.038005 => {
2172
+ delta_from => 5.038004,
2173
+ changed => {
2174
+ },
2175
+ removed => {
2176
+ }
2177
+ },
2178
+ 5.040003 => {
2179
+ delta_from => 5.040002,
2180
+ changed => {
2181
+ },
2182
+ removed => {
2183
+ }
2184
+ },
2185
+ 5.043002 => {
2186
+ delta_from => 5.043001,
2187
+ changed => {
2188
+ },
2189
+ removed => {
2190
+ }
2191
+ },
2192
+ 5.043003 => {
2193
+ delta_from => 5.043002,
2194
+ changed => {
2195
+ },
2196
+ removed => {
2197
+ }
2198
+ },
2199
+ 5.043004 => {
2200
+ delta_from => 5.043003,
2201
+ changed => {
2202
+ },
2203
+ removed => {
2204
+ }
2205
+ },
2206
+ 5.043005 => {
2207
+ delta_from => 5.043004,
2208
+ changed => {
2209
+ },
2210
+ removed => {
2211
+ }
2212
+ },
2213
+ 5.043006 => {
2214
+ delta_from => 5.043005,
2215
+ changed => {
2216
+ },
2217
+ removed => {
2218
+ }
2219
+ },
2220
+ 5.043007 => {
2221
+ delta_from => 5.043006,
2222
+ changed => {
2223
+ },
2224
+ removed => {
2225
+ }
2226
+ },
2227
+ 5.043008 => {
2228
+ delta_from => 5.043007,
2229
+ changed => {
2230
+ },
2231
+ removed => {
2232
+ }
2233
+ },
2234
+ 5.042001 => {
2235
+ delta_from => 5.042000,
2236
+ changed => {
2237
+ },
2238
+ removed => {
2239
+ }
2240
+ },
2241
+ 5.043009 => {
2242
+ delta_from => 5.043008,
2243
+ changed => {
2244
+ },
2245
+ removed => {
2246
+ }
2247
+ },
2248
+ 5.042002 => {
2249
+ delta_from => 5.042001,
2250
+ changed => {
2251
+ },
2252
+ removed => {
2253
+ }
2254
+ },
2255
+ );
2256
+
2257
+ %utilities = Module::CoreList::_undelta(\%delta);
2258
+
2259
+ # Create aliases with trailing zeros for $] use
2260
+
2261
+ $utilities{'5.000'} = $utilities{5};
2262
+
2263
+ _create_aliases(\%utilities);
2264
+
2265
+ sub _create_aliases {
2266
+ my ($hash) = @_;
2267
+
2268
+ for my $version (keys %$hash) {
2269
+ next unless $version >= 5.010;
2270
+
2271
+ my $padded = sprintf "%0.6f", $version;
2272
+
2273
+ # If the version in string form isn't the same as the numeric version,
2274
+ # alias it.
2275
+ if ($padded ne $version && $version == $padded) {
2276
+ $hash->{$padded} = $hash->{$version};
2277
+ }
2278
+ }
2279
+ }
2280
+
2281
+ 'foo';
2282
+
2283
+ =pod
2284
+
2285
+ =head1 NAME
2286
+
2287
+ Module::CoreList::Utils - what utilities shipped with versions of perl
2288
+
2289
+ =head1 SYNOPSIS
2290
+
2291
+ use Module::CoreList::Utils;
2292
+
2293
+ print $Module::CoreList::Utils::utilities{5.009003}{ptar}; # prints 1
2294
+
2295
+ print Module::CoreList::Utils->first_release('corelist');
2296
+ # prints 5.008009
2297
+
2298
+ print Module::CoreList::Utils->first_release_by_date('corelist');
2299
+ # prints 5.009002
2300
+
2301
+ =head1 DESCRIPTION
2302
+
2303
+ Module::CoreList::Utils provides information on which core and dual-life utilities shipped
2304
+ with each version of L<perl>.
2305
+
2306
+ It provides a number of mechanisms for querying this information.
2307
+
2308
+ There is a functional programming API available for programmers to query
2309
+ information.
2310
+
2311
+ Programmers may also query the contained hash structure to find relevant
2312
+ information.
2313
+
2314
+ =head1 FUNCTIONS API
2315
+
2316
+ These are the functions that are available, they may either be called as functions or class methods:
2317
+
2318
+ Module::CoreList::Utils::first_release('corelist'); # as a function
2319
+
2320
+ Module::CoreList::Utils->first_release('corelist'); # class method
2321
+
2322
+ =over
2323
+
2324
+ =item C<utilities>
2325
+
2326
+ Requires a perl version as an argument, returns a list of utilities that shipped with
2327
+ that version of perl, or undef/empty list if that perl doesn't exist.
2328
+
2329
+ =item C<first_release( UTILITY )>
2330
+
2331
+ Requires a UTILITY name as an argument, returns the perl version when that utility first
2332
+ appeared in core as ordered by perl version number or undef ( in scalar context )
2333
+ or an empty list ( in list context ) if that utility is not in core.
2334
+
2335
+ =item C<first_release_by_date( UTILITY )>
2336
+
2337
+ Requires a UTILITY name as an argument, returns the perl version when that utility first
2338
+ appeared in core as ordered by release date or undef ( in scalar context )
2339
+ or an empty list ( in list context ) if that utility is not in core.
2340
+
2341
+ =item C<removed_from( UTILITY )>
2342
+
2343
+ Takes a UTILITY name as an argument, returns the first perl version where that utility
2344
+ was removed from core. Returns undef if the given utility was never in core or remains
2345
+ in core.
2346
+
2347
+ =item C<removed_from_by_date( UTILITY )>
2348
+
2349
+ Takes a UTILITY name as an argument, returns the first perl version by release date where that
2350
+ utility was removed from core. Returns undef if the given utility was never in core or remains
2351
+ in core.
2352
+
2353
+ =back
2354
+
2355
+ =head1 DATA STRUCTURES
2356
+
2357
+ These are the hash data structures that are available:
2358
+
2359
+ =over
2360
+
2361
+ =item C<%Module::CoreList::Utils::utilities>
2362
+
2363
+ A hash of hashes that is keyed on perl version as indicated
2364
+ in $]. The second level hash is utility / defined pairs.
2365
+
2366
+ =back
2367
+
2368
+ =head1 AUTHOR
2369
+
2370
+ Chris C<BinGOs> Williams <chris@bingosnet.co.uk>
2371
+
2372
+ Currently maintained by the perl 5 porters E<lt>perl5-porters@perl.orgE<gt>.
2373
+
2374
+ This module is the result of archaeology undertaken during QA Hackathon
2375
+ in Lancaster, April 2013.
2376
+
2377
+ =head1 LICENSE
2378
+
2379
+ Copyright (C) 2013 Chris Williams. All Rights Reserved.
2380
+
2381
+ This module is free software; you can redistribute it and/or modify it
2382
+ under the same terms as Perl itself.
2383
+
2384
+ =head1 SEE ALSO
2385
+
2386
+ L<corelist>, L<Module::CoreList>, L<perl>, L<http://perlpunks.de/corelist>
2387
+
2388
+ =cut
git/usr/share/perl5/core_perl/Module/Load/Conditional.pm ADDED
@@ -0,0 +1,624 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package Module::Load::Conditional;
2
+
3
+ use strict;
4
+
5
+ use Module::Load qw/load autoload_remote/;
6
+ use Params::Check qw[check];
7
+ use Locale::Maketext::Simple Style => 'gettext';
8
+
9
+ use Carp ();
10
+ use File::Spec ();
11
+ use FileHandle ();
12
+ use version;
13
+
14
+ use Module::Metadata ();
15
+
16
+ use constant ON_VMS => $^O eq 'VMS';
17
+ use constant ON_WIN32 => $^O eq 'MSWin32' ? 1 : 0;
18
+ use constant QUOTE => do { ON_WIN32 ? q["] : q['] };
19
+
20
+ BEGIN {
21
+ use vars qw[ $VERSION @ISA $VERBOSE $CACHE @EXPORT_OK $DEPRECATED
22
+ $FIND_VERSION $ERROR $CHECK_INC_HASH $FORCE_SAFE_INC ];
23
+ use Exporter;
24
+ @ISA = qw[Exporter];
25
+ $VERSION = '0.74';
26
+ $VERBOSE = 0;
27
+ $DEPRECATED = 0;
28
+ $FIND_VERSION = 1;
29
+ $CHECK_INC_HASH = 0;
30
+ $FORCE_SAFE_INC = 0;
31
+ @EXPORT_OK = qw[check_install can_load requires];
32
+ }
33
+
34
+ =pod
35
+
36
+ =head1 NAME
37
+
38
+ Module::Load::Conditional - Looking up module information / loading at runtime
39
+
40
+ =head1 SYNOPSIS
41
+
42
+ use Module::Load::Conditional qw[can_load check_install requires];
43
+
44
+
45
+ my $use_list = {
46
+ CPANPLUS => 0.05,
47
+ LWP => 5.60,
48
+ 'Test::More' => undef,
49
+ };
50
+
51
+ print can_load( modules => $use_list )
52
+ ? 'all modules loaded successfully'
53
+ : 'failed to load required modules';
54
+
55
+
56
+ my $rv = check_install( module => 'LWP', version => 5.60 )
57
+ or print 'LWP is not installed!';
58
+
59
+ print 'LWP up to date' if $rv->{uptodate};
60
+ print "LWP version is $rv->{version}\n";
61
+ print "LWP is installed as file $rv->{file}\n";
62
+
63
+
64
+ print "LWP requires the following modules to be installed:\n";
65
+ print join "\n", requires('LWP');
66
+
67
+ ### allow M::L::C to peek in your %INC rather than just
68
+ ### scanning @INC
69
+ $Module::Load::Conditional::CHECK_INC_HASH = 1;
70
+
71
+ ### reset the 'can_load' cache
72
+ undef $Module::Load::Conditional::CACHE;
73
+
74
+ ### don't have Module::Load::Conditional issue warnings --
75
+ ### default is '1'
76
+ $Module::Load::Conditional::VERBOSE = 0;
77
+
78
+ ### The last error that happened during a call to 'can_load'
79
+ my $err = $Module::Load::Conditional::ERROR;
80
+
81
+
82
+ =head1 DESCRIPTION
83
+
84
+ Module::Load::Conditional provides simple ways to query and possibly load any of
85
+ the modules you have installed on your system during runtime.
86
+
87
+ It is able to load multiple modules at once or none at all if one of
88
+ them was not able to load. It also takes care of any error checking
89
+ and so forth.
90
+
91
+ =head1 Methods
92
+
93
+ =head2 $href = check_install( module => NAME [, version => VERSION, verbose => BOOL ] );
94
+
95
+ C<check_install> allows you to verify if a certain module is installed
96
+ or not. You may call it with the following arguments:
97
+
98
+ =over 4
99
+
100
+ =item module
101
+
102
+ The name of the module you wish to verify -- this is a required key
103
+
104
+ =item version
105
+
106
+ The version this module needs to be -- this is optional
107
+
108
+ =item verbose
109
+
110
+ Whether or not to be verbose about what it is doing -- it will default
111
+ to $Module::Load::Conditional::VERBOSE
112
+
113
+ =back
114
+
115
+ It will return undef if it was not able to find where the module was
116
+ installed, or a hash reference with the following keys if it was able
117
+ to find the file:
118
+
119
+ =over 4
120
+
121
+ =item file
122
+
123
+ Full path to the file that contains the module
124
+
125
+ =item dir
126
+
127
+ Directory, or more exact the C<@INC> entry, where the module was
128
+ loaded from.
129
+
130
+ =item version
131
+
132
+ The version number of the installed module - this will be C<undef> if
133
+ the module had no (or unparsable) version number, or if the variable
134
+ C<$Module::Load::Conditional::FIND_VERSION> was set to true.
135
+ (See the C<GLOBAL VARIABLES> section below for details)
136
+
137
+ =item uptodate
138
+
139
+ A boolean value indicating whether or not the module was found to be
140
+ at least the version you specified. If you did not specify a version,
141
+ uptodate will always be true if the module was found.
142
+ If no parsable version was found in the module, uptodate will also be
143
+ true, since C<check_install> had no way to verify clearly.
144
+
145
+ See also C<$Module::Load::Conditional::DEPRECATED>, which affects
146
+ the outcome of this value.
147
+
148
+ =back
149
+
150
+ =cut
151
+
152
+ ### this checks if a certain module is installed already ###
153
+ ### if it returns true, the module in question is already installed
154
+ ### or we found the file, but couldn't open it, OR there was no version
155
+ ### to be found in the module
156
+ ### it will return 0 if the version in the module is LOWER then the one
157
+ ### we are looking for, or if we couldn't find the desired module to begin with
158
+ ### if the installed version is higher or equal to the one we want, it will return
159
+ ### a hashref with he module name and version in it.. so 'true' as well.
160
+ sub check_install {
161
+ my %hash = @_;
162
+
163
+ my $tmpl = {
164
+ version => { default => '0.0' },
165
+ module => { required => 1 },
166
+ verbose => { default => $VERBOSE },
167
+ };
168
+
169
+ my $args;
170
+ unless( $args = check( $tmpl, \%hash, $VERBOSE ) ) {
171
+ warn loc( q[A problem occurred checking arguments] ) if $VERBOSE;
172
+ return;
173
+ }
174
+
175
+ my $file = File::Spec->catfile( split /::/, $args->{module} ) . '.pm';
176
+ my $file_inc = File::Spec::Unix->catfile(
177
+ split /::/, $args->{module}
178
+ ) . '.pm';
179
+
180
+ ### where we store the return value ###
181
+ my $href = {
182
+ file => undef,
183
+ version => undef,
184
+ uptodate => undef,
185
+ };
186
+
187
+ my $filename;
188
+
189
+ ### check the inc hash if we're allowed to
190
+ if( $CHECK_INC_HASH ) {
191
+ $filename = $href->{'file'} =
192
+ $INC{ $file_inc } if defined $INC{ $file_inc };
193
+
194
+ ### find the version by inspecting the package
195
+ if( defined $filename && $FIND_VERSION ) {
196
+ no strict 'refs';
197
+ $href->{version} = ${ "$args->{module}"."::VERSION" };
198
+ }
199
+ }
200
+
201
+ ### we didn't find the filename yet by looking in %INC,
202
+ ### so scan the dirs
203
+ unless( $filename ) {
204
+
205
+ local @INC = @INC[0..$#INC-1] if $FORCE_SAFE_INC && $INC[-1] eq '.';
206
+
207
+ DIR: for my $dir ( @INC ) {
208
+
209
+ my $fh;
210
+
211
+ if ( ref $dir ) {
212
+ ### @INC hook -- we invoke it and get the filehandle back
213
+ ### this is actually documented behaviour as of 5.8 ;)
214
+
215
+ my $existed_in_inc = $INC{$file_inc};
216
+
217
+ if (UNIVERSAL::isa($dir, 'CODE')) {
218
+ ($fh) = $dir->($dir, $file);
219
+
220
+ } elsif (UNIVERSAL::isa($dir, 'ARRAY')) {
221
+ ($fh) = $dir->[0]->($dir, $file, @{$dir}{1..$#{$dir}})
222
+
223
+ } elsif (UNIVERSAL::can($dir, 'INC')) {
224
+ ($fh) = $dir->INC($file);
225
+ }
226
+
227
+ if (!UNIVERSAL::isa($fh, 'GLOB')) {
228
+ warn loc(q[Cannot open file '%1': %2], $file, $!)
229
+ if $args->{verbose};
230
+ next;
231
+ }
232
+
233
+ $filename = $INC{$file_inc} || $file;
234
+
235
+ delete $INC{$file_inc} if not $existed_in_inc;
236
+
237
+ } else {
238
+ $filename = File::Spec->catfile($dir, $file);
239
+ next unless -e $filename;
240
+
241
+ $fh = FileHandle->new();
242
+ if (!$fh->open($filename)) {
243
+ warn loc(q[Cannot open file '%1': %2], $file, $!)
244
+ if $args->{verbose};
245
+ next;
246
+ }
247
+ }
248
+
249
+ ### store the directory we found the file in
250
+ $href->{dir} = $dir;
251
+
252
+ ### files need to be in unix format under vms,
253
+ ### or they might be loaded twice
254
+ $href->{file} = ON_VMS
255
+ ? VMS::Filespec::unixify( $filename )
256
+ : $filename;
257
+
258
+ ### if we don't need the version, we're done
259
+ last DIR unless $FIND_VERSION;
260
+
261
+ ### otherwise, the user wants us to find the version from files
262
+
263
+ {
264
+ local $SIG{__WARN__} = sub {};
265
+ my $ver = eval {
266
+ my $mod_info = Module::Metadata->new_from_handle( $fh, $filename );
267
+ $mod_info->version( $args->{module} );
268
+ };
269
+
270
+ if( defined $ver ) {
271
+ $href->{version} = $ver;
272
+
273
+ last DIR;
274
+ }
275
+ }
276
+ }
277
+ }
278
+
279
+ ### if we couldn't find the file, return undef ###
280
+ return unless defined $href->{file};
281
+
282
+ ### only complain if we're expected to find a version higher than 0.0 anyway
283
+ if( $FIND_VERSION and not defined $href->{version} ) {
284
+ { ### don't warn about the 'not numeric' stuff ###
285
+ local $^W;
286
+
287
+ ### if we got here, we didn't find the version
288
+ warn loc(q[Could not check version on '%1'], $args->{module} )
289
+ if $args->{verbose} and $args->{version} > 0;
290
+ }
291
+ $href->{uptodate} = 1;
292
+
293
+ } else {
294
+ ### don't warn about the 'not numeric' stuff ###
295
+ local $^W;
296
+
297
+ ### use qv(), as it will deal with developer release number
298
+ ### ie ones containing _ as well. This addresses bug report
299
+ ### #29348: Version compare logic doesn't handle alphas?
300
+ ###
301
+ ### Update from JPeacock: apparently qv() and version->new
302
+ ### are different things, and we *must* use version->new
303
+ ### here, or things like #30056 might start happening
304
+
305
+ ### We have to wrap this in an eval as version-0.82 raises
306
+ ### exceptions and not warnings now *sigh*
307
+
308
+ eval {
309
+
310
+ $href->{uptodate} =
311
+ version->new( $args->{version} ) <= version->new( $href->{version} )
312
+ ? 1
313
+ : 0;
314
+
315
+ };
316
+ }
317
+
318
+ if ( $DEPRECATED and "$]" >= 5.011 ) {
319
+ local @INC = @INC[0..$#INC-1] if $FORCE_SAFE_INC && $INC[-1] eq '.';
320
+ require Module::CoreList;
321
+ require Config;
322
+
323
+ no warnings 'once';
324
+ $href->{uptodate} = 0 if
325
+ exists $Module::CoreList::version{ 0+$] }{ $args->{module} } and
326
+ Module::CoreList::is_deprecated( $args->{module} ) and
327
+ $Config::Config{privlibexp} eq $href->{dir}
328
+ and $Config::Config{privlibexp} ne $Config::Config{sitelibexp};
329
+ }
330
+
331
+ return $href;
332
+ }
333
+
334
+ =head2 $bool = can_load( modules => { NAME => VERSION [,NAME => VERSION] }, [verbose => BOOL, nocache => BOOL, autoload => BOOL] )
335
+
336
+ C<can_load> will take a list of modules, optionally with version
337
+ numbers and determine if it is able to load them. If it can load *ALL*
338
+ of them, it will. If one or more are unloadable, none will be loaded.
339
+
340
+ This is particularly useful if you have More Than One Way (tm) to
341
+ solve a problem in a program, and only wish to continue down a path
342
+ if all modules could be loaded, and not load them if they couldn't.
343
+
344
+ This function uses the C<load> function or the C<autoload_remote> function
345
+ from Module::Load under the hood.
346
+
347
+ C<can_load> takes the following arguments:
348
+
349
+ =over 4
350
+
351
+ =item modules
352
+
353
+ This is a hashref of module/version pairs. The version indicates the
354
+ minimum version to load. If no version is provided, any version is
355
+ assumed to be good enough.
356
+
357
+ =item verbose
358
+
359
+ This controls whether warnings should be printed if a module failed
360
+ to load.
361
+ The default is to use the value of $Module::Load::Conditional::VERBOSE.
362
+
363
+ =item nocache
364
+
365
+ C<can_load> keeps its results in a cache, so it will not load the
366
+ same module twice, nor will it attempt to load a module that has
367
+ already failed to load before. By default, C<can_load> will check its
368
+ cache, but you can override that by setting C<nocache> to true.
369
+
370
+ =item autoload
371
+
372
+ This controls whether imports the functions of a loaded modules to the caller package. The default is no importing any functions.
373
+
374
+ See the C<autoload> function and the C<autoload_remote> function from L<Module::Load> for details.
375
+
376
+ =cut
377
+
378
+ sub can_load {
379
+ my %hash = @_;
380
+
381
+ my $tmpl = {
382
+ modules => { default => {}, strict_type => 1 },
383
+ verbose => { default => $VERBOSE },
384
+ nocache => { default => 0 },
385
+ autoload => { default => 0 },
386
+ };
387
+
388
+ my $args;
389
+
390
+ unless( $args = check( $tmpl, \%hash, $VERBOSE ) ) {
391
+ $ERROR = loc(q[Problem validating arguments!]);
392
+ warn $ERROR if $VERBOSE;
393
+ return;
394
+ }
395
+
396
+ ### layout of $CACHE:
397
+ ### $CACHE = {
398
+ ### $ module => {
399
+ ### usable => BOOL,
400
+ ### version => \d,
401
+ ### file => /path/to/file,
402
+ ### },
403
+ ### };
404
+
405
+ $CACHE ||= {}; # in case it was undef'd
406
+
407
+ my $error;
408
+ BLOCK: {
409
+ my $href = $args->{modules};
410
+
411
+ my @load;
412
+ for my $mod ( keys %$href ) {
413
+
414
+ next if $CACHE->{$mod}->{usable} && !$args->{nocache};
415
+
416
+ ### else, check if the hash key is defined already,
417
+ ### meaning $mod => 0,
418
+ ### indicating UNSUCCESSFUL prior attempt of usage
419
+
420
+ ### use qv(), as it will deal with developer release number
421
+ ### ie ones containing _ as well. This addresses bug report
422
+ ### #29348: Version compare logic doesn't handle alphas?
423
+ ###
424
+ ### Update from JPeacock: apparently qv() and version->new
425
+ ### are different things, and we *must* use version->new
426
+ ### here, or things like #30056 might start happening
427
+ if ( !$args->{nocache}
428
+ && defined $CACHE->{$mod}->{usable}
429
+ && (version->new( $CACHE->{$mod}->{version}||0 )
430
+ >= version->new( $href->{$mod} ) )
431
+ ) {
432
+ $error = loc( q[Already tried to use '%1', which was unsuccessful], $mod);
433
+ last BLOCK;
434
+ }
435
+
436
+ my $mod_data = check_install(
437
+ module => $mod,
438
+ version => $href->{$mod}
439
+ );
440
+
441
+ if( !$mod_data or !defined $mod_data->{file} ) {
442
+ $error = loc(q[Could not find or check module '%1'], $mod);
443
+ $CACHE->{$mod}->{usable} = 0;
444
+ last BLOCK;
445
+ }
446
+
447
+ map {
448
+ $CACHE->{$mod}->{$_} = $mod_data->{$_}
449
+ } qw[version file uptodate];
450
+
451
+ push @load, $mod;
452
+ }
453
+
454
+ for my $mod ( @load ) {
455
+
456
+ if ( $CACHE->{$mod}->{uptodate} ) {
457
+
458
+ local @INC = @INC[0..$#INC-1] if $FORCE_SAFE_INC && $INC[-1] eq '.';
459
+
460
+ if ( $args->{autoload} ) {
461
+ my $who = (caller())[0];
462
+ eval { autoload_remote $who, $mod };
463
+ } else {
464
+ eval { load $mod };
465
+ }
466
+
467
+ ### in case anything goes wrong, log the error, the fact
468
+ ### we tried to use this module and return 0;
469
+ if( $@ ) {
470
+ $error = $@;
471
+ $CACHE->{$mod}->{usable} = 0;
472
+ last BLOCK;
473
+ } else {
474
+ $CACHE->{$mod}->{usable} = 1;
475
+ }
476
+
477
+ ### module not found in @INC, store the result in
478
+ ### $CACHE and return 0
479
+ } else {
480
+
481
+ $error = loc(q[Module '%1' is not uptodate!], $mod);
482
+ $CACHE->{$mod}->{usable} = 0;
483
+ last BLOCK;
484
+ }
485
+ }
486
+
487
+ } # BLOCK
488
+
489
+ if( defined $error ) {
490
+ $ERROR = $error;
491
+ Carp::carp( loc(q|%1 [THIS MAY BE A PROBLEM!]|,$error) ) if $args->{verbose};
492
+ return;
493
+ } else {
494
+ return 1;
495
+ }
496
+ }
497
+
498
+ =back
499
+
500
+ =head2 @list = requires( MODULE );
501
+
502
+ C<requires> can tell you what other modules a particular module
503
+ requires. This is particularly useful when you're intending to write
504
+ a module for public release and are listing its prerequisites.
505
+
506
+ C<requires> takes but one argument: the name of a module.
507
+ It will then first check if it can actually load this module, and
508
+ return undef if it can't.
509
+ Otherwise, it will return a list of modules and pragmas that would
510
+ have been loaded on the module's behalf.
511
+
512
+ Note: The list C<require> returns has originated from your current
513
+ perl and your current install.
514
+
515
+ =cut
516
+
517
+ sub requires {
518
+ my $who = shift;
519
+
520
+ unless( check_install( module => $who ) ) {
521
+ warn loc(q[You do not have module '%1' installed], $who) if $VERBOSE;
522
+ return undef;
523
+ }
524
+
525
+ local @INC = @INC[0..$#INC-1] if $FORCE_SAFE_INC && $INC[-1] eq '.';
526
+
527
+ my $lib = join " ", map { qq["-I$_"] } @INC;
528
+ my $oneliner = 'print(join(qq[\n],map{qq[BONG=$_]}keys(%INC)),qq[\n])';
529
+ my $cmd = join '', qq["$^X" $lib -M$who -e], QUOTE, $oneliner, QUOTE;
530
+
531
+ return sort
532
+ grep { !/^$who$/ }
533
+ map { chomp; s|/|::|g; $_ }
534
+ grep { s|\.pm$||i; }
535
+ map { s!^BONG\=!!; $_ }
536
+ grep { m!^BONG\=! }
537
+ `$cmd`;
538
+ }
539
+
540
+ 1;
541
+
542
+ __END__
543
+
544
+ =head1 Global Variables
545
+
546
+ The behaviour of Module::Load::Conditional can be altered by changing the
547
+ following global variables:
548
+
549
+ =head2 $Module::Load::Conditional::VERBOSE
550
+
551
+ This controls whether Module::Load::Conditional will issue warnings and
552
+ explanations as to why certain things may have failed. If you set it
553
+ to 0, Module::Load::Conditional will not output any warnings.
554
+ The default is 0;
555
+
556
+ =head2 $Module::Load::Conditional::FIND_VERSION
557
+
558
+ This controls whether Module::Load::Conditional will try to parse
559
+ (and eval) the version from the module you're trying to load.
560
+
561
+ If you don't wish to do this, set this variable to C<false>. Understand
562
+ then that version comparisons are not possible, and Module::Load::Conditional
563
+ can not tell you what module version you have installed.
564
+ This may be desirable from a security or performance point of view.
565
+ Note that C<$FIND_VERSION> code runs safely under C<taint mode>.
566
+
567
+ The default is 1;
568
+
569
+ =head2 $Module::Load::Conditional::CHECK_INC_HASH
570
+
571
+ This controls whether C<Module::Load::Conditional> checks your
572
+ C<%INC> hash to see if a module is available. By default, only
573
+ C<@INC> is scanned to see if a module is physically on your
574
+ filesystem, or available via an C<@INC-hook>. Setting this variable
575
+ to C<true> will trust any entries in C<%INC> and return them for
576
+ you.
577
+
578
+ The default is 0;
579
+
580
+ =head2 $Module::Load::Conditional::FORCE_SAFE_INC
581
+
582
+ This controls whether C<Module::Load::Conditional> sanitises C<@INC>
583
+ by removing "C<.>". The current default setting is C<0>, but this
584
+ may change in a future release.
585
+
586
+ =head2 $Module::Load::Conditional::CACHE
587
+
588
+ This holds the cache of the C<can_load> function. If you explicitly
589
+ want to remove the current cache, you can set this variable to
590
+ C<undef>
591
+
592
+ =head2 $Module::Load::Conditional::ERROR
593
+
594
+ This holds a string of the last error that happened during a call to
595
+ C<can_load>. It is useful to inspect this when C<can_load> returns
596
+ C<undef>.
597
+
598
+ =head2 $Module::Load::Conditional::DEPRECATED
599
+
600
+ This controls whether C<Module::Load::Conditional> checks if
601
+ a dual-life core module has been deprecated. If this is set to
602
+ true C<check_install> will return false to C<uptodate>, if
603
+ a dual-life module is found to be loaded from C<$Config{privlibexp}>
604
+
605
+ The default is 0;
606
+
607
+ =head1 See Also
608
+
609
+ C<Module::Load>
610
+
611
+ =head1 BUG REPORTS
612
+
613
+ Please report bugs or other issues to E<lt>bug-module-load-conditional@rt.cpan.orgE<gt>.
614
+
615
+ =head1 AUTHOR
616
+
617
+ This module by Jos Boumans E<lt>kane@cpan.orgE<gt>.
618
+
619
+ =head1 COPYRIGHT
620
+
621
+ This library is free software; you may redistribute and/or modify it
622
+ under the same terms as Perl itself.
623
+
624
+ =cut
git/usr/share/perl5/core_perl/Net/FTP/A.pm ADDED
@@ -0,0 +1,115 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ##
2
+ ## Package to read/write on ASCII data connections
3
+ ##
4
+
5
+ package Net::FTP::A;
6
+
7
+ use 5.008001;
8
+
9
+ use strict;
10
+ use warnings;
11
+
12
+ use Carp;
13
+ use Net::FTP::dataconn;
14
+
15
+ our @ISA = qw(Net::FTP::dataconn);
16
+ our $VERSION = "3.15";
17
+
18
+ our $buf;
19
+
20
+ sub read {
21
+ my $data = shift;
22
+ local *buf = \$_[0];
23
+ shift;
24
+ my $size = shift || croak 'read($buf,$size,[$offset])';
25
+ my $timeout = @_ ? shift: $data->timeout;
26
+
27
+ if (length(${*$data}) < $size && !${*$data}{'net_ftp_eof'}) {
28
+ my $blksize = ${*$data}{'net_ftp_blksize'};
29
+ $blksize = $size if $size > $blksize;
30
+
31
+ my $l = 0;
32
+ my $n;
33
+
34
+ READ:
35
+ {
36
+ my $readbuf = defined(${*$data}{'net_ftp_cr'}) ? "\015" : '';
37
+
38
+ $data->can_read($timeout)
39
+ or croak "Timeout";
40
+
41
+ if ($n = sysread($data, $readbuf, $blksize, length $readbuf)) {
42
+ ${*$data}{'net_ftp_bytesread'} += $n;
43
+ ${*$data}{'net_ftp_cr'} =
44
+ substr($readbuf, -1) eq "\015"
45
+ ? chop($readbuf)
46
+ : undef;
47
+ }
48
+ else {
49
+ return
50
+ unless defined $n;
51
+
52
+ ${*$data}{'net_ftp_eof'} = 1;
53
+ }
54
+
55
+ $readbuf =~ s/\015\012/\n/sgo;
56
+ ${*$data} .= $readbuf;
57
+
58
+ unless (length(${*$data})) {
59
+
60
+ redo READ
61
+ if ($n > 0);
62
+
63
+ $size = length(${*$data})
64
+ if ($n == 0);
65
+ }
66
+ }
67
+ }
68
+
69
+ $buf = substr(${*$data}, 0, $size);
70
+ substr(${*$data}, 0, $size) = '';
71
+
72
+ length $buf;
73
+ }
74
+
75
+
76
+ sub write {
77
+ my $data = shift;
78
+ local *buf = \$_[0];
79
+ shift;
80
+ my $size = shift || croak 'write($buf,$size,[$timeout])';
81
+ my $timeout = @_ ? shift: $data->timeout;
82
+
83
+ my $nr = (my $tmp = substr($buf, 0, $size)) =~ tr/\r\n/\015\012/;
84
+ $tmp =~ s/(?<!\015)\012/\015\012/sg if $nr;
85
+ $tmp =~ s/^\015// if ${*$data}{'net_ftp_outcr'};
86
+ ${*$data}{'net_ftp_outcr'} = substr($tmp, -1) eq "\015";
87
+
88
+ # If the remote server has closed the connection we will be signal'd
89
+ # when we write. This can happen if the disk on the remote server fills up
90
+
91
+ local $SIG{PIPE} = 'IGNORE'
92
+ unless ($SIG{PIPE} || '') eq 'IGNORE'
93
+ or $^O eq 'MacOS';
94
+
95
+ my $len = length($tmp);
96
+ my $off = 0;
97
+ my $wrote = 0;
98
+
99
+ my $blksize = ${*$data}{'net_ftp_blksize'};
100
+
101
+ while ($len) {
102
+ $data->can_write($timeout)
103
+ or croak "Timeout";
104
+
105
+ $off += $wrote;
106
+ $wrote = syswrite($data, substr($tmp, $off), $len > $blksize ? $blksize : $len);
107
+ return
108
+ unless defined($wrote);
109
+ $len -= $wrote;
110
+ }
111
+
112
+ $size;
113
+ }
114
+
115
+ 1;
git/usr/share/perl5/core_perl/Net/FTP/E.pm ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package Net::FTP::E;
2
+
3
+ use 5.008001;
4
+
5
+ use strict;
6
+ use warnings;
7
+
8
+ use Net::FTP::I;
9
+
10
+ our @ISA = qw(Net::FTP::I);
11
+ our $VERSION = "3.15";
12
+
13
+ 1;
git/usr/share/perl5/core_perl/Net/FTP/I.pm ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ##
2
+ ## Package to read/write on BINARY data connections
3
+ ##
4
+
5
+ package Net::FTP::I;
6
+
7
+ use 5.008001;
8
+
9
+ use strict;
10
+ use warnings;
11
+
12
+ use Carp;
13
+ use Net::FTP::dataconn;
14
+
15
+ our @ISA = qw(Net::FTP::dataconn);
16
+ our $VERSION = "3.15";
17
+
18
+ our $buf;
19
+
20
+ sub read {
21
+ my $data = shift;
22
+ local *buf = \$_[0];
23
+ shift;
24
+ my $size = shift || croak 'read($buf,$size,[$timeout])';
25
+ my $timeout = @_ ? shift: $data->timeout;
26
+
27
+ my $n;
28
+
29
+ if ($size > length ${*$data} and !${*$data}{'net_ftp_eof'}) {
30
+ $data->can_read($timeout)
31
+ or croak "Timeout";
32
+
33
+ my $blksize = ${*$data}{'net_ftp_blksize'};
34
+ $blksize = $size if $size > $blksize;
35
+
36
+ unless ($n = sysread($data, ${*$data}, $blksize, length ${*$data})) {
37
+ return unless defined $n;
38
+ ${*$data}{'net_ftp_eof'} = 1;
39
+ }
40
+ }
41
+
42
+ $buf = substr(${*$data}, 0, $size);
43
+
44
+ $n = length($buf);
45
+
46
+ substr(${*$data}, 0, $n) = '';
47
+
48
+ ${*$data}{'net_ftp_bytesread'} += $n;
49
+
50
+ $n;
51
+ }
52
+
53
+
54
+ sub write {
55
+ my $data = shift;
56
+ local *buf = \$_[0];
57
+ shift;
58
+ my $size = shift || croak 'write($buf,$size,[$timeout])';
59
+ my $timeout = @_ ? shift: $data->timeout;
60
+
61
+ # If the remote server has closed the connection we will be signal'd
62
+ # when we write. This can happen if the disk on the remote server fills up
63
+
64
+ local $SIG{PIPE} = 'IGNORE'
65
+ unless ($SIG{PIPE} || '') eq 'IGNORE'
66
+ or $^O eq 'MacOS';
67
+ my $sent = $size;
68
+ my $off = 0;
69
+
70
+ my $blksize = ${*$data}{'net_ftp_blksize'};
71
+ while ($sent > 0) {
72
+ $data->can_write($timeout)
73
+ or croak "Timeout";
74
+
75
+ my $n = syswrite($data, $buf, $sent > $blksize ? $blksize : $sent, $off);
76
+ return unless defined($n);
77
+ $sent -= $n;
78
+ $off += $n;
79
+ }
80
+
81
+ $size;
82
+ }
83
+
84
+ 1;
git/usr/share/perl5/core_perl/Net/FTP/L.pm ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package Net::FTP::L;
2
+
3
+ use 5.008001;
4
+
5
+ use strict;
6
+ use warnings;
7
+
8
+ use Net::FTP::I;
9
+
10
+ our @ISA = qw(Net::FTP::I);
11
+ our $VERSION = "3.15";
12
+
13
+ 1;
git/usr/share/perl5/core_perl/Net/FTP/dataconn.pm ADDED
@@ -0,0 +1,237 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ##
2
+ ## Generic data connection package
3
+ ##
4
+
5
+ package Net::FTP::dataconn;
6
+
7
+ use 5.008001;
8
+
9
+ use strict;
10
+ use warnings;
11
+
12
+ use Carp;
13
+ use Errno;
14
+ use Net::Cmd;
15
+
16
+ our $VERSION = '3.15';
17
+
18
+ $Net::FTP::IOCLASS or die "please load Net::FTP before Net::FTP::dataconn";
19
+ our @ISA = $Net::FTP::IOCLASS;
20
+
21
+ sub reading {
22
+ my $data = shift;
23
+ ${*$data}{'net_ftp_bytesread'} = 0;
24
+ }
25
+
26
+
27
+ sub abort {
28
+ my $data = shift;
29
+ my $ftp = ${*$data}{'net_ftp_cmd'};
30
+
31
+ # no need to abort if we have finished the xfer
32
+ return $data->close
33
+ if ${*$data}{'net_ftp_eof'};
34
+
35
+ # for some reason if we continuously open RETR connections and not
36
+ # read a single byte, then abort them after a while the server will
37
+ # close our connection, this prevents the unexpected EOF on the
38
+ # command channel -- GMB
39
+ if (exists ${*$data}{'net_ftp_bytesread'}
40
+ && (${*$data}{'net_ftp_bytesread'} == 0))
41
+ {
42
+ my $buf = "";
43
+ my $timeout = $data->timeout;
44
+ $data->can_read($timeout) && sysread($data, $buf, 1);
45
+ }
46
+
47
+ ${*$data}{'net_ftp_eof'} = 1; # fake
48
+
49
+ $ftp->abort; # this will close me
50
+ }
51
+
52
+
53
+ sub _close {
54
+ my $data = shift;
55
+ my $ftp = ${*$data}{'net_ftp_cmd'};
56
+
57
+ $data->SUPER::close();
58
+
59
+ delete ${*$ftp}{'net_ftp_dataconn'}
60
+ if defined $ftp
61
+ && exists ${*$ftp}{'net_ftp_dataconn'}
62
+ && $data == ${*$ftp}{'net_ftp_dataconn'};
63
+ }
64
+
65
+
66
+ sub close {
67
+ my $data = shift;
68
+ my $ftp = ${*$data}{'net_ftp_cmd'};
69
+
70
+ if (exists ${*$data}{'net_ftp_bytesread'} && !${*$data}{'net_ftp_eof'}) {
71
+ my $junk;
72
+ eval { local($SIG{__DIE__}); $data->read($junk, 1, 0) };
73
+ return $data->abort unless ${*$data}{'net_ftp_eof'};
74
+ }
75
+
76
+ $data->_close;
77
+
78
+ return unless defined $ftp;
79
+
80
+ $ftp->response() == CMD_OK
81
+ && $ftp->message =~ /unique file name:\s*(\S*)\s*\)/
82
+ && (${*$ftp}{'net_ftp_unique'} = $1);
83
+
84
+ $ftp->status == CMD_OK;
85
+ }
86
+
87
+
88
+ sub _select {
89
+ my ($data, $timeout, $do_read) = @_;
90
+ my ($rin, $rout, $win, $wout, $tout, $nfound);
91
+
92
+ vec($rin = '', fileno($data), 1) = 1;
93
+
94
+ ($win, $rin) = ($rin, $win) unless $do_read;
95
+
96
+ while (1) {
97
+ $nfound = select($rout = $rin, $wout = $win, undef, $tout = $timeout);
98
+
99
+ last if $nfound >= 0;
100
+
101
+ croak "select: $!"
102
+ unless $!{EINTR};
103
+ }
104
+
105
+ $nfound;
106
+ }
107
+
108
+
109
+ sub can_read {
110
+ _select(@_[0, 1], 1);
111
+ }
112
+
113
+
114
+ sub can_write {
115
+ _select(@_[0, 1], 0);
116
+ }
117
+
118
+
119
+ sub cmd {
120
+ my $ftp = shift;
121
+
122
+ ${*$ftp}{'net_ftp_cmd'};
123
+ }
124
+
125
+
126
+ sub bytes_read {
127
+ my $ftp = shift;
128
+
129
+ ${*$ftp}{'net_ftp_bytesread'} || 0;
130
+ }
131
+
132
+ 1;
133
+
134
+ __END__
135
+
136
+ =head1 NAME
137
+
138
+ Net::FTP::dataconn - FTP Client data connection class
139
+
140
+ =head1 SYNOPSIS
141
+
142
+ # Perform IO operations on an FTP client data connection object:
143
+
144
+ $num_bytes_read = $obj->read($buffer, $size);
145
+ $num_bytes_read = $obj->read($buffer, $size, $timeout);
146
+
147
+ $num_bytes_written = $obj->write($buffer, $size);
148
+ $num_bytes_written = $obj->write($buffer, $size, $timeout);
149
+
150
+ $num_bytes_read_so_far = $obj->bytes_read();
151
+
152
+ $obj->abort();
153
+
154
+ $closed_successfully = $obj->close();
155
+
156
+ =head1 DESCRIPTION
157
+
158
+ Some of the methods defined in C<Net::FTP> return an object which will
159
+ be derived from this class. The dataconn class itself is derived from
160
+ the C<IO::Socket::INET> class, so any normal IO operations can be performed.
161
+ However the following methods are defined in the dataconn class and IO should
162
+ be performed using these.
163
+
164
+ =over 4
165
+
166
+ =item C<read($buffer, $size[, $timeout])>
167
+
168
+ Read C<$size> bytes of data from the server and place it into C<$buffer>, also
169
+ performing any <CRLF> translation necessary. C<$timeout> is optional, if not
170
+ given, the timeout value from the command connection will be used.
171
+
172
+ Returns the number of bytes read before any <CRLF> translation.
173
+
174
+ =item C<write($buffer, $size[, $timeout])>
175
+
176
+ Write C<$size> bytes of data from C<$buffer> to the server, also
177
+ performing any <CRLF> translation necessary. C<$timeout> is optional, if not
178
+ given, the timeout value from the command connection will be used.
179
+
180
+ Returns the number of bytes written before any <CRLF> translation.
181
+
182
+ =item C<bytes_read()>
183
+
184
+ Returns the number of bytes read so far.
185
+
186
+ =item C<abort()>
187
+
188
+ Abort the current data transfer.
189
+
190
+ =item C<close()>
191
+
192
+ Close the data connection and get a response from the FTP server. Returns
193
+ I<true> if the connection was closed successfully and the first digit of
194
+ the response from the server was a '2'.
195
+
196
+ =back
197
+
198
+ =head1 EXPORTS
199
+
200
+ I<None>.
201
+
202
+ =head1 KNOWN BUGS
203
+
204
+ I<None>.
205
+
206
+ =head1 AUTHOR
207
+
208
+ Graham Barr E<lt>L<gbarr@pobox.com|mailto:gbarr@pobox.com>E<gt>.
209
+
210
+ Steve Hay E<lt>L<shay@cpan.org|mailto:shay@cpan.org>E<gt> is now maintaining
211
+ libnet as of version 1.22_02.
212
+
213
+ =head1 COPYRIGHT
214
+
215
+ Copyright (C) 1997-2010 Graham Barr. All rights reserved.
216
+
217
+ Copyright (C) 2013-2014, 2020 Steve Hay. All rights reserved.
218
+
219
+ =head1 LICENCE
220
+
221
+ This module is free software; you can redistribute it and/or modify it under the
222
+ same terms as Perl itself, i.e. under the terms of either the GNU General Public
223
+ License or the Artistic License, as specified in the F<LICENCE> file.
224
+
225
+ =head1 VERSION
226
+
227
+ Version 3.15
228
+
229
+ =head1 DATE
230
+
231
+ 20 March 2023
232
+
233
+ =head1 HISTORY
234
+
235
+ See the F<Changes> file.
236
+
237
+ =cut
git/usr/share/perl5/core_perl/Parse/CPAN/Meta.pm ADDED
@@ -0,0 +1,370 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ use 5.008001;
2
+ use strict;
3
+ use warnings;
4
+ package Parse::CPAN::Meta;
5
+ # ABSTRACT: Parse META.yml and META.json CPAN metadata files
6
+
7
+ our $VERSION = '2.150010';
8
+
9
+ use Exporter;
10
+ use Carp 'croak';
11
+
12
+ our @ISA = qw/Exporter/;
13
+ our @EXPORT_OK = qw/Load LoadFile/;
14
+
15
+ sub load_file {
16
+ my ($class, $filename) = @_;
17
+
18
+ my $meta = _slurp($filename);
19
+
20
+ if ($filename =~ /\.ya?ml$/) {
21
+ return $class->load_yaml_string($meta);
22
+ }
23
+ elsif ($filename =~ /\.json$/) {
24
+ return $class->load_json_string($meta);
25
+ }
26
+ else {
27
+ $class->load_string($meta); # try to detect yaml/json
28
+ }
29
+ }
30
+
31
+ sub load_string {
32
+ my ($class, $string) = @_;
33
+ if ( $string =~ /^---/ ) { # looks like YAML
34
+ return $class->load_yaml_string($string);
35
+ }
36
+ elsif ( $string =~ /^\s*\{/ ) { # looks like JSON
37
+ return $class->load_json_string($string);
38
+ }
39
+ else { # maybe doc-marker-free YAML
40
+ return $class->load_yaml_string($string);
41
+ }
42
+ }
43
+
44
+ sub load_yaml_string {
45
+ my ($class, $string) = @_;
46
+ my $backend = $class->yaml_backend();
47
+ my $data = eval { no strict 'refs'; &{"$backend\::Load"}($string) };
48
+ croak $@ if $@;
49
+ return $data || {}; # in case document was valid but empty
50
+ }
51
+
52
+ sub load_json_string {
53
+ my ($class, $string) = @_;
54
+ require Encode;
55
+ # load_json_string takes characters, decode_json expects bytes
56
+ my $encoded = Encode::encode('UTF-8', $string, Encode::PERLQQ());
57
+ my $data = eval { $class->json_decoder()->can('decode_json')->($encoded) };
58
+ croak $@ if $@;
59
+ return $data || {};
60
+ }
61
+
62
+ sub yaml_backend {
63
+ if ($ENV{PERL_CORE} or not defined $ENV{PERL_YAML_BACKEND} ) {
64
+ _can_load( 'CPAN::Meta::YAML', 0.011 )
65
+ or croak "CPAN::Meta::YAML 0.011 is not available\n";
66
+ return "CPAN::Meta::YAML";
67
+ }
68
+ else {
69
+ my $backend = $ENV{PERL_YAML_BACKEND};
70
+ _can_load( $backend )
71
+ or croak "Could not load PERL_YAML_BACKEND '$backend'\n";
72
+ $backend->can("Load")
73
+ or croak "PERL_YAML_BACKEND '$backend' does not implement Load()\n";
74
+ return $backend;
75
+ }
76
+ }
77
+
78
+ sub json_decoder {
79
+ if ($ENV{PERL_CORE}) {
80
+ _can_load( 'JSON::PP' => 2.27300 )
81
+ or croak "JSON::PP 2.27300 is not available\n";
82
+ return 'JSON::PP';
83
+ }
84
+ if (my $decoder = $ENV{CPAN_META_JSON_DECODER}) {
85
+ _can_load( $decoder )
86
+ or croak "Could not load CPAN_META_JSON_DECODER '$decoder'\n";
87
+ $decoder->can('decode_json')
88
+ or croak "No decode_json sub provided by CPAN_META_JSON_DECODER '$decoder'\n";
89
+ return $decoder;
90
+ }
91
+ return $_[0]->json_backend;
92
+ }
93
+
94
+ sub json_backend {
95
+ if ($ENV{PERL_CORE}) {
96
+ _can_load( 'JSON::PP' => 2.27300 )
97
+ or croak "JSON::PP 2.27300 is not available\n";
98
+ return 'JSON::PP';
99
+ }
100
+ if (my $backend = $ENV{CPAN_META_JSON_BACKEND}) {
101
+ _can_load( $backend )
102
+ or croak "Could not load CPAN_META_JSON_BACKEND '$backend'\n";
103
+ $backend->can('new')
104
+ or croak "No constructor provided by CPAN_META_JSON_BACKEND '$backend'\n";
105
+ return $backend;
106
+ }
107
+ if (! $ENV{PERL_JSON_BACKEND} or $ENV{PERL_JSON_BACKEND} eq 'JSON::PP') {
108
+ _can_load( 'JSON::PP' => 2.27300 )
109
+ or croak "JSON::PP 2.27300 is not available\n";
110
+ return 'JSON::PP';
111
+ }
112
+ else {
113
+ _can_load( 'JSON' => 2.5 )
114
+ or croak "JSON 2.5 is required for " .
115
+ "\$ENV{PERL_JSON_BACKEND} = '$ENV{PERL_JSON_BACKEND}'\n";
116
+ return "JSON";
117
+ }
118
+ }
119
+
120
+ sub _slurp {
121
+ require Encode;
122
+ open my $fh, "<:raw", "$_[0]" ## no critic
123
+ or die "can't open $_[0] for reading: $!";
124
+ my $content = do { local $/; <$fh> };
125
+ $content = Encode::decode('UTF-8', $content, Encode::PERLQQ());
126
+ return $content;
127
+ }
128
+
129
+ sub _can_load {
130
+ my ($module, $version) = @_;
131
+ (my $file = $module) =~ s{::}{/}g;
132
+ $file .= ".pm";
133
+ return 1 if $INC{$file};
134
+ return 0 if exists $INC{$file}; # prior load failed
135
+ eval { require $file; 1 }
136
+ or return 0;
137
+ if ( defined $version ) {
138
+ eval { $module->VERSION($version); 1 }
139
+ or return 0;
140
+ }
141
+ return 1;
142
+ }
143
+
144
+ # Kept for backwards compatibility only
145
+ # Create an object from a file
146
+ sub LoadFile ($) { ## no critic
147
+ return Load(_slurp(shift));
148
+ }
149
+
150
+ # Parse a document from a string.
151
+ sub Load ($) { ## no critic
152
+ require CPAN::Meta::YAML;
153
+ my $object = eval { CPAN::Meta::YAML::Load(shift) };
154
+ croak $@ if $@;
155
+ return $object;
156
+ }
157
+
158
+ 1;
159
+
160
+ __END__
161
+
162
+ =pod
163
+
164
+ =encoding UTF-8
165
+
166
+ =head1 NAME
167
+
168
+ Parse::CPAN::Meta - Parse META.yml and META.json CPAN metadata files
169
+
170
+ =head1 VERSION
171
+
172
+ version 2.150010
173
+
174
+ =head1 SYNOPSIS
175
+
176
+ #############################################
177
+ # In your file
178
+
179
+ ---
180
+ name: My-Distribution
181
+ version: 1.23
182
+ resources:
183
+ homepage: "http://example.com/dist/My-Distribution"
184
+
185
+
186
+ #############################################
187
+ # In your program
188
+
189
+ use Parse::CPAN::Meta;
190
+
191
+ my $distmeta = Parse::CPAN::Meta->load_file('META.yml');
192
+
193
+ # Reading properties
194
+ my $name = $distmeta->{name};
195
+ my $version = $distmeta->{version};
196
+ my $homepage = $distmeta->{resources}{homepage};
197
+
198
+ =head1 DESCRIPTION
199
+
200
+ B<Parse::CPAN::Meta> is a parser for F<META.json> and F<META.yml> files, using
201
+ L<JSON::PP> and/or L<CPAN::Meta::YAML>.
202
+
203
+ B<Parse::CPAN::Meta> provides three methods: C<load_file>, C<load_json_string>,
204
+ and C<load_yaml_string>. These will read and deserialize CPAN metafiles, and
205
+ are described below in detail.
206
+
207
+ B<Parse::CPAN::Meta> provides a legacy API of only two functions,
208
+ based on the YAML functions of the same name. Wherever possible,
209
+ identical calling semantics are used. These may only be used with YAML sources.
210
+
211
+ All error reporting is done with exceptions (die'ing).
212
+
213
+ Note that META files are expected to be in UTF-8 encoding, only. When
214
+ converted string data, it must first be decoded from UTF-8.
215
+
216
+ =begin Pod::Coverage
217
+
218
+
219
+
220
+
221
+ =end Pod::Coverage
222
+
223
+ =head1 METHODS
224
+
225
+ =head2 load_file
226
+
227
+ my $metadata_structure = Parse::CPAN::Meta->load_file('META.json');
228
+
229
+ my $metadata_structure = Parse::CPAN::Meta->load_file('META.yml');
230
+
231
+ This method will read the named file and deserialize it to a data structure,
232
+ determining whether it should be JSON or YAML based on the filename.
233
+ The file will be read using the ":utf8" IO layer.
234
+
235
+ =head2 load_yaml_string
236
+
237
+ my $metadata_structure = Parse::CPAN::Meta->load_yaml_string($yaml_string);
238
+
239
+ This method deserializes the given string of YAML and returns the first
240
+ document in it. (CPAN metadata files should always have only one document.)
241
+ If the source was UTF-8 encoded, the string must be decoded before calling
242
+ C<load_yaml_string>.
243
+
244
+ =head2 load_json_string
245
+
246
+ my $metadata_structure = Parse::CPAN::Meta->load_json_string($json_string);
247
+
248
+ This method deserializes the given string of JSON and the result.
249
+ If the source was UTF-8 encoded, the string must be decoded before calling
250
+ C<load_json_string>.
251
+
252
+ =head2 load_string
253
+
254
+ my $metadata_structure = Parse::CPAN::Meta->load_string($some_string);
255
+
256
+ If you don't know whether a string contains YAML or JSON data, this method
257
+ will use some heuristics and guess. If it can't tell, it assumes YAML.
258
+
259
+ =head2 yaml_backend
260
+
261
+ my $backend = Parse::CPAN::Meta->yaml_backend;
262
+
263
+ Returns the module name of the YAML serializer. See L</ENVIRONMENT>
264
+ for details.
265
+
266
+ =head2 json_backend
267
+
268
+ my $backend = Parse::CPAN::Meta->json_backend;
269
+
270
+ Returns the module name of the JSON serializer. If C<CPAN_META_JSON_BACKEND>
271
+ is set, this will be whatever that's set to. If not, this will either
272
+ be L<JSON::PP> or L<JSON>. If C<PERL_JSON_BACKEND> is set,
273
+ this will return L<JSON> as further delegation is handled by
274
+ the L<JSON> module. See L</ENVIRONMENT> for details.
275
+
276
+ =head2 json_decoder
277
+
278
+ my $decoder = Parse::CPAN::Meta->json_decoder;
279
+
280
+ Returns the module name of the JSON decoder. Unlike L</json_backend>, this
281
+ is not necessarily a full L<JSON>-style module, but only something that will
282
+ provide a C<decode_json> subroutine. If C<CPAN_META_JSON_DECODER> is set,
283
+ this will be whatever that's set to. If not, this will be whatever has
284
+ been selected as L</json_backend>. See L</ENVIRONMENT> for more notes.
285
+
286
+ =head1 FUNCTIONS
287
+
288
+ For maintenance clarity, no functions are exported by default. These functions
289
+ are available for backwards compatibility only and are best avoided in favor of
290
+ C<load_file>.
291
+
292
+ =head2 Load
293
+
294
+ my @yaml = Parse::CPAN::Meta::Load( $string );
295
+
296
+ Parses a string containing a valid YAML stream into a list of Perl data
297
+ structures.
298
+
299
+ =head2 LoadFile
300
+
301
+ my @yaml = Parse::CPAN::Meta::LoadFile( 'META.yml' );
302
+
303
+ Reads the YAML stream from a file instead of a string.
304
+
305
+ =head1 ENVIRONMENT
306
+
307
+ =head2 CPAN_META_JSON_DECODER
308
+
309
+ By default, L<JSON::PP> will be used for deserializing JSON data. If the
310
+ C<CPAN_META_JSON_DECODER> environment variable exists, this is expected to
311
+ be the name of a loadable module that provides a C<decode_json> subroutine,
312
+ which will then be used for deserialization. Relying only on the existence
313
+ of said subroutine allows for maximum compatibility, since this API is
314
+ provided by all of L<JSON::PP>, L<JSON::XS>, L<Cpanel::JSON::XS>,
315
+ L<JSON::MaybeXS>, L<JSON::Tiny>, and L<Mojo::JSON>.
316
+
317
+ =head2 CPAN_META_JSON_BACKEND
318
+
319
+ By default, L<JSON::PP> will be used for deserializing JSON data. If the
320
+ C<CPAN_META_JSON_BACKEND> environment variable exists, this is expected to
321
+ be the name of a loadable module that provides the L<JSON> API, since
322
+ downstream code expects to be able to call C<new> on this class. As such,
323
+ while L<JSON::PP>, L<JSON::XS>, L<Cpanel::JSON::XS> and L<JSON::MaybeXS> will
324
+ work for this, to use L<Mojo::JSON> or L<JSON::Tiny> for decoding requires
325
+ setting L</CPAN_META_JSON_DECODER>.
326
+
327
+ =head2 PERL_JSON_BACKEND
328
+
329
+ If the C<CPAN_META_JSON_BACKEND> environment variable does not exist, and if
330
+ C<PERL_JSON_BACKEND> environment variable exists, is true and is not
331
+ "JSON::PP", then the L<JSON> module (version 2.5 or greater) will be loaded and
332
+ used to interpret C<PERL_JSON_BACKEND>. If L<JSON> is not installed or is too
333
+ old, an exception will be thrown. Note that at the time of writing, the only
334
+ useful values are 1, which will tell L<JSON> to guess, or L<JSON::XS> - if
335
+ you want to use a newer JSON module, see L</CPAN_META_JSON_BACKEND>.
336
+
337
+ =head2 PERL_YAML_BACKEND
338
+
339
+ By default, L<CPAN::Meta::YAML> will be used for deserializing YAML data. If
340
+ the C<PERL_YAML_BACKEND> environment variable is defined, then it is interpreted
341
+ as a module to use for deserialization. The given module must be installed,
342
+ must load correctly and must implement the C<Load()> function or an exception
343
+ will be thrown.
344
+
345
+ =head1 AUTHORS
346
+
347
+ =over 4
348
+
349
+ =item *
350
+
351
+ David Golden <dagolden@cpan.org>
352
+
353
+ =item *
354
+
355
+ Ricardo Signes <rjbs@cpan.org>
356
+
357
+ =item *
358
+
359
+ Adam Kennedy <adamk@cpan.org>
360
+
361
+ =back
362
+
363
+ =head1 COPYRIGHT AND LICENSE
364
+
365
+ This software is copyright (c) 2010 by David Golden, Ricardo Signes, Adam Kennedy and Contributors.
366
+
367
+ This is free software; you can redistribute it and/or modify it under
368
+ the same terms as the Perl 5 programming language system itself.
369
+
370
+ =cut
git/usr/share/perl5/core_perl/PerlIO/via/QuotedPrint.pm ADDED
@@ -0,0 +1,176 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (C) 2002-2004, 2012 Elizabeth Mattijsen. All rights reserved.
2
+ # Copyright (C) 2015 Steve Hay. All rights reserved.
3
+
4
+ # This module is free software; you can redistribute it and/or modify it under
5
+ # the same terms as Perl itself, i.e. under the terms of either the GNU General
6
+ # Public License or the Artistic License, as specified in the F<LICENCE> file.
7
+
8
+ package PerlIO::via::QuotedPrint;
9
+
10
+ use 5.008001;
11
+
12
+ # be as strict as possible
13
+ use strict;
14
+
15
+ our $VERSION = '0.10';
16
+
17
+ # modules that we need
18
+ use MIME::QuotedPrint (); # no need to pollute this namespace
19
+
20
+ # satisfy -require-
21
+ 1;
22
+
23
+ #-------------------------------------------------------------------------------
24
+ #
25
+ # Standard Perl features
26
+ #
27
+ #-------------------------------------------------------------------------------
28
+ # IN: 1 class to bless with
29
+ # 2 mode string (ignored)
30
+ # 3 file handle of PerlIO layer below (ignored)
31
+ # OUT: 1 blessed object
32
+
33
+ sub PUSHED { bless \*PUSHED,$_[0] } #PUSHED
34
+
35
+ #-------------------------------------------------------------------------------
36
+ # IN: 1 instantiated object (ignored)
37
+ # 2 handle to read from
38
+ # OUT: 1 decoded string
39
+
40
+ sub FILL {
41
+
42
+ # decode and return
43
+ my $line= readline( $_[1] );
44
+ return ( defined $line )
45
+ ? MIME::QuotedPrint::decode_qp($line)
46
+ : undef;
47
+ } #FILL
48
+
49
+ #-------------------------------------------------------------------------------
50
+ # IN: 1 instantiated object (ignored)
51
+ # 2 buffer to be written
52
+ # 3 handle to write to
53
+ # OUT: 1 number of bytes written
54
+
55
+ sub WRITE {
56
+
57
+ # encode and write to handle: indicate result
58
+ return ( print { $_[2] } MIME::QuotedPrint::encode_qp( $_[1] ) )
59
+ ? length( $_[1] )
60
+ : -1;
61
+ } #WRITE
62
+
63
+ #-------------------------------------------------------------------------------
64
+
65
+ __END__
66
+
67
+ =head1 NAME
68
+
69
+ PerlIO::via::QuotedPrint - PerlIO layer for quoted-printable strings
70
+
71
+ =head1 SYNOPSIS
72
+
73
+ use PerlIO::via::QuotedPrint;
74
+
75
+ open(my $in, '<:via(QuotedPrint)', 'file.qp') or
76
+ die "Can't open file.qp for reading: $!\n";
77
+
78
+ open(my $out, '>:via(QuotedPrint)', 'file.qp') or
79
+ die "Can't open file.qp for writing: $!\n";
80
+
81
+ =head1 DESCRIPTION
82
+
83
+ This module implements a PerlIO layer that works on files encoded in the
84
+ quoted-printable format. It will decode from quoted-printable while reading
85
+ from a handle, and it will encode as quoted-printable while writing to a handle.
86
+
87
+ =head1 EXPORTS
88
+
89
+ I<None>.
90
+
91
+ =head1 KNOWN BUGS
92
+
93
+ I<None>.
94
+
95
+ =head1 FEEDBACK
96
+
97
+ Patches, bug reports, suggestions or any other feedback is welcome.
98
+
99
+ Patches can be sent as GitHub pull requests at
100
+ L<https://github.com/steve-m-hay/PerlIO-via-QuotedPrint/pulls>.
101
+
102
+ Bug reports and suggestions can be made on the CPAN Request Tracker at
103
+ L<https://rt.cpan.org/Public/Bug/Report.html?Queue=PerlIO-via-QuotedPrint>.
104
+
105
+ Currently active requests on the CPAN Request Tracker can be viewed at
106
+ L<https://rt.cpan.org/Public/Dist/Display.html?Status=Active;Queue=PerlIO-via-QuotedPrint>.
107
+
108
+ Please test this distribution. See CPAN Testers Reports at
109
+ L<https://www.cpantesters.org/> for details of how to get involved.
110
+
111
+ Previous test results on CPAN Testers Reports can be viewed at
112
+ L<https://www.cpantesters.org/distro/P/PerlIO-via-QuotedPrint.html>.
113
+
114
+ Please rate this distribution on CPAN Ratings at
115
+ L<https://cpanratings.perl.org/rate/?distribution=PerlIO-via-QuotedPrint>.
116
+
117
+ =head1 SEE ALSO
118
+
119
+ L<PerlIO::via>,
120
+ L<MIME::QuotedPrint>.
121
+
122
+ =head1 ACKNOWLEDGEMENTS
123
+
124
+ Based on an example in the standard library module MIME::QuotedPrint in Perl
125
+ (version 5.8.0).
126
+
127
+ =head1 AVAILABILITY
128
+
129
+ The latest version of this module is available from CPAN (see
130
+ L<perlmodlib/"CPAN"> for details) at
131
+
132
+ L<https://metacpan.org/release/PerlIO-via-QuotedPrint> or
133
+
134
+ L<https://www.cpan.org/authors/id/S/SH/SHAY/> or
135
+
136
+ L<https://www.cpan.org/modules/by-module/PerlIO/>.
137
+
138
+ The latest source code is available from GitHub at
139
+ L<https://github.com/steve-m-hay/PerlIO-via-QuotedPrint>.
140
+
141
+ =head1 INSTALLATION
142
+
143
+ See the F<INSTALL> file.
144
+
145
+ =head1 AUTHOR
146
+
147
+ Elizabeth Mattijsen E<lt>L<liz@dijkmat.nl|mailto:liz@dijkmat.nl>E<gt>.
148
+
149
+ Steve Hay E<lt>L<shay@cpan.org|mailto:shay@cpan.org>E<gt> is now maintaining
150
+ PerlIO::via::QuotedPrint as of version 0.08.
151
+
152
+ =head1 COPYRIGHT
153
+
154
+ Copyright (C) 2002-2004, 2012 Elizabeth Mattijsen. All rights reserved.
155
+
156
+ Copyright (C) 2015, 2020 Steve Hay. All rights reserved.
157
+
158
+ =head1 LICENCE
159
+
160
+ This module is free software; you can redistribute it and/or modify it under
161
+ the same terms as Perl itself, i.e. under the terms of either the GNU General
162
+ Public License or the Artistic License, as specified in the F<LICENCE> file.
163
+
164
+ =head1 VERSION
165
+
166
+ Version 0.10
167
+
168
+ =head1 DATE
169
+
170
+ 22 May 2022
171
+
172
+ =head1 HISTORY
173
+
174
+ See the F<Changes> file.
175
+
176
+ =cut
git/usr/share/perl5/core_perl/Term/Table/Cell.pm ADDED
@@ -0,0 +1,147 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package Term::Table::Cell;
2
+ use strict;
3
+ use warnings;
4
+
5
+ our $VERSION = '0.024';
6
+
7
+ use Term::Table::LineBreak();
8
+ use Term::Table::Util qw/uni_length/;
9
+
10
+ use List::Util qw/sum/;
11
+
12
+ use Term::Table::HashBase qw/value border_left border_right _break _widths border_color value_color reset_color/;
13
+
14
+ my %CHAR_MAP = (
15
+ # Special case, \n should render as \n, but also actually do the newline thing
16
+ "\n" => "\\n\n",
17
+
18
+ "\a" => '\\a',
19
+ "\b" => '\\b',
20
+ "\e" => '\\e',
21
+ "\f" => '\\f',
22
+ "\r" => '\\r',
23
+ "\t" => '\\t',
24
+ " " => ' ',
25
+ );
26
+
27
+ sub init {
28
+ my $self = shift;
29
+
30
+ # Stringify
31
+ $self->{+VALUE} = defined $self->{+VALUE} ? "$self->{+VALUE}" : '';
32
+ }
33
+
34
+ sub char_id {
35
+ my $class = shift;
36
+ my ($char) = @_;
37
+ return "\\N{U+" . sprintf("\%X", utf8::native_to_unicode(ord($char))) . "}";
38
+ }
39
+
40
+ sub show_char {
41
+ my $class = shift;
42
+ my ($char, %props) = @_;
43
+ return $char if $props{no_newline} && $char eq "\n";
44
+ return $CHAR_MAP{$char} || $class->char_id($char);
45
+ }
46
+
47
+ sub sanitize {
48
+ my $self = shift;
49
+ $self->{+VALUE} =~ s/([\s\t\p{Zl}\p{C}\p{Zp}])/$self->show_char($1)/ge; # All whitespace except normal space
50
+ }
51
+
52
+ sub mark_tail {
53
+ my $self = shift;
54
+ $self->{+VALUE} =~ s/([\s\t\p{Zl}\p{C}\p{Zp}])$/$1 eq ' ' ? $self->char_id($1) : $self->show_char($1, no_newline => 1)/se;
55
+ }
56
+
57
+ sub value_width {
58
+ my $self = shift;
59
+
60
+ my $w = $self->{+_WIDTHS} ||= {};
61
+ return $w->{value} if defined $w->{value};
62
+
63
+ my @parts = split /(\n)/, $self->{+VALUE};
64
+
65
+ my $max = 0;
66
+ while (@parts) {
67
+ my $text = shift @parts;
68
+ my $sep = shift @parts || '';
69
+ my $len = uni_length("$text");
70
+ $max = $len if $len > $max;
71
+ }
72
+
73
+ return $w->{value} = $max;
74
+ }
75
+
76
+ sub border_left_width {
77
+ my $self = shift;
78
+ $self->{+_WIDTHS}->{left} ||= uni_length($self->{+BORDER_LEFT} || '');
79
+ }
80
+
81
+ sub border_right_width {
82
+ my $self = shift;
83
+ $self->{+_WIDTHS}->{right} ||= uni_length($self->{+BORDER_RIGHT} || '');
84
+ }
85
+
86
+ sub width {
87
+ my $self = shift;
88
+ $self->{+_WIDTHS}->{all} ||= sum(map { $self->$_ } qw/value_width border_left_width border_right_width/);
89
+ }
90
+
91
+ sub break {
92
+ my $self = shift;
93
+ $self->{+_BREAK} ||= Term::Table::LineBreak->new(string => $self->{+VALUE});
94
+ }
95
+
96
+ sub reset {
97
+ my $self = shift;
98
+ delete $self->{+_BREAK};
99
+ }
100
+
101
+ 1;
102
+
103
+ __END__
104
+
105
+ =pod
106
+
107
+ =encoding UTF-8
108
+
109
+ =head1 NAME
110
+
111
+ Term::Table::Cell - Representation of a cell in a table.
112
+
113
+ =head1 DESCRIPTION
114
+
115
+ This package is used to represent a cell in a table.
116
+
117
+ =head1 SOURCE
118
+
119
+ The source code repository for Term-Table can be found at
120
+ F<http://github.com/exodist/Term-Table/>.
121
+
122
+ =head1 MAINTAINERS
123
+
124
+ =over 4
125
+
126
+ =item Chad Granum E<lt>exodist@cpan.orgE<gt>
127
+
128
+ =back
129
+
130
+ =head1 AUTHORS
131
+
132
+ =over 4
133
+
134
+ =item Chad Granum E<lt>exodist@cpan.orgE<gt>
135
+
136
+ =back
137
+
138
+ =head1 COPYRIGHT
139
+
140
+ Copyright 2016 Chad Granum E<lt>exodist@cpan.orgE<gt>.
141
+
142
+ This program is free software; you can redistribute it and/or
143
+ modify it under the same terms as Perl itself.
144
+
145
+ See F<http://dev.perl.org/licenses/>
146
+
147
+ =cut
git/usr/share/perl5/core_perl/Term/Table/CellStack.pm ADDED
@@ -0,0 +1,130 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package Term::Table::CellStack;
2
+ use strict;
3
+ use warnings;
4
+
5
+ our $VERSION = '0.024';
6
+
7
+ use Term::Table::HashBase qw/-cells -idx/;
8
+
9
+ use List::Util qw/max/;
10
+
11
+ sub init {
12
+ my $self = shift;
13
+ $self->{+CELLS} ||= [];
14
+ }
15
+
16
+ sub add_cell {
17
+ my $self = shift;
18
+ push @{$self->{+CELLS}} => @_;
19
+ }
20
+
21
+ sub add_cells {
22
+ my $self = shift;
23
+ push @{$self->{+CELLS}} => @_;
24
+ }
25
+
26
+ sub sanitize {
27
+ my $self = shift;
28
+ $_->sanitize(@_) for @{$self->{+CELLS}};
29
+ }
30
+
31
+ sub mark_tail {
32
+ my $self = shift;
33
+ $_->mark_tail(@_) for @{$self->{+CELLS}};
34
+ }
35
+
36
+ my @proxy = qw{
37
+ border_left border_right border_color value_color reset_color
38
+ border_left_width border_right_width
39
+ };
40
+
41
+ for my $meth (@proxy) {
42
+ no strict 'refs';
43
+ *$meth = sub {
44
+ my $self = shift;
45
+ $self->{+CELLS}->[$self->{+IDX}]->$meth;
46
+ };
47
+ }
48
+
49
+ for my $meth (qw{value_width width}) {
50
+ no strict 'refs';
51
+ *$meth = sub {
52
+ my $self = shift;
53
+ return max(map { $_->$meth } @{$self->{+CELLS}});
54
+ };
55
+ }
56
+
57
+ sub next {
58
+ my $self = shift;
59
+ my ($cw) = @_;
60
+
61
+ while ($self->{+IDX} < @{$self->{+CELLS}}) {
62
+ my $cell = $self->{+CELLS}->[$self->{+IDX}];
63
+
64
+ my $lw = $cell->border_left_width;
65
+ my $rw = $cell->border_right_width;
66
+ my $vw = $cw - $lw - $rw;
67
+ my $it = $cell->break->next($vw);
68
+
69
+ return ($it, $vw) if $it;
70
+ $self->{+IDX}++;
71
+ }
72
+
73
+ return;
74
+ }
75
+
76
+ sub break { $_[0] }
77
+
78
+ sub reset {
79
+ my $self = shift;
80
+ $self->{+IDX} = 0;
81
+ $_->reset for @{$self->{+CELLS}};
82
+ }
83
+
84
+ 1;
85
+
86
+ __END__
87
+
88
+ =pod
89
+
90
+ =encoding UTF-8
91
+
92
+ =head1 NAME
93
+
94
+ Term::Table::CellStack - Combine several cells into one (vertical)
95
+
96
+ =head1 DESCRIPTION
97
+
98
+ This package is used to represent a merged-cell in a table (vertical).
99
+
100
+ =head1 SOURCE
101
+
102
+ The source code repository for Term-Table can be found at
103
+ F<http://github.com/exodist/Term-Table/>.
104
+
105
+ =head1 MAINTAINERS
106
+
107
+ =over 4
108
+
109
+ =item Chad Granum E<lt>exodist@cpan.orgE<gt>
110
+
111
+ =back
112
+
113
+ =head1 AUTHORS
114
+
115
+ =over 4
116
+
117
+ =item Chad Granum E<lt>exodist@cpan.orgE<gt>
118
+
119
+ =back
120
+
121
+ =head1 COPYRIGHT
122
+
123
+ Copyright 2016 Chad Granum E<lt>exodist@cpan.orgE<gt>.
124
+
125
+ This program is free software; you can redistribute it and/or
126
+ modify it under the same terms as Perl itself.
127
+
128
+ See F<http://dev.perl.org/licenses/>
129
+
130
+ =cut
git/usr/share/perl5/core_perl/Term/Table/HashBase.pm ADDED
@@ -0,0 +1,473 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package Term::Table::HashBase;
2
+ use strict;
3
+ use warnings;
4
+
5
+ our $VERSION = '0.024';
6
+
7
+ #################################################################
8
+ # #
9
+ # This is a generated file! Do not modify this file directly! #
10
+ # Use hashbase_inc.pl script to regenerate this file. #
11
+ # The script is part of the Object::HashBase distribution. #
12
+ # Note: You can modify the version number above this comment #
13
+ # if needed, that is fine. #
14
+ # #
15
+ #################################################################
16
+
17
+ {
18
+ no warnings 'once';
19
+ $Term::Table::HashBase::HB_VERSION = '0.008';
20
+ *Term::Table::HashBase::ATTR_SUBS = \%Object::HashBase::ATTR_SUBS;
21
+ *Term::Table::HashBase::ATTR_LIST = \%Object::HashBase::ATTR_LIST;
22
+ *Term::Table::HashBase::VERSION = \%Object::HashBase::VERSION;
23
+ *Term::Table::HashBase::CAN_CACHE = \%Object::HashBase::CAN_CACHE;
24
+ }
25
+
26
+
27
+ require Carp;
28
+ {
29
+ no warnings 'once';
30
+ $Carp::Internal{+__PACKAGE__} = 1;
31
+ }
32
+
33
+ BEGIN {
34
+ # these are not strictly equivalent, but for out use we don't care
35
+ # about order
36
+ *_isa = ($] >= 5.010 && require mro) ? \&mro::get_linear_isa : sub {
37
+ no strict 'refs';
38
+ my @packages = ($_[0]);
39
+ my %seen;
40
+ for my $package (@packages) {
41
+ push @packages, grep !$seen{$_}++, @{"$package\::ISA"};
42
+ }
43
+ return \@packages;
44
+ }
45
+ }
46
+
47
+ my %SPEC = (
48
+ '^' => {reader => 1, writer => 0, dep_writer => 1, read_only => 0, strip => 1},
49
+ '-' => {reader => 1, writer => 0, dep_writer => 0, read_only => 1, strip => 1},
50
+ '>' => {reader => 0, writer => 1, dep_writer => 0, read_only => 0, strip => 1},
51
+ '<' => {reader => 1, writer => 0, dep_writer => 0, read_only => 0, strip => 1},
52
+ '+' => {reader => 0, writer => 0, dep_writer => 0, read_only => 0, strip => 1},
53
+ );
54
+
55
+ sub import {
56
+ my $class = shift;
57
+ my $into = caller;
58
+
59
+ # Make sure we list the OLDEST version used to create this class.
60
+ my $ver = $Term::Table::HashBase::HB_VERSION || $Term::Table::HashBase::VERSION;
61
+ $Term::Table::HashBase::VERSION{$into} = $ver if !$Term::Table::HashBase::VERSION{$into} || $Term::Table::HashBase::VERSION{$into} > $ver;
62
+
63
+ my $isa = _isa($into);
64
+ my $attr_list = $Term::Table::HashBase::ATTR_LIST{$into} ||= [];
65
+ my $attr_subs = $Term::Table::HashBase::ATTR_SUBS{$into} ||= {};
66
+
67
+ my %subs = (
68
+ ($into->can('new') ? () : (new => \&_new)),
69
+ (map %{$Term::Table::HashBase::ATTR_SUBS{$_} || {}}, @{$isa}[1 .. $#$isa]),
70
+ (
71
+ map {
72
+ my $p = substr($_, 0, 1);
73
+ my $x = $_;
74
+
75
+ my $spec = $SPEC{$p} || {reader => 1, writer => 1};
76
+
77
+ substr($x, 0, 1) = '' if $spec->{strip};
78
+ push @$attr_list => $x;
79
+ my ($sub, $attr) = (uc $x, $x);
80
+
81
+ $attr_subs->{$sub} = sub() { $attr };
82
+ my %out = ($sub => $attr_subs->{$sub});
83
+
84
+ $out{$attr} = sub { $_[0]->{$attr} } if $spec->{reader};
85
+ $out{"set_$attr"} = sub { $_[0]->{$attr} = $_[1] } if $spec->{writer};
86
+ $out{"set_$attr"} = sub { Carp::croak("'$attr' is read-only") } if $spec->{read_only};
87
+ $out{"set_$attr"} = sub { Carp::carp("set_$attr() is deprecated"); $_[0]->{$attr} = $_[1] } if $spec->{dep_writer};
88
+
89
+ %out;
90
+ } @_
91
+ ),
92
+ );
93
+
94
+ no strict 'refs';
95
+ *{"$into\::$_"} = $subs{$_} for keys %subs;
96
+ }
97
+
98
+ sub attr_list {
99
+ my $class = shift;
100
+
101
+ my $isa = _isa($class);
102
+
103
+ my %seen;
104
+ my @list = grep { !$seen{$_}++ } map {
105
+ my @out;
106
+
107
+ if (0.004 > ($Term::Table::HashBase::VERSION{$_} || 0)) {
108
+ Carp::carp("$_ uses an inlined version of Term::Table::HashBase too old to support attr_list()");
109
+ }
110
+ else {
111
+ my $list = $Term::Table::HashBase::ATTR_LIST{$_};
112
+ @out = $list ? @$list : ()
113
+ }
114
+
115
+ @out;
116
+ } reverse @$isa;
117
+
118
+ return @list;
119
+ }
120
+
121
+ sub _new {
122
+ my $class = shift;
123
+
124
+ my $self;
125
+
126
+ if (@_ == 1) {
127
+ my $arg = shift;
128
+ my $type = ref($arg);
129
+
130
+ if ($type eq 'HASH') {
131
+ $self = bless({%$arg}, $class)
132
+ }
133
+ else {
134
+ Carp::croak("Not sure what to do with '$type' in $class constructor")
135
+ unless $type eq 'ARRAY';
136
+
137
+ my %proto;
138
+ my @attributes = attr_list($class);
139
+ while (@$arg) {
140
+ my $val = shift @$arg;
141
+ my $key = shift @attributes or Carp::croak("Too many arguments for $class constructor");
142
+ $proto{$key} = $val;
143
+ }
144
+
145
+ $self = bless(\%proto, $class);
146
+ }
147
+ }
148
+ else {
149
+ $self = bless({@_}, $class);
150
+ }
151
+
152
+ $Term::Table::HashBase::CAN_CACHE{$class} = $self->can('init')
153
+ unless exists $Term::Table::HashBase::CAN_CACHE{$class};
154
+
155
+ $self->init if $Term::Table::HashBase::CAN_CACHE{$class};
156
+
157
+ $self;
158
+ }
159
+
160
+ 1;
161
+
162
+ __END__
163
+
164
+ =pod
165
+
166
+ =encoding UTF-8
167
+
168
+ =head1 NAME
169
+
170
+ Term::Table::HashBase - Build hash based classes.
171
+
172
+ =head1 SYNOPSIS
173
+
174
+ A class:
175
+
176
+ package My::Class;
177
+ use strict;
178
+ use warnings;
179
+
180
+ # Generate 3 accessors
181
+ use Term::Table::HashBase qw/foo -bar ^baz <bat >ban +boo/;
182
+
183
+ # Chance to initialize defaults
184
+ sub init {
185
+ my $self = shift; # No other args
186
+ $self->{+FOO} ||= "foo";
187
+ $self->{+BAR} ||= "bar";
188
+ $self->{+BAZ} ||= "baz";
189
+ $self->{+BAT} ||= "bat";
190
+ $self->{+BAN} ||= "ban";
191
+ $self->{+BOO} ||= "boo";
192
+ }
193
+
194
+ sub print {
195
+ print join ", " => map { $self->{$_} } FOO, BAR, BAZ, BAT, BAN, BOO;
196
+ }
197
+
198
+ Subclass it
199
+
200
+ package My::Subclass;
201
+ use strict;
202
+ use warnings;
203
+
204
+ # Note, you should subclass before loading HashBase.
205
+ use base 'My::Class';
206
+ use Term::Table::HashBase qw/bub/;
207
+
208
+ sub init {
209
+ my $self = shift;
210
+
211
+ # We get the constants from the base class for free.
212
+ $self->{+FOO} ||= 'SubFoo';
213
+ $self->{+BUB} ||= 'bub';
214
+
215
+ $self->SUPER::init();
216
+ }
217
+
218
+ use it:
219
+
220
+ package main;
221
+ use strict;
222
+ use warnings;
223
+ use My::Class;
224
+
225
+ # These are all functionally identical
226
+ my $one = My::Class->new(foo => 'MyFoo', bar => 'MyBar');
227
+ my $two = My::Class->new({foo => 'MyFoo', bar => 'MyBar'});
228
+ my $three = My::Class->new(['MyFoo', 'MyBar']);
229
+
230
+ # Readers!
231
+ my $foo = $one->foo; # 'MyFoo'
232
+ my $bar = $one->bar; # 'MyBar'
233
+ my $baz = $one->baz; # Defaulted to: 'baz'
234
+ my $bat = $one->bat; # Defaulted to: 'bat'
235
+ # '>ban' means setter only, no reader
236
+ # '+boo' means no setter or reader, just the BOO constant
237
+
238
+ # Setters!
239
+ $one->set_foo('A Foo');
240
+
241
+ #'-bar' means read-only, so the setter will throw an exception (but is defined).
242
+ $one->set_bar('A bar');
243
+
244
+ # '^baz' means deprecated setter, this will warn about the setter being
245
+ # deprecated.
246
+ $one->set_baz('A Baz');
247
+
248
+ # '<bat' means no setter defined at all
249
+ # '+boo' means no setter or reader, just the BOO constant
250
+
251
+ $one->{+FOO} = 'xxx';
252
+
253
+ =head1 DESCRIPTION
254
+
255
+ This package is used to generate classes based on hashrefs. Using this class
256
+ will give you a C<new()> method, as well as generating accessors you request.
257
+ Generated accessors will be getters, C<set_ACCESSOR> setters will also be
258
+ generated for you. You also get constants for each accessor (all caps) which
259
+ return the key into the hash for that accessor. Single inheritance is also
260
+ supported.
261
+
262
+ =head1 THIS IS A BUNDLED COPY OF HASHBASE
263
+
264
+ This is a bundled copy of L<Object::HashBase>. This file was generated using
265
+ the
266
+ C</home/exodist/perl5/perlbrew/perls/main/bin/hashbase_inc.pl>
267
+ script.
268
+
269
+ =head1 METHODS
270
+
271
+ =head2 PROVIDED BY HASH BASE
272
+
273
+ =over 4
274
+
275
+ =item $it = $class->new(%PAIRS)
276
+
277
+ =item $it = $class->new(\%PAIRS)
278
+
279
+ =item $it = $class->new(\@ORDERED_VALUES)
280
+
281
+ Create a new instance.
282
+
283
+ HashBase will not export C<new()> if there is already a C<new()> method in your
284
+ packages inheritance chain.
285
+
286
+ B<If you do not want this method you can define your own> you just have to
287
+ declare it before loading L<Term::Table::HashBase>.
288
+
289
+ package My::Package;
290
+
291
+ # predeclare new() so that HashBase does not give us one.
292
+ sub new;
293
+
294
+ use Term::Table::HashBase qw/foo bar baz/;
295
+
296
+ # Now we define our own new method.
297
+ sub new { ... }
298
+
299
+ This makes it so that HashBase sees that you have your own C<new()> method.
300
+ Alternatively you can define the method before loading HashBase instead of just
301
+ declaring it, but that scatters your use statements.
302
+
303
+ The most common way to create an object is to pass in key/value pairs where
304
+ each key is an attribute and each value is what you want assigned to that
305
+ attribute. No checking is done to verify the attributes or values are valid,
306
+ you may do that in C<init()> if desired.
307
+
308
+ If you would like, you can pass in a hashref instead of pairs. When you do so
309
+ the hashref will be copied, and the copy will be returned blessed as an object.
310
+ There is no way to ask HashBase to bless a specific hashref.
311
+
312
+ In some cases an object may only have 1 or 2 attributes, in which case a
313
+ hashref may be too verbose for your liking. In these cases you can pass in an
314
+ arrayref with only values. The values will be assigned to attributes in the
315
+ order the attributes were listed. When there is inheritance involved the
316
+ attributes from parent classes will come before subclasses.
317
+
318
+ =back
319
+
320
+ =head2 HOOKS
321
+
322
+ =over 4
323
+
324
+ =item $self->init()
325
+
326
+ This gives you the chance to set some default values to your fields. The only
327
+ argument is C<$self> with its indexes already set from the constructor.
328
+
329
+ B<Note:> Term::Table::HashBase checks for an init using C<< $class->can('init') >>
330
+ during construction. It DOES NOT call C<can()> on the created object. Also note
331
+ that the result of the check is cached, it is only ever checked once, the first
332
+ time an instance of your class is created. This means that adding an C<init()>
333
+ method AFTER the first construction will result in it being ignored.
334
+
335
+ =back
336
+
337
+ =head1 ACCESSORS
338
+
339
+ =head2 READ/WRITE
340
+
341
+ To generate accessors you list them when using the module:
342
+
343
+ use Term::Table::HashBase qw/foo/;
344
+
345
+ This will generate the following subs in your namespace:
346
+
347
+ =over 4
348
+
349
+ =item foo()
350
+
351
+ Getter, used to get the value of the C<foo> field.
352
+
353
+ =item set_foo()
354
+
355
+ Setter, used to set the value of the C<foo> field.
356
+
357
+ =item FOO()
358
+
359
+ Constant, returns the field C<foo>'s key into the class hashref. Subclasses will
360
+ also get this function as a constant, not simply a method, that means it is
361
+ copied into the subclass namespace.
362
+
363
+ The main reason for using these constants is to help avoid spelling mistakes
364
+ and similar typos. It will not help you if you forget to prefix the '+' though.
365
+
366
+ =back
367
+
368
+ =head2 READ ONLY
369
+
370
+ use Term::Table::HashBase qw/-foo/;
371
+
372
+ =over 4
373
+
374
+ =item set_foo()
375
+
376
+ Throws an exception telling you the attribute is read-only. This is exported to
377
+ override any active setters for the attribute in a parent class.
378
+
379
+ =back
380
+
381
+ =head2 DEPRECATED SETTER
382
+
383
+ use Term::Table::HashBase qw/^foo/;
384
+
385
+ =over 4
386
+
387
+ =item set_foo()
388
+
389
+ This will set the value, but it will also warn you that the method is
390
+ deprecated.
391
+
392
+ =back
393
+
394
+ =head2 NO SETTER
395
+
396
+ use Term::Table::HashBase qw/<foo/;
397
+
398
+ Only gives you a reader, no C<set_foo> method is defined at all.
399
+
400
+ =head2 NO READER
401
+
402
+ use Term::Table::HashBase qw/>foo/;
403
+
404
+ Only gives you a write (C<set_foo>), no C<foo> method is defined at all.
405
+
406
+ =head2 CONSTANT ONLY
407
+
408
+ use Term::Table::HashBase qw/+foo/;
409
+
410
+ This does not create any methods for you, it just adds the C<FOO> constant.
411
+
412
+ =head1 SUBCLASSING
413
+
414
+ You can subclass an existing HashBase class.
415
+
416
+ use base 'Another::HashBase::Class';
417
+ use Term::Table::HashBase qw/foo bar baz/;
418
+
419
+ The base class is added to C<@ISA> for you, and all constants from base classes
420
+ are added to subclasses automatically.
421
+
422
+ =head1 GETTING A LIST OF ATTRIBUTES FOR A CLASS
423
+
424
+ Term::Table::HashBase provides a function for retrieving a list of attributes for an
425
+ Term::Table::HashBase class.
426
+
427
+ =over 4
428
+
429
+ =item @list = Term::Table::HashBase::attr_list($class)
430
+
431
+ =item @list = $class->Term::Table::HashBase::attr_list()
432
+
433
+ Either form above will work. This will return a list of attributes defined on
434
+ the object. This list is returned in the attribute definition order, parent
435
+ class attributes are listed before subclass attributes. Duplicate attributes
436
+ will be removed before the list is returned.
437
+
438
+ B<Note:> This list is used in the C<< $class->new(\@ARRAY) >> constructor to
439
+ determine the attribute to which each value will be paired.
440
+
441
+ =back
442
+
443
+ =head1 SOURCE
444
+
445
+ The source code repository for HashBase can be found at
446
+ F<http://github.com/Test-More/HashBase/>.
447
+
448
+ =head1 MAINTAINERS
449
+
450
+ =over 4
451
+
452
+ =item Chad Granum E<lt>exodist@cpan.orgE<gt>
453
+
454
+ =back
455
+
456
+ =head1 AUTHORS
457
+
458
+ =over 4
459
+
460
+ =item Chad Granum E<lt>exodist@cpan.orgE<gt>
461
+
462
+ =back
463
+
464
+ =head1 COPYRIGHT
465
+
466
+ Copyright 2017 Chad Granum E<lt>exodist@cpan.orgE<gt>.
467
+
468
+ This program is free software; you can redistribute it and/or
469
+ modify it under the same terms as Perl itself.
470
+
471
+ See F<http://dev.perl.org/licenses/>
472
+
473
+ =cut
git/usr/share/perl5/core_perl/Term/Table/LineBreak.pm ADDED
@@ -0,0 +1,144 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package Term::Table::LineBreak;
2
+ use strict;
3
+ use warnings;
4
+
5
+ our $VERSION = '0.024';
6
+
7
+ use Carp qw/croak/;
8
+ use Scalar::Util qw/blessed/;
9
+ use Term::Table::Util qw/uni_length/;
10
+
11
+ use Term::Table::HashBase qw/string gcstring _len _parts idx/;
12
+
13
+ sub init {
14
+ my $self = shift;
15
+
16
+ croak "string is a required attribute"
17
+ unless defined $self->{+STRING};
18
+ }
19
+
20
+ sub columns { uni_length($_[0]->{+STRING}) }
21
+
22
+ sub break {
23
+ my $self = shift;
24
+ my ($len) = @_;
25
+
26
+ $self->{+_LEN} = $len;
27
+
28
+ $self->{+IDX} = 0;
29
+ my $str = $self->{+STRING} . ""; # Force stringification
30
+
31
+ my @parts;
32
+ my @chars = split //, $str;
33
+ while (@chars) {
34
+ my $size = 0;
35
+ my $part = '';
36
+ until ($size == $len) {
37
+ my $char = shift @chars;
38
+ $char = '' unless defined $char;
39
+
40
+ my $l = uni_length("$char");
41
+ last unless $l;
42
+
43
+ last if $char eq "\n";
44
+
45
+ if ($size + $l > $len) {
46
+ unshift @chars => $char;
47
+ last;
48
+ }
49
+
50
+ $size += $l;
51
+ $part .= $char;
52
+ }
53
+
54
+ # If we stopped just before a newline, grab it
55
+ shift @chars if $size == $len && @chars && $chars[0] eq "\n";
56
+
57
+ until ($size == $len) {
58
+ $part .= ' ';
59
+ $size += 1;
60
+ }
61
+ push @parts => $part;
62
+ }
63
+
64
+ $self->{+_PARTS} = \@parts;
65
+ }
66
+
67
+ sub next {
68
+ my $self = shift;
69
+
70
+ if (@_) {
71
+ my ($len) = @_;
72
+ $self->break($len) if !$self->{+_LEN} || $self->{+_LEN} != $len;
73
+ }
74
+ else {
75
+ croak "String has not yet been broken"
76
+ unless $self->{+_PARTS};
77
+ }
78
+
79
+ my $idx = $self->{+IDX}++;
80
+ my $parts = $self->{+_PARTS};
81
+
82
+ return undef if $idx >= @$parts;
83
+ return $parts->[$idx];
84
+ }
85
+
86
+ 1;
87
+
88
+ __END__
89
+
90
+ =pod
91
+
92
+ =encoding UTF-8
93
+
94
+ =head1 NAME
95
+
96
+ Term::Table::LineBreak - Break up lines for use in tables.
97
+
98
+ =head1 DESCRIPTION
99
+
100
+ This is meant for internal use. This package takes long lines of text and
101
+ splits them so that they fit in table rows.
102
+
103
+ =head1 SYNOPSIS
104
+
105
+ use Term::Table::LineBreak;
106
+
107
+ my $lb = Term::Table::LineBreak->new(string => $STRING);
108
+
109
+ $lb->break($SIZE);
110
+ while (my $part = $lb->next) {
111
+ ...
112
+ }
113
+
114
+ =head1 SOURCE
115
+
116
+ The source code repository for Term-Table can be found at
117
+ F<http://github.com/exodist/Term-Table/>.
118
+
119
+ =head1 MAINTAINERS
120
+
121
+ =over 4
122
+
123
+ =item Chad Granum E<lt>exodist@cpan.orgE<gt>
124
+
125
+ =back
126
+
127
+ =head1 AUTHORS
128
+
129
+ =over 4
130
+
131
+ =item Chad Granum E<lt>exodist@cpan.orgE<gt>
132
+
133
+ =back
134
+
135
+ =head1 COPYRIGHT
136
+
137
+ Copyright 2016 Chad Granum E<lt>exodist@cpan.orgE<gt>.
138
+
139
+ This program is free software; you can redistribute it and/or
140
+ modify it under the same terms as Perl itself.
141
+
142
+ See F<http://dev.perl.org/licenses/>
143
+
144
+ =cut
git/usr/share/perl5/core_perl/Term/Table/Spacer.pm ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package Term::Table::Spacer;
2
+ use strict;
3
+ use warnings;
4
+
5
+ our $VERSION = '0.024';
6
+
7
+ sub new { bless {}, $_[0] }
8
+
9
+ sub width { 1 }
10
+
11
+ sub sanitize { }
12
+ sub mark_tail { }
13
+ sub reset { }
14
+
15
+ 1;
git/usr/share/perl5/core_perl/Term/Table/Util.pm ADDED
@@ -0,0 +1,200 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package Term::Table::Util;
2
+ use strict;
3
+ use warnings;
4
+
5
+ use Config qw/%Config/;
6
+
7
+ our $VERSION = '0.024';
8
+
9
+ use base 'Exporter';
10
+ our @EXPORT_OK = qw/term_size USE_GCS USE_TERM_READKEY USE_TERM_SIZE_ANY uni_length/;
11
+
12
+ sub DEFAULT_SIZE() { 80 }
13
+
14
+ my $IO;
15
+ BEGIN {
16
+ open($IO, '>&', *STDOUT) or die "Could not clone STDOUT";
17
+ }
18
+
19
+ sub try(&) {
20
+ my $code = shift;
21
+ local ($@, $?, $!);
22
+ my $ok = eval { $code->(); 1 };
23
+ my $err = $@;
24
+ return ($ok, $err);
25
+ }
26
+
27
+ my ($tsa) = try { require Term::Size::Any; Term::Size::Any->import('chars') };
28
+ my ($trk) = try { require Term::ReadKey };
29
+ $trk &&= Term::ReadKey->can('GetTerminalSize');
30
+
31
+ if (!-t $IO) {
32
+ *USE_TERM_READKEY = sub() { 0 };
33
+ *USE_TERM_SIZE_ANY = sub() { 0 };
34
+ *term_size = sub {
35
+ return $ENV{TABLE_TERM_SIZE} if $ENV{TABLE_TERM_SIZE};
36
+ return DEFAULT_SIZE;
37
+ };
38
+ }
39
+ elsif ($tsa) {
40
+ *USE_TERM_READKEY = sub() { 0 };
41
+ *USE_TERM_SIZE_ANY = sub() { 1 };
42
+ *_term_size = sub {
43
+ my $size = chars($IO);
44
+ return DEFAULT_SIZE if !$size;
45
+ return DEFAULT_SIZE if $size < DEFAULT_SIZE;
46
+ return $size;
47
+ };
48
+ }
49
+ elsif ($trk) {
50
+ *USE_TERM_READKEY = sub() { 1 };
51
+ *USE_TERM_SIZE_ANY = sub() { 0 };
52
+ *_term_size = sub {
53
+ my $total;
54
+ try {
55
+ my @warnings;
56
+ {
57
+ local $SIG{__WARN__} = sub { push @warnings => @_ };
58
+ ($total) = Term::ReadKey::GetTerminalSize($IO);
59
+ }
60
+ @warnings = grep { $_ !~ m/Unable to get Terminal Size/ } @warnings;
61
+ warn @warnings if @warnings;
62
+ };
63
+ return DEFAULT_SIZE if !$total;
64
+ return DEFAULT_SIZE if $total < DEFAULT_SIZE;
65
+ return $total;
66
+ };
67
+ }
68
+ else {
69
+ *USE_TERM_READKEY = sub() { 0 };
70
+ *USE_TERM_SIZE_ANY = sub() { 0 };
71
+ *term_size = sub {
72
+ return $ENV{TABLE_TERM_SIZE} if $ENV{TABLE_TERM_SIZE};
73
+ return DEFAULT_SIZE;
74
+ };
75
+ }
76
+
77
+ if (USE_TERM_READKEY() || USE_TERM_SIZE_ANY()) {
78
+ if (index($Config{sig_name}, 'WINCH') >= 0) {
79
+ my $changed = 0;
80
+ my $polled = -1;
81
+ $SIG{WINCH} = sub { $changed++ };
82
+
83
+ my $size;
84
+ *term_size = sub {
85
+ return $ENV{TABLE_TERM_SIZE} if $ENV{TABLE_TERM_SIZE};
86
+
87
+ unless ($changed == $polled) {
88
+ $polled = $changed;
89
+ $size = _term_size();
90
+ }
91
+
92
+ return $size;
93
+ }
94
+ }
95
+ else {
96
+ *term_size = sub {
97
+ return $ENV{TABLE_TERM_SIZE} if $ENV{TABLE_TERM_SIZE};
98
+ _term_size();
99
+ };
100
+ }
101
+ }
102
+
103
+ my ($gcs, $err) = try { require Unicode::GCString };
104
+
105
+ if ($gcs) {
106
+ *USE_GCS = sub() { 1 };
107
+ *uni_length = sub { Unicode::GCString->new($_[0])->columns };
108
+ }
109
+ else {
110
+ *USE_GCS = sub() { 0 };
111
+ *uni_length = sub { length($_[0]) };
112
+ }
113
+
114
+ 1;
115
+
116
+ __END__
117
+
118
+ =pod
119
+
120
+ =encoding UTF-8
121
+
122
+ =head1 NAME
123
+
124
+ Term::Table::Util - Utilities for Term::Table.
125
+
126
+ =head1 DESCRIPTION
127
+
128
+ This package exports some tools used by Term::Table.
129
+
130
+ =head1 EXPORTS
131
+
132
+ =head2 CONSTANTS
133
+
134
+ =over 4
135
+
136
+ =item $bool = USE_GCS
137
+
138
+ True if L<Unicode::GCString> is installed.
139
+
140
+ =item $bool = USE_TERM_READKEY
141
+
142
+ True if L<Term::ReadKey> is installed.
143
+
144
+ =back
145
+
146
+ =head2 UTILITIES
147
+
148
+ =over 4
149
+
150
+ =item $width = term_size()
151
+
152
+ Get the width of the terminal.
153
+
154
+ If the C<$TABLE_TERM_SIZE> environment variable is set then that value will be
155
+ returned.
156
+
157
+ This will default to 80 if there is no good way to get the size, or if the size
158
+ is unreasonably small.
159
+
160
+ If L<Term::ReadKey> is installed it will be used.
161
+
162
+ =item $width = uni_length($string)
163
+
164
+ Get the width (in columns) of the specified string. When L<Unicode::GCString>
165
+ is installed this will work on unicode strings, otherwise it will just use
166
+ C<length($string)>.
167
+
168
+ =back
169
+
170
+ =head1 SOURCE
171
+
172
+ The source code repository for Term-Table can be found at
173
+ F<http://github.com/exodist/Term-Table/>.
174
+
175
+ =head1 MAINTAINERS
176
+
177
+ =over 4
178
+
179
+ =item Chad Granum E<lt>exodist@cpan.orgE<gt>
180
+
181
+ =back
182
+
183
+ =head1 AUTHORS
184
+
185
+ =over 4
186
+
187
+ =item Chad Granum E<lt>exodist@cpan.orgE<gt>
188
+
189
+ =back
190
+
191
+ =head1 COPYRIGHT
192
+
193
+ Copyright 2016 Chad Granum E<lt>exodist@cpan.orgE<gt>.
194
+
195
+ This program is free software; you can redistribute it and/or
196
+ modify it under the same terms as Perl itself.
197
+
198
+ See F<http://dev.perl.org/licenses/>
199
+
200
+ =cut
git/usr/share/perl5/core_perl/Test/Builder/Formatter.pm ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package Test::Builder::Formatter;
2
+ use strict;
3
+ use warnings;
4
+
5
+ our $VERSION = '1.302210';
6
+
7
+ BEGIN { require Test2::Formatter::TAP; our @ISA = qw(Test2::Formatter::TAP) }
8
+
9
+ use Test2::Util::HashBase qw/no_header no_diag/;
10
+
11
+ BEGIN {
12
+ *OUT_STD = Test2::Formatter::TAP->can('OUT_STD');
13
+ *OUT_ERR = Test2::Formatter::TAP->can('OUT_ERR');
14
+
15
+ my $todo = OUT_ERR() + 1;
16
+ *OUT_TODO = sub() { $todo };
17
+ }
18
+
19
+ sub init {
20
+ my $self = shift;
21
+ $self->SUPER::init(@_);
22
+ $self->{+HANDLES}->[OUT_TODO] = $self->{+HANDLES}->[OUT_STD];
23
+ }
24
+
25
+ sub plan_tap {
26
+ my ($self, $f) = @_;
27
+
28
+ return if $self->{+NO_HEADER};
29
+ return $self->SUPER::plan_tap($f);
30
+ }
31
+
32
+ sub debug_tap {
33
+ my ($self, $f, $num) = @_;
34
+ return if $self->{+NO_DIAG};
35
+ my @out = $self->SUPER::debug_tap($f, $num);
36
+ $self->redirect(\@out) if @out && ref $f->{about} && defined $f->{about}->{package}
37
+ && $f->{about}->{package} eq 'Test::Builder::TodoDiag';
38
+ return @out;
39
+ }
40
+
41
+ sub info_tap {
42
+ my ($self, $f) = @_;
43
+ return if $self->{+NO_DIAG};
44
+ my @out = $self->SUPER::info_tap($f);
45
+ $self->redirect(\@out) if @out && ref $f->{about} && defined $f->{about}->{package}
46
+ && $f->{about}->{package} eq 'Test::Builder::TodoDiag';
47
+ return @out;
48
+ }
49
+
50
+ sub redirect {
51
+ my ($self, $out) = @_;
52
+ $_->[0] = OUT_TODO for @$out;
53
+ }
54
+
55
+ sub no_subtest_space { 1 }
56
+
57
+ 1;
58
+
59
+ __END__
60
+
61
+ =pod
62
+
63
+ =encoding UTF-8
64
+
65
+ =head1 NAME
66
+
67
+ Test::Builder::Formatter - Test::Builder subclass of Test2::Formatter::TAP
68
+
69
+ =head1 DESCRIPTION
70
+
71
+ This is what takes events and turns them into TAP.
72
+
73
+ =head1 SYNOPSIS
74
+
75
+ use Test::Builder; # Loads Test::Builder::Formatter for you
76
+
77
+ =head1 SOURCE
78
+
79
+ The source code repository for Test2 can be found at
80
+ L<https://github.com/Test-More/test-more/>.
81
+
82
+ =head1 MAINTAINERS
83
+
84
+ =over 4
85
+
86
+ =item Chad Granum E<lt>exodist@cpan.orgE<gt>
87
+
88
+ =back
89
+
90
+ =head1 AUTHORS
91
+
92
+ =over 4
93
+
94
+ =item Chad Granum E<lt>exodist@cpan.orgE<gt>
95
+
96
+ =back
97
+
98
+ =head1 COPYRIGHT
99
+
100
+ Copyright Chad Granum E<lt>exodist@cpan.orgE<gt>.
101
+
102
+ This program is free software; you can redistribute it and/or
103
+ modify it under the same terms as Perl itself.
104
+
105
+ See L<https://dev.perl.org/licenses/>
106
+
107
+ =cut
git/usr/share/perl5/core_perl/Test/Builder/Module.pm ADDED
@@ -0,0 +1,182 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package Test::Builder::Module;
2
+
3
+ use strict;
4
+
5
+ use Test::Builder;
6
+
7
+ require Exporter;
8
+ our @ISA = qw(Exporter);
9
+
10
+ our $VERSION = '1.302210';
11
+
12
+
13
+ =head1 NAME
14
+
15
+ Test::Builder::Module - Base class for test modules
16
+
17
+ =head1 SYNOPSIS
18
+
19
+ # Emulates Test::Simple
20
+ package Your::Module;
21
+
22
+ my $CLASS = __PACKAGE__;
23
+
24
+ use parent 'Test::Builder::Module';
25
+ @EXPORT = qw(ok);
26
+
27
+ sub ok ($;$) {
28
+ my $tb = $CLASS->builder;
29
+ return $tb->ok(@_);
30
+ }
31
+
32
+ 1;
33
+
34
+
35
+ =head1 DESCRIPTION
36
+
37
+ This is a superclass for L<Test::Builder>-based modules. It provides a
38
+ handful of common functionality and a method of getting at the underlying
39
+ L<Test::Builder> object.
40
+
41
+
42
+ =head2 Importing
43
+
44
+ Test::Builder::Module is a subclass of L<Exporter> which means your
45
+ module is also a subclass of Exporter. @EXPORT, @EXPORT_OK, etc...
46
+ all act normally.
47
+
48
+ A few methods are provided to do the C<< use Your::Module tests => 23 >> part
49
+ for you.
50
+
51
+ =head3 import
52
+
53
+ Test::Builder::Module provides an C<import()> method which acts in the
54
+ same basic way as L<Test::More>'s, setting the plan and controlling
55
+ exporting of functions and variables. This allows your module to set
56
+ the plan independent of L<Test::More>.
57
+
58
+ All arguments passed to C<import()> are passed onto
59
+ C<< Your::Module->builder->plan() >> with the exception of
60
+ C<< import =>[qw(things to import)] >>.
61
+
62
+ use Your::Module import => [qw(this that)], tests => 23;
63
+
64
+ says to import the functions C<this()> and C<that()> as well as set the plan
65
+ to be 23 tests.
66
+
67
+ C<import()> also sets the C<exported_to()> attribute of your builder to be
68
+ the caller of the C<import()> function.
69
+
70
+ Additional behaviors can be added to your C<import()> method by overriding
71
+ C<import_extra()>.
72
+
73
+ =cut
74
+
75
+ sub import {
76
+ my($class) = shift;
77
+
78
+ Test2::API::test2_load() unless Test2::API::test2_in_preload();
79
+
80
+ # Don't run all this when loading ourself.
81
+ return 1 if $class eq 'Test::Builder::Module';
82
+
83
+ my $test = $class->builder;
84
+
85
+ my $caller = caller;
86
+
87
+ $test->exported_to($caller);
88
+
89
+ $class->import_extra( \@_ );
90
+ my(@imports) = $class->_strip_imports( \@_ );
91
+
92
+ $test->plan(@_);
93
+
94
+ local $Exporter::ExportLevel = $Exporter::ExportLevel + 1;
95
+ $class->Exporter::import(@imports);
96
+ }
97
+
98
+ sub _strip_imports {
99
+ my $class = shift;
100
+ my $list = shift;
101
+
102
+ my @imports = ();
103
+ my @other = ();
104
+ my $idx = 0;
105
+ while( $idx <= $#{$list} ) {
106
+ my $item = $list->[$idx];
107
+
108
+ if( defined $item and $item eq 'import' ) {
109
+ push @imports, @{ $list->[ $idx + 1 ] };
110
+ $idx++;
111
+ }
112
+ else {
113
+ push @other, $item;
114
+ }
115
+
116
+ $idx++;
117
+ }
118
+
119
+ @$list = @other;
120
+
121
+ return @imports;
122
+ }
123
+
124
+ =head3 import_extra
125
+
126
+ Your::Module->import_extra(\@import_args);
127
+
128
+ C<import_extra()> is called by C<import()>. It provides an opportunity for you
129
+ to add behaviors to your module based on its import list.
130
+
131
+ Any extra arguments which shouldn't be passed on to C<plan()> should be
132
+ stripped off by this method.
133
+
134
+ See L<Test::More> for an example of its use.
135
+
136
+ B<NOTE> This mechanism is I<VERY ALPHA AND LIKELY TO CHANGE> as it
137
+ feels like a bit of an ugly hack in its current form.
138
+
139
+ =cut
140
+
141
+ sub import_extra { }
142
+
143
+ =head2 Builder
144
+
145
+ Test::Builder::Module provides some methods of getting at the underlying
146
+ Test::Builder object.
147
+
148
+ =head3 builder
149
+
150
+ my $builder = Your::Class->builder;
151
+
152
+ This method returns the L<Test::Builder> object associated with Your::Class.
153
+ It is not a constructor so you can call it as often as you like.
154
+
155
+ This is the preferred way to get the L<Test::Builder> object. You should
156
+ I<not> get it via C<< Test::Builder->new >> as was previously
157
+ recommended.
158
+
159
+ The object returned by C<builder()> may change at runtime so you should
160
+ call C<builder()> inside each function rather than store it in a global.
161
+
162
+ sub ok {
163
+ my $builder = Your::Class->builder;
164
+
165
+ return $builder->ok(@_);
166
+ }
167
+
168
+
169
+ =cut
170
+
171
+ sub builder {
172
+ return Test::Builder->new;
173
+ }
174
+
175
+ =head1 SEE ALSO
176
+
177
+ L<< Test2::Manual::Tooling::TestBuilder >> describes the improved
178
+ options for writing testing modules provided by L<< Test2 >>.
179
+
180
+ =cut
181
+
182
+ 1;
git/usr/share/perl5/core_perl/Test/Builder/Tester.pm ADDED
@@ -0,0 +1,675 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package Test::Builder::Tester;
2
+
3
+ use strict;
4
+ our $VERSION = '1.302210';
5
+
6
+ use Test::Builder;
7
+ use Symbol;
8
+ use Carp;
9
+
10
+ =head1 NAME
11
+
12
+ Test::Builder::Tester - test testsuites that have been built with
13
+ Test::Builder
14
+
15
+ =head1 SYNOPSIS
16
+
17
+ use Test::Builder::Tester tests => 1;
18
+ use Test::More;
19
+
20
+ test_out("not ok 1 - foo");
21
+ test_fail(+1);
22
+ fail("foo");
23
+ test_test("fail works");
24
+
25
+ =head1 DESCRIPTION
26
+
27
+ A module that helps you test testing modules that are built with
28
+ L<Test::Builder>.
29
+
30
+ The testing system is designed to be used by performing a three step
31
+ process for each test you wish to test. This process starts with using
32
+ C<test_out> and C<test_err> in advance to declare what the testsuite you
33
+ are testing will output with L<Test::Builder> to stdout and stderr.
34
+
35
+ You then can run the test(s) from your test suite that call
36
+ L<Test::Builder>. At this point the output of L<Test::Builder> is
37
+ safely captured by L<Test::Builder::Tester> rather than being
38
+ interpreted as real test output.
39
+
40
+ The final stage is to call C<test_test> that will simply compare what you
41
+ predeclared to what L<Test::Builder> actually outputted, and report the
42
+ results back with a "ok" or "not ok" (with debugging) to the normal
43
+ output.
44
+
45
+ =cut
46
+
47
+ ####
48
+ # set up testing
49
+ ####
50
+
51
+ my $t = Test::Builder->new;
52
+
53
+ ###
54
+ # make us an exporter
55
+ ###
56
+
57
+ use Exporter;
58
+ our @ISA = qw(Exporter);
59
+
60
+ our @EXPORT = qw(test_out test_err test_fail test_diag test_test line_num);
61
+
62
+ sub import {
63
+ my $class = shift;
64
+ my(@plan) = @_;
65
+
66
+ my $caller = caller;
67
+
68
+ $t->exported_to($caller);
69
+ $t->plan(@plan);
70
+
71
+ my @imports = ();
72
+ foreach my $idx ( 0 .. $#plan ) {
73
+ if( $plan[$idx] eq 'import' ) {
74
+ @imports = @{ $plan[ $idx + 1 ] };
75
+ last;
76
+ }
77
+ }
78
+
79
+ __PACKAGE__->export_to_level( 1, __PACKAGE__, @imports );
80
+ }
81
+
82
+ ###
83
+ # set up file handles
84
+ ###
85
+
86
+ # create some private file handles
87
+ my $output_handle = gensym;
88
+ my $error_handle = gensym;
89
+
90
+ # and tie them to this package
91
+ my $out = tie *$output_handle, "Test::Builder::Tester::Tie", "STDOUT";
92
+ my $err = tie *$error_handle, "Test::Builder::Tester::Tie", "STDERR";
93
+
94
+ ####
95
+ # exported functions
96
+ ####
97
+
98
+ # for remembering that we're testing and where we're testing at
99
+ my $testing = 0;
100
+ my $testing_num;
101
+ my $original_is_passing;
102
+
103
+ # remembering where the file handles were originally connected
104
+ my $original_output_handle;
105
+ my $original_failure_handle;
106
+ my $original_todo_handle;
107
+ my $original_formatter;
108
+
109
+ my $original_harness_env;
110
+
111
+ # function that starts testing and redirects the filehandles for now
112
+ sub _start_testing {
113
+ # Hack for things that conditioned on Test-Stream being loaded
114
+ $INC{'Test/Stream.pm'} ||= 'fake' if $INC{'Test/Moose/More.pm'};
115
+ # even if we're running under Test::Harness pretend we're not
116
+ # for now. This needed so Test::Builder doesn't add extra spaces
117
+ $original_harness_env = $ENV{HARNESS_ACTIVE} || 0;
118
+ $ENV{HARNESS_ACTIVE} = 0;
119
+
120
+ my $hub = $t->{Hub} || ($t->{Stack} ? $t->{Stack}->top : Test2::API::test2_stack->top);
121
+ $original_formatter = $hub->format;
122
+ unless ($original_formatter && $original_formatter->isa('Test::Builder::Formatter')) {
123
+ my $fmt = Test::Builder::Formatter->new;
124
+ $hub->format($fmt);
125
+ }
126
+
127
+ # remember what the handles were set to
128
+ $original_output_handle = $t->output();
129
+ $original_failure_handle = $t->failure_output();
130
+ $original_todo_handle = $t->todo_output();
131
+
132
+ # switch out to our own handles
133
+ $t->output($output_handle);
134
+ $t->failure_output($error_handle);
135
+ $t->todo_output($output_handle);
136
+
137
+ # clear the expected list
138
+ $out->reset();
139
+ $err->reset();
140
+
141
+ # remember that we're testing
142
+ $testing = 1;
143
+ $testing_num = $t->current_test;
144
+ $t->current_test(0);
145
+ $original_is_passing = $t->is_passing;
146
+ $t->is_passing(1);
147
+
148
+ # look, we shouldn't do the ending stuff
149
+ $t->no_ending(1);
150
+ }
151
+
152
+ =head2 Functions
153
+
154
+ These are the six methods that are exported as default.
155
+
156
+ =over 4
157
+
158
+ =item test_out
159
+
160
+ =item test_err
161
+
162
+ Procedures for predeclaring the output that your test suite is
163
+ expected to produce until C<test_test> is called. These procedures
164
+ automatically assume that each line terminates with "\n". So
165
+
166
+ test_out("ok 1","ok 2");
167
+
168
+ is the same as
169
+
170
+ test_out("ok 1\nok 2");
171
+
172
+ which is even the same as
173
+
174
+ test_out("ok 1");
175
+ test_out("ok 2");
176
+
177
+ Once C<test_out> or C<test_err> (or C<test_fail> or C<test_diag>) have
178
+ been called, all further output from L<Test::Builder> will be
179
+ captured by L<Test::Builder::Tester>. This means that you will not
180
+ be able perform further tests to the normal output in the normal way
181
+ until you call C<test_test> (well, unless you manually meddle with the
182
+ output filehandles)
183
+
184
+ =cut
185
+
186
+ sub test_out {
187
+ # do we need to do any setup?
188
+ _start_testing() unless $testing;
189
+
190
+ $out->expect(@_);
191
+ }
192
+
193
+ sub test_err {
194
+ # do we need to do any setup?
195
+ _start_testing() unless $testing;
196
+
197
+ $err->expect(@_);
198
+ }
199
+
200
+ =item test_fail
201
+
202
+ Because the standard failure message that L<Test::Builder> produces
203
+ whenever a test fails will be a common occurrence in your test error
204
+ output, and because it has changed between Test::Builder versions, rather
205
+ than forcing you to call C<test_err> with the string all the time like
206
+ so
207
+
208
+ test_err("# Failed test ($0 at line ".line_num(+1).")");
209
+
210
+ C<test_fail> exists as a convenience function that can be called
211
+ instead. It takes one argument, the offset from the current line that
212
+ the line that causes the fail is on.
213
+
214
+ test_fail(+1);
215
+
216
+ This means that the example in the synopsis could be rewritten
217
+ more simply as:
218
+
219
+ test_out("not ok 1 - foo");
220
+ test_fail(+1);
221
+ fail("foo");
222
+ test_test("fail works");
223
+
224
+ =cut
225
+
226
+ sub test_fail {
227
+ # do we need to do any setup?
228
+ _start_testing() unless $testing;
229
+
230
+ # work out what line we should be on
231
+ my( $package, $filename, $line ) = caller;
232
+ $line = $line + ( shift() || 0 ); # prevent warnings
233
+
234
+ # expect that on stderr
235
+ $err->expect("# Failed test ($filename at line $line)");
236
+ }
237
+
238
+ =item test_diag
239
+
240
+ As most of the remaining expected output to the error stream will be
241
+ created by L<Test::Builder>'s C<diag> function, L<Test::Builder::Tester>
242
+ provides a convenience function C<test_diag> that you can use instead of
243
+ C<test_err>.
244
+
245
+ The C<test_diag> function prepends comment hashes and spacing to the
246
+ start and newlines to the end of the expected output passed to it and
247
+ adds it to the list of expected error output. So, instead of writing
248
+
249
+ test_err("# Couldn't open file");
250
+
251
+ you can write
252
+
253
+ test_diag("Couldn't open file");
254
+
255
+ Remember that L<Test::Builder>'s diag function will not add newlines to
256
+ the end of output and test_diag will. So to check
257
+
258
+ Test::Builder->new->diag("foo\n","bar\n");
259
+
260
+ You would do
261
+
262
+ test_diag("foo","bar")
263
+
264
+ without the newlines.
265
+
266
+ =cut
267
+
268
+ sub test_diag {
269
+ # do we need to do any setup?
270
+ _start_testing() unless $testing;
271
+
272
+ # expect the same thing, but prepended with "# "
273
+ local $_;
274
+ $err->expect( map { "# $_" } @_ );
275
+ }
276
+
277
+ =item test_test
278
+
279
+ Actually performs the output check testing the tests, comparing the
280
+ data (with C<eq>) that we have captured from L<Test::Builder> against
281
+ what was declared with C<test_out> and C<test_err>.
282
+
283
+ This takes name/value pairs that affect how the test is run.
284
+
285
+ =over
286
+
287
+ =item title (synonym 'name', 'label')
288
+
289
+ The name of the test that will be displayed after the C<ok> or C<not
290
+ ok>.
291
+
292
+ =item skip_out
293
+
294
+ Setting this to a true value will cause the test to ignore if the
295
+ output sent by the test to the output stream does not match that
296
+ declared with C<test_out>.
297
+
298
+ =item skip_err
299
+
300
+ Setting this to a true value will cause the test to ignore if the
301
+ output sent by the test to the error stream does not match that
302
+ declared with C<test_err>.
303
+
304
+ =back
305
+
306
+ As a convenience, if only one argument is passed then this argument
307
+ is assumed to be the name of the test (as in the above examples.)
308
+
309
+ Once C<test_test> has been run test output will be redirected back to
310
+ the original filehandles that L<Test::Builder> was connected to
311
+ (probably STDOUT and STDERR,) meaning any further tests you run
312
+ will function normally and cause success/errors for L<Test::Harness>.
313
+
314
+ =cut
315
+
316
+ sub test_test {
317
+ # END the hack
318
+ delete $INC{'Test/Stream.pm'} if $INC{'Test/Stream.pm'} && $INC{'Test/Stream.pm'} eq 'fake';
319
+ # decode the arguments as described in the pod
320
+ my $mess;
321
+ my %args;
322
+ if( @_ == 1 ) {
323
+ $mess = shift
324
+ }
325
+ else {
326
+ %args = @_;
327
+ $mess = $args{name} if exists( $args{name} );
328
+ $mess = $args{title} if exists( $args{title} );
329
+ $mess = $args{label} if exists( $args{label} );
330
+ }
331
+
332
+ # er, are we testing?
333
+ croak "Not testing. You must declare output with a test function first."
334
+ unless $testing;
335
+
336
+
337
+ my $hub = $t->{Hub} || Test2::API::test2_stack->top;
338
+ $hub->format($original_formatter);
339
+
340
+ # okay, reconnect the test suite back to the saved handles
341
+ $t->output($original_output_handle);
342
+ $t->failure_output($original_failure_handle);
343
+ $t->todo_output($original_todo_handle);
344
+
345
+ # restore the test no, etc, back to the original point
346
+ $t->current_test($testing_num);
347
+ $testing = 0;
348
+ $t->is_passing($original_is_passing);
349
+
350
+ # re-enable the original setting of the harness
351
+ $ENV{HARNESS_ACTIVE} = $original_harness_env;
352
+
353
+ # check the output we've stashed
354
+ unless( $t->ok( ( $args{skip_out} || $out->check ) &&
355
+ ( $args{skip_err} || $err->check ), $mess )
356
+ )
357
+ {
358
+ # print out the diagnostic information about why this
359
+ # test failed
360
+
361
+ local $_;
362
+
363
+ $t->diag( map { "$_\n" } $out->complaint )
364
+ unless $args{skip_out} || $out->check;
365
+
366
+ $t->diag( map { "$_\n" } $err->complaint )
367
+ unless $args{skip_err} || $err->check;
368
+ }
369
+ }
370
+
371
+ =item line_num
372
+
373
+ A utility function that returns the line number that the function was
374
+ called on. You can pass it an offset which will be added to the
375
+ result. This is very useful for working out the correct text of
376
+ diagnostic functions that contain line numbers.
377
+
378
+ Essentially this is the same as the C<__LINE__> macro, but the
379
+ C<line_num(+3)> idiom is arguably nicer.
380
+
381
+ =cut
382
+
383
+ sub line_num {
384
+ my( $package, $filename, $line ) = caller;
385
+ return $line + ( shift() || 0 ); # prevent warnings
386
+ }
387
+
388
+ =back
389
+
390
+ In addition to the six exported functions there exists one
391
+ function that can only be accessed with a fully qualified function
392
+ call.
393
+
394
+ =over 4
395
+
396
+ =item color
397
+
398
+ When C<test_test> is called and the output that your tests generate
399
+ does not match that which you declared, C<test_test> will print out
400
+ debug information showing the two conflicting versions. As this
401
+ output itself is debug information it can be confusing which part of
402
+ the output is from C<test_test> and which was the original output from
403
+ your original tests. Also, it may be hard to spot things like
404
+ extraneous whitespace at the end of lines that may cause your test to
405
+ fail even though the output looks similar.
406
+
407
+ To assist you C<test_test> can colour the background of the debug
408
+ information to disambiguate the different types of output. The debug
409
+ output will have its background coloured green and red. The green
410
+ part represents the text which is the same between the executed and
411
+ actual output, the red shows which part differs.
412
+
413
+ The C<color> function determines if colouring should occur or not.
414
+ Passing it a true or false value will enable or disable colouring
415
+ respectively, and the function called with no argument will return the
416
+ current setting.
417
+
418
+ To enable colouring from the command line, you can use the
419
+ L<Text::Builder::Tester::Color> module like so:
420
+
421
+ perl -Mlib=Text::Builder::Tester::Color test.t
422
+
423
+ Or by including the L<Test::Builder::Tester::Color> module directly in
424
+ the PERL5LIB.
425
+
426
+ =cut
427
+
428
+ my $color;
429
+
430
+ sub color {
431
+ $color = shift if @_;
432
+ $color;
433
+ }
434
+
435
+ =back
436
+
437
+ =head1 BUGS
438
+
439
+ Test::Builder::Tester does not handle plans well. It has never done anything
440
+ special with plans. This means that plans from outside Test::Builder::Tester
441
+ will affect Test::Builder::Tester, worse plans when using Test::Builder::Tester
442
+ will affect overall testing. At this point there are no plans to fix this bug
443
+ as people have come to depend on it, and Test::Builder::Tester is now
444
+ discouraged in favor of C<Test2::API::intercept()>. See
445
+ L<https://github.com/Test-More/test-more/issues/667>
446
+
447
+ Calls C<< Test::Builder->no_ending >> turning off the ending tests.
448
+ This is needed as otherwise it will trip out because we've run more
449
+ tests than we strictly should have and it'll register any failures we
450
+ had that we were testing for as real failures.
451
+
452
+ The color function doesn't work unless L<Term::ANSIColor> is
453
+ compatible with your terminal. Additionally, L<Win32::Console::ANSI>
454
+ must be installed on windows platforms for color output.
455
+
456
+ Bugs (and requests for new features) can be reported to the author
457
+ though GitHub:
458
+ L<https://github.com/Test-More/test-more/issues>
459
+
460
+ =head1 AUTHOR
461
+
462
+ Copyright Mark Fowler E<lt>mark@twoshortplanks.comE<gt> 2002, 2004.
463
+
464
+ Some code taken from L<Test::More> and L<Test::Catch>, written by
465
+ Michael G Schwern E<lt>schwern@pobox.comE<gt>. Hence, those parts
466
+ Copyright Micheal G Schwern 2001. Used and distributed with
467
+ permission.
468
+
469
+ This program is free software; you can redistribute it
470
+ and/or modify it under the same terms as Perl itself.
471
+
472
+ =head1 MAINTAINERS
473
+
474
+ =over 4
475
+
476
+ =item Chad Granum E<lt>exodist@cpan.orgE<gt>
477
+
478
+ =back
479
+
480
+ =head1 NOTES
481
+
482
+ Thanks to Richard Clamp E<lt>richardc@unixbeard.netE<gt> for letting
483
+ me use his testing system to try this module out on.
484
+
485
+ =head1 SEE ALSO
486
+
487
+ L<Test::Builder>, L<Test::Builder::Tester::Color>, L<Test::More>.
488
+
489
+ =cut
490
+
491
+ 1;
492
+
493
+ ####################################################################
494
+ # Helper class that is used to remember expected and received data
495
+
496
+ package Test::Builder::Tester::Tie;
497
+
498
+ ##
499
+ # add line(s) to be expected
500
+
501
+ sub expect {
502
+ my $self = shift;
503
+
504
+ my @checks = @_;
505
+ foreach my $check (@checks) {
506
+ $check = $self->_account_for_subtest($check);
507
+ $check = $self->_translate_Failed_check($check);
508
+ push @{ $self->{wanted} }, ref $check ? $check : "$check\n";
509
+ }
510
+ }
511
+
512
+ sub _account_for_subtest {
513
+ my( $self, $check ) = @_;
514
+
515
+ my $hub = $t->{Stack}->top;
516
+ my $nesting = $hub->isa('Test2::Hub::Subtest') ? $hub->nested : 0;
517
+ return ref($check) ? $check : (' ' x $nesting) . $check;
518
+ }
519
+
520
+ sub _translate_Failed_check {
521
+ my( $self, $check ) = @_;
522
+
523
+ if( $check =~ /\A(.*)# (Failed .*test) \((.*?) at line (\d+)\)\Z(?!\n)/ ) {
524
+ $check = "/\Q$1\E#\\s+\Q$2\E.*?\\n?.*?\Qat $3\E line \Q$4\E.*\\n?/";
525
+ }
526
+
527
+ return $check;
528
+ }
529
+
530
+ ##
531
+ # return true iff the expected data matches the got data
532
+
533
+ sub check {
534
+ my $self = shift;
535
+
536
+ # turn off warnings as these might be undef
537
+ local $^W = 0;
538
+
539
+ my @checks = @{ $self->{wanted} };
540
+ my $got = $self->{got};
541
+ foreach my $check (@checks) {
542
+ $check = "\Q$check\E" unless( $check =~ s,^/(.*)/$,$1, or ref $check );
543
+ return 0 unless $got =~ s/^$check//;
544
+ }
545
+
546
+ return length $got == 0;
547
+ }
548
+
549
+ ##
550
+ # a complaint message about the inputs not matching (to be
551
+ # used for debugging messages)
552
+
553
+ sub complaint {
554
+ my $self = shift;
555
+ my $type = $self->type;
556
+ my $got = $self->got;
557
+ my $wanted = join '', @{ $self->wanted };
558
+
559
+ # are we running in colour mode?
560
+ if(Test::Builder::Tester::color) {
561
+ # get color
562
+ eval { require Term::ANSIColor };
563
+ unless($@) {
564
+ eval { require Win32::Console::ANSI } if 'MSWin32' eq $^O; # support color on windows platforms
565
+
566
+ # colours
567
+
568
+ my $green = Term::ANSIColor::color("black") . Term::ANSIColor::color("on_green");
569
+ my $red = Term::ANSIColor::color("black") . Term::ANSIColor::color("on_red");
570
+ my $reset = Term::ANSIColor::color("reset");
571
+
572
+ # work out where the two strings start to differ
573
+ my $char = 0;
574
+ $char++ while substr( $got, $char, 1 ) eq substr( $wanted, $char, 1 );
575
+
576
+ # get the start string and the two end strings
577
+ my $start = $green . substr( $wanted, 0, $char );
578
+ my $gotend = $red . substr( $got, $char ) . $reset;
579
+ my $wantedend = $red . substr( $wanted, $char ) . $reset;
580
+
581
+ # make the start turn green on and off
582
+ $start =~ s/\n/$reset\n$green/g;
583
+
584
+ # make the ends turn red on and off
585
+ $gotend =~ s/\n/$reset\n$red/g;
586
+ $wantedend =~ s/\n/$reset\n$red/g;
587
+
588
+ # rebuild the strings
589
+ $got = $start . $gotend;
590
+ $wanted = $start . $wantedend;
591
+ }
592
+ }
593
+
594
+ my @got = split "\n", $got;
595
+ my @wanted = split "\n", $wanted;
596
+
597
+ $got = "";
598
+ $wanted = "";
599
+
600
+ while (@got || @wanted) {
601
+ my $g = shift @got || "";
602
+ my $w = shift @wanted || "";
603
+ if ($g ne $w) {
604
+ if($g =~ s/(\s+)$/ |> /g) {
605
+ $g .= ($_ eq ' ' ? '_' : '\t') for split '', $1;
606
+ }
607
+ if($w =~ s/(\s+)$/ |> /g) {
608
+ $w .= ($_ eq ' ' ? '_' : '\t') for split '', $1;
609
+ }
610
+ $g = "> $g";
611
+ $w = "> $w";
612
+ }
613
+ else {
614
+ $g = " $g";
615
+ $w = " $w";
616
+ }
617
+ $got = $got ? "$got\n$g" : $g;
618
+ $wanted = $wanted ? "$wanted\n$w" : $w;
619
+ }
620
+
621
+ return "$type is:\n" . "$got\nnot:\n$wanted\nas expected";
622
+ }
623
+
624
+ ##
625
+ # forget all expected and got data
626
+
627
+ sub reset {
628
+ my $self = shift;
629
+ %$self = (
630
+ type => $self->{type},
631
+ got => '',
632
+ wanted => [],
633
+ );
634
+ }
635
+
636
+ sub got {
637
+ my $self = shift;
638
+ return $self->{got};
639
+ }
640
+
641
+ sub wanted {
642
+ my $self = shift;
643
+ return $self->{wanted};
644
+ }
645
+
646
+ sub type {
647
+ my $self = shift;
648
+ return $self->{type};
649
+ }
650
+
651
+ ###
652
+ # tie interface
653
+ ###
654
+
655
+ sub PRINT {
656
+ my $self = shift;
657
+ $self->{got} .= join '', @_;
658
+ }
659
+
660
+ sub TIEHANDLE {
661
+ my( $class, $type ) = @_;
662
+
663
+ my $self = bless { type => $type }, $class;
664
+
665
+ $self->reset;
666
+
667
+ return $self;
668
+ }
669
+
670
+ sub READ { }
671
+ sub READLINE { }
672
+ sub GETC { }
673
+ sub FILENO { }
674
+
675
+ 1;
git/usr/share/perl5/core_perl/Test/Builder/Tester/Color.pm ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package Test::Builder::Tester::Color;
2
+
3
+ use strict;
4
+ our $VERSION = '1.302210';
5
+
6
+ require Test::Builder::Tester;
7
+
8
+
9
+ =head1 NAME
10
+
11
+ Test::Builder::Tester::Color - turn on colour in Test::Builder::Tester
12
+
13
+ =head1 SYNOPSIS
14
+
15
+ When running a test script
16
+
17
+ perl -MTest::Builder::Tester::Color test.t
18
+
19
+ =head1 DESCRIPTION
20
+
21
+ Importing this module causes the subroutine color in Test::Builder::Tester
22
+ to be called with a true value causing colour highlighting to be turned
23
+ on in debug output.
24
+
25
+ The sole purpose of this module is to enable colour highlighting
26
+ from the command line.
27
+
28
+ =cut
29
+
30
+ sub import {
31
+ Test::Builder::Tester::color(1);
32
+ }
33
+
34
+ =head1 AUTHOR
35
+
36
+ Copyright Mark Fowler E<lt>mark@twoshortplanks.comE<gt> 2002.
37
+
38
+ This program is free software; you can redistribute it
39
+ and/or modify it under the same terms as Perl itself.
40
+
41
+ =head1 BUGS
42
+
43
+ This module will have no effect unless Term::ANSIColor is installed.
44
+
45
+ =head1 SEE ALSO
46
+
47
+ L<Test::Builder::Tester>, L<Term::ANSIColor>
48
+
49
+ =cut
50
+
51
+ 1;
git/usr/share/perl5/core_perl/Test/Builder/TodoDiag.pm ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package Test::Builder::TodoDiag;
2
+ use strict;
3
+ use warnings;
4
+
5
+ our $VERSION = '1.302210';
6
+
7
+ BEGIN { require Test2::Event::Diag; our @ISA = qw(Test2::Event::Diag) }
8
+
9
+ sub diagnostics { 0 }
10
+
11
+ sub facet_data {
12
+ my $self = shift;
13
+ my $out = $self->SUPER::facet_data();
14
+ $out->{info}->[0]->{debug} = 0;
15
+ return $out;
16
+ }
17
+
18
+ 1;
19
+
20
+ __END__
21
+
22
+ =pod
23
+
24
+ =encoding UTF-8
25
+
26
+ =head1 NAME
27
+
28
+ Test::Builder::TodoDiag - Test::Builder subclass of Test2::Event::Diag
29
+
30
+ =head1 DESCRIPTION
31
+
32
+ This is used to encapsulate diag messages created inside TODO.
33
+
34
+ =head1 SYNOPSIS
35
+
36
+ You do not need to use this directly.
37
+
38
+ =head1 SOURCE
39
+
40
+ The source code repository for Test2 can be found at
41
+ L<https://github.com/Test-More/test-more/>.
42
+
43
+ =head1 MAINTAINERS
44
+
45
+ =over 4
46
+
47
+ =item Chad Granum E<lt>exodist@cpan.orgE<gt>
48
+
49
+ =back
50
+
51
+ =head1 AUTHORS
52
+
53
+ =over 4
54
+
55
+ =item Chad Granum E<lt>exodist@cpan.orgE<gt>
56
+
57
+ =back
58
+
59
+ =head1 COPYRIGHT
60
+
61
+ Copyright Chad Granum E<lt>exodist@cpan.orgE<gt>.
62
+
63
+ This program is free software; you can redistribute it and/or
64
+ modify it under the same terms as Perl itself.
65
+
66
+ See L<https://dev.perl.org/licenses/>
67
+
68
+ =cut
git/usr/share/perl5/core_perl/Test/Tester/Capture.pm ADDED
@@ -0,0 +1,240 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ use strict;
2
+
3
+ package Test::Tester::Capture;
4
+
5
+ our $VERSION = '1.302210';
6
+
7
+
8
+ use Test::Builder;
9
+
10
+ our @ISA = qw( Test::Builder );
11
+
12
+ # Make Test::Tester::Capture thread-safe for ithreads.
13
+ BEGIN {
14
+ use Config;
15
+ *share = sub { 0 };
16
+ *lock = sub { 0 };
17
+ }
18
+
19
+ my $Curr_Test = 0; share($Curr_Test);
20
+ my @Test_Results = (); share(@Test_Results);
21
+ my $Prem_Diag = {diag => ""}; share($Curr_Test);
22
+
23
+ sub new
24
+ {
25
+ # Test::Tester::Capgture::new used to just return __PACKAGE__
26
+ # because Test::Builder::new enforced its singleton nature by
27
+ # return __PACKAGE__. That has since changed, Test::Builder::new now
28
+ # returns a blessed has and around version 0.78, Test::Builder::todo
29
+ # started wanting to modify $self. To cope with this, we now return
30
+ # a blessed hash. This is a short-term hack, the correct thing to do
31
+ # is to detect which style of Test::Builder we're dealing with and
32
+ # act appropriately.
33
+
34
+ my $class = shift;
35
+ return bless {}, $class;
36
+ }
37
+
38
+ sub ok {
39
+ my($self, $test, $name) = @_;
40
+
41
+ my $ctx = $self->ctx;
42
+
43
+ # $test might contain an object which we don't want to accidentally
44
+ # store, so we turn it into a boolean.
45
+ $test = $test ? 1 : 0;
46
+
47
+ lock $Curr_Test;
48
+ $Curr_Test++;
49
+
50
+ my($pack, $file, $line) = $self->caller;
51
+
52
+ my $todo = $self->todo();
53
+
54
+ my $result = {};
55
+ share($result);
56
+
57
+ unless( $test ) {
58
+ @$result{ 'ok', 'actual_ok' } = ( ( $todo ? 1 : 0 ), 0 );
59
+ }
60
+ else {
61
+ @$result{ 'ok', 'actual_ok' } = ( 1, $test );
62
+ }
63
+
64
+ if( defined $name ) {
65
+ $name =~ s|#|\\#|g; # # in a name can confuse Test::Harness.
66
+ $result->{name} = $name;
67
+ }
68
+ else {
69
+ $result->{name} = '';
70
+ }
71
+
72
+ if( $todo ) {
73
+ my $what_todo = $todo;
74
+ $result->{reason} = $what_todo;
75
+ $result->{type} = 'todo';
76
+ }
77
+ else {
78
+ $result->{reason} = '';
79
+ $result->{type} = '';
80
+ }
81
+
82
+ $Test_Results[$Curr_Test-1] = $result;
83
+
84
+ unless( $test ) {
85
+ my $msg = $todo ? "Failed (TODO)" : "Failed";
86
+ $result->{fail_diag} = (" $msg test ($file at line $line)\n");
87
+ }
88
+
89
+ $result->{diag} = "";
90
+ $result->{_level} = $Test::Builder::Level;
91
+ $result->{_depth} = Test::Tester::find_run_tests();
92
+
93
+ $ctx->release;
94
+
95
+ return $test ? 1 : 0;
96
+ }
97
+
98
+ sub skip {
99
+ my($self, $why) = @_;
100
+ $why ||= '';
101
+
102
+ my $ctx = $self->ctx;
103
+
104
+ lock($Curr_Test);
105
+ $Curr_Test++;
106
+
107
+ my %result;
108
+ share(%result);
109
+ %result = (
110
+ 'ok' => 1,
111
+ actual_ok => 1,
112
+ name => '',
113
+ type => 'skip',
114
+ reason => $why,
115
+ diag => "",
116
+ _level => $Test::Builder::Level,
117
+ _depth => Test::Tester::find_run_tests(),
118
+ );
119
+ $Test_Results[$Curr_Test-1] = \%result;
120
+
121
+ $ctx->release;
122
+ return 1;
123
+ }
124
+
125
+ sub todo_skip {
126
+ my($self, $why) = @_;
127
+ $why ||= '';
128
+
129
+ my $ctx = $self->ctx;
130
+
131
+ lock($Curr_Test);
132
+ $Curr_Test++;
133
+
134
+ my %result;
135
+ share(%result);
136
+ %result = (
137
+ 'ok' => 1,
138
+ actual_ok => 0,
139
+ name => '',
140
+ type => 'todo_skip',
141
+ reason => $why,
142
+ diag => "",
143
+ _level => $Test::Builder::Level,
144
+ _depth => Test::Tester::find_run_tests(),
145
+ );
146
+
147
+ $Test_Results[$Curr_Test-1] = \%result;
148
+
149
+ $ctx->release;
150
+ return 1;
151
+ }
152
+
153
+ sub diag {
154
+ my($self, @msgs) = @_;
155
+ return unless @msgs;
156
+
157
+ # Prevent printing headers when compiling (i.e. -c)
158
+ return if $^C;
159
+
160
+ my $ctx = $self->ctx;
161
+
162
+ # Escape each line with a #.
163
+ foreach (@msgs) {
164
+ $_ = 'undef' unless defined;
165
+ }
166
+
167
+ push @msgs, "\n" unless $msgs[-1] =~ /\n\Z/;
168
+
169
+ my $result = $Curr_Test ? $Test_Results[$Curr_Test - 1] : $Prem_Diag;
170
+
171
+ $result->{diag} .= join("", @msgs);
172
+
173
+ $ctx->release;
174
+ return 0;
175
+ }
176
+
177
+ sub details {
178
+ return @Test_Results;
179
+ }
180
+
181
+
182
+ # Stub. Feel free to send me a patch to implement this.
183
+ sub note {
184
+ }
185
+
186
+ sub explain {
187
+ return Test::Builder::explain(@_);
188
+ }
189
+
190
+ sub premature
191
+ {
192
+ return $Prem_Diag->{diag};
193
+ }
194
+
195
+ sub current_test
196
+ {
197
+ if (@_ > 1)
198
+ {
199
+ die "Don't try to change the test number!";
200
+ }
201
+ else
202
+ {
203
+ return $Curr_Test;
204
+ }
205
+ }
206
+
207
+ sub reset
208
+ {
209
+ $Curr_Test = 0;
210
+ @Test_Results = ();
211
+ $Prem_Diag = {diag => ""};
212
+ }
213
+
214
+ 1;
215
+
216
+ __END__
217
+
218
+ =head1 NAME
219
+
220
+ Test::Tester::Capture - Help testing test modules built with Test::Builder
221
+
222
+ =head1 DESCRIPTION
223
+
224
+ This is a subclass of Test::Builder that overrides many of the methods so
225
+ that they don't output anything. It also keeps track of its own set of test
226
+ results so that you can use Test::Builder based modules to perform tests on
227
+ other Test::Builder based modules.
228
+
229
+ =head1 AUTHOR
230
+
231
+ Most of the code here was lifted straight from Test::Builder and then had
232
+ chunks removed by Fergal Daly <fergal@esatclear.ie>.
233
+
234
+ =head1 LICENSE
235
+
236
+ Under the same license as Perl itself
237
+
238
+ See L<https://dev.perl.org/licenses/>
239
+
240
+ =cut
git/usr/share/perl5/core_perl/Test/Tester/CaptureRunner.pm ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # $Header: /home/fergal/my/cvs/Test-Tester/lib/Test/Tester/CaptureRunner.pm,v 1.3 2003/03/05 01:07:55 fergal Exp $
2
+ use strict;
3
+
4
+ package Test::Tester::CaptureRunner;
5
+
6
+ our $VERSION = '1.302210';
7
+
8
+
9
+ use Test::Tester::Capture;
10
+ require Exporter;
11
+
12
+ sub new
13
+ {
14
+ my $pkg = shift;
15
+ my $self = bless {}, $pkg;
16
+ return $self;
17
+ }
18
+
19
+ sub run_tests
20
+ {
21
+ my $self = shift;
22
+
23
+ my $test = shift;
24
+
25
+ capture()->reset;
26
+
27
+ $self->{StartLevel} = $Test::Builder::Level;
28
+ &$test();
29
+ }
30
+
31
+ sub get_results
32
+ {
33
+ my $self = shift;
34
+ my @results = capture()->details;
35
+
36
+ my $start = $self->{StartLevel};
37
+ foreach my $res (@results)
38
+ {
39
+ next if defined $res->{depth};
40
+ my $depth = $res->{_depth} - $res->{_level} - $start - 3;
41
+ # print "my $depth = $res->{_depth} - $res->{_level} - $start - 1\n";
42
+ $res->{depth} = $depth;
43
+ }
44
+
45
+ return @results;
46
+ }
47
+
48
+ sub get_premature
49
+ {
50
+ return capture()->premature;
51
+ }
52
+
53
+ sub capture
54
+ {
55
+ return Test::Tester::Capture->new;
56
+ }
57
+
58
+ __END__
59
+
60
+ =head1 NAME
61
+
62
+ Test::Tester::CaptureRunner - Help testing test modules built with Test::Builder
63
+
64
+ =head1 DESCRIPTION
65
+
66
+ This stuff if needed to allow me to play with other ways of monitoring the
67
+ test results.
68
+
69
+ =head1 AUTHOR
70
+
71
+ Copyright 2003 by Fergal Daly <fergal@esatclear.ie>.
72
+
73
+ =head1 LICENSE
74
+
75
+ Under the same license as Perl itself
76
+
77
+ See L<https://dev.perl.org/licenses/>
78
+
79
+ =cut
git/usr/share/perl5/core_perl/Test/Tester/Delegate.pm ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ use strict;
2
+ use warnings;
3
+
4
+ package Test::Tester::Delegate;
5
+
6
+ our $VERSION = '1.302210';
7
+
8
+ use Scalar::Util();
9
+
10
+ sub new
11
+ {
12
+ my $pkg = shift;
13
+
14
+ my $obj = shift;
15
+ my $self = bless {}, $pkg;
16
+
17
+ return $self;
18
+ }
19
+
20
+ sub AUTOLOAD
21
+ {
22
+ my ($sub) = our $AUTOLOAD =~ /.*::(.*?)$/;
23
+
24
+ return if $sub eq "DESTROY";
25
+
26
+ my $obj = $_[0]->{Object};
27
+
28
+ my $ref = $obj->can($sub);
29
+ shift(@_);
30
+ unshift(@_, $obj);
31
+ goto &$ref;
32
+ }
33
+
34
+ sub can {
35
+ my $this = shift;
36
+ my ($sub) = @_;
37
+
38
+ return $this->{Object}->can($sub) if Scalar::Util::blessed($this);
39
+
40
+ return $this->SUPER::can(@_);
41
+ }
42
+
43
+ 1;
git/usr/share/perl5/core_perl/Test/use/ok.pm ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package Test::use::ok;
2
+ use 5.005;
3
+
4
+ our $VERSION = '1.302210';
5
+
6
+
7
+ __END__
8
+
9
+ =head1 NAME
10
+
11
+ Test::use::ok - Alternative to Test::More::use_ok
12
+
13
+ =head1 SYNOPSIS
14
+
15
+ use ok 'Some::Module';
16
+
17
+ =head1 DESCRIPTION
18
+
19
+ According to the B<Test::More> documentation, it is recommended to run
20
+ C<use_ok()> inside a C<BEGIN> block, so functions are exported at
21
+ compile-time and prototypes are properly honored.
22
+
23
+ That is, instead of writing this:
24
+
25
+ use_ok( 'Some::Module' );
26
+ use_ok( 'Other::Module' );
27
+
28
+ One should write this:
29
+
30
+ BEGIN { use_ok( 'Some::Module' ); }
31
+ BEGIN { use_ok( 'Other::Module' ); }
32
+
33
+ However, people often either forget to add C<BEGIN>, or mistakenly group
34
+ C<use_ok> with other tests in a single C<BEGIN> block, which can create subtle
35
+ differences in execution order.
36
+
37
+ With this module, simply change all C<use_ok> in test scripts to C<use ok>,
38
+ and they will be executed at C<BEGIN> time. The explicit space after C<use>
39
+ makes it clear that this is a single compile-time action.
40
+
41
+ =head1 SEE ALSO
42
+
43
+ L<Test::More>
44
+
45
+ =head1 MAINTAINER
46
+
47
+ =over 4
48
+
49
+ =item Chad Granum E<lt>exodist@cpan.orgE<gt>
50
+
51
+ =back
52
+
53
+ =encoding utf8
54
+
55
+ =head1 CC0 1.0 Universal
56
+
57
+ To the extent possible under law, 唐鳳 has waived all copyright and related
58
+ or neighboring rights to L<Test::use::ok>.
59
+
60
+ This work is published from Taiwan.
61
+
62
+ L<https://creativecommons.org/publicdomain/zero/1.0/>
63
+
64
+ =cut
git/usr/share/perl5/core_perl/Test2/API/Breakage.pm ADDED
@@ -0,0 +1,180 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package Test2::API::Breakage;
2
+ use strict;
3
+ use warnings;
4
+
5
+ our $VERSION = '1.302210';
6
+
7
+
8
+ use Test2::Util qw/pkg_to_file/;
9
+
10
+ our @EXPORT_OK = qw{
11
+ upgrade_suggested
12
+ upgrade_required
13
+ known_broken
14
+ };
15
+ BEGIN { require Exporter; our @ISA = qw(Exporter) }
16
+
17
+ sub upgrade_suggested {
18
+ return (
19
+ 'Test::Exception' => '0.42',
20
+ 'Test::FITesque' => '0.04',
21
+ 'Test::Module::Used' => '0.2.5',
22
+ 'Test::Moose::More' => '0.025',
23
+ );
24
+ }
25
+
26
+ sub upgrade_required {
27
+ return (
28
+ 'Test::Builder::Clutch' => '0.07',
29
+ 'Test::Dist::VersionSync' => '1.1.4',
30
+ 'Test::Modern' => '0.012',
31
+ 'Test::SharedFork' => '0.34',
32
+ 'Test::Alien' => '0.04',
33
+ 'Test::UseAllModules' => '0.14',
34
+ 'Test::More::Prefix' => '0.005',
35
+
36
+ 'Test2::Tools::EventDumper' => 0.000007,
37
+ 'Test2::Harness' => 0.000013,
38
+
39
+ 'Test::DBIx::Class::Schema' => '1.0.9',
40
+ 'Test::Clustericious::Cluster' => '0.30',
41
+ );
42
+ }
43
+
44
+ sub known_broken {
45
+ return (
46
+ 'Net::BitTorrent' => '0.052',
47
+ 'Test::Able' => '0.11',
48
+ 'Test::Aggregate' => '0.373',
49
+ 'Test::Flatten' => '0.11',
50
+ 'Test::Group' => '0.20',
51
+ 'Test::ParallelSubtest' => '0.05',
52
+ 'Test::Pretty' => '0.32',
53
+ 'Test::Wrapper' => '0.3.0',
54
+
55
+ 'Log::Dispatch::Config::TestLog' => '0.02',
56
+ );
57
+ }
58
+
59
+ # Not reportable:
60
+ # Device::Chip => 0.07 - Tests will not pass, but not broken if already installed, also no fixed version we can upgrade to.
61
+
62
+ sub report {
63
+ my $class = shift;
64
+ my ($require) = @_;
65
+
66
+ my %suggest = __PACKAGE__->upgrade_suggested();
67
+ my %required = __PACKAGE__->upgrade_required();
68
+ my %broken = __PACKAGE__->known_broken();
69
+
70
+ my @warn;
71
+ for my $mod (keys %suggest) {
72
+ my $file = pkg_to_file($mod);
73
+ next unless $INC{$file} || ($require && eval { require $file; 1 });
74
+ my $want = $suggest{$mod};
75
+ next if eval { $mod->VERSION($want); 1 };
76
+ my $error = $@;
77
+ chomp $error;
78
+ push @warn => " * Module '$mod' is outdated, we recommend updating above $want. error was: '$error'; INC is $INC{$file}";
79
+ }
80
+
81
+ for my $mod (keys %required) {
82
+ my $file = pkg_to_file($mod);
83
+ next unless $INC{$file} || ($require && eval { require $file; 1 });
84
+ my $want = $required{$mod};
85
+ next if eval { $mod->VERSION($want); 1 };
86
+ push @warn => " * Module '$mod' is outdated and known to be broken, please update to $want or higher.";
87
+ }
88
+
89
+ for my $mod (keys %broken) {
90
+ my $file = pkg_to_file($mod);
91
+ next unless $INC{$file} || ($require && eval { require $file; 1 });
92
+ my $tested = $broken{$mod};
93
+ push @warn => " * Module '$mod' is known to be broken in version $tested and below, newer versions have not been tested. You have: " . $mod->VERSION;
94
+ }
95
+
96
+ return @warn;
97
+ }
98
+
99
+ 1;
100
+
101
+ __END__
102
+
103
+
104
+ =pod
105
+
106
+ =encoding UTF-8
107
+
108
+ =head1 NAME
109
+
110
+ Test2::API::Breakage - What breaks at what version
111
+
112
+ =head1 DESCRIPTION
113
+
114
+ This module provides lists of modules that are broken, or have been broken in
115
+ the past, when upgrading L<Test::Builder> to use L<Test2>.
116
+
117
+ =head1 FUNCTIONS
118
+
119
+ These can be imported, or called as methods on the class.
120
+
121
+ =over 4
122
+
123
+ =item %mod_ver = upgrade_suggested()
124
+
125
+ =item %mod_ver = Test2::API::Breakage->upgrade_suggested()
126
+
127
+ This returns key/value pairs. The key is the module name, the value is the
128
+ version number. If the installed version of the module is at or below the
129
+ specified one then an upgrade would be a good idea, but not strictly necessary.
130
+
131
+ =item %mod_ver = upgrade_required()
132
+
133
+ =item %mod_ver = Test2::API::Breakage->upgrade_required()
134
+
135
+ This returns key/value pairs. The key is the module name, the value is the
136
+ version number. If the installed version of the module is at or below the
137
+ specified one then an upgrade is required for the module to work properly.
138
+
139
+ =item %mod_ver = known_broken()
140
+
141
+ =item %mod_ver = Test2::API::Breakage->known_broken()
142
+
143
+ This returns key/value pairs. The key is the module name, the value is the
144
+ version number. If the installed version of the module is at or below the
145
+ specified one then the module will not work. A newer version may work, but is
146
+ not tested or verified.
147
+
148
+ =back
149
+
150
+ =head1 SOURCE
151
+
152
+ The source code repository for Test2 can be found at
153
+ L<https://github.com/Test-More/test-more/>.
154
+
155
+ =head1 MAINTAINERS
156
+
157
+ =over 4
158
+
159
+ =item Chad Granum E<lt>exodist@cpan.orgE<gt>
160
+
161
+ =back
162
+
163
+ =head1 AUTHORS
164
+
165
+ =over 4
166
+
167
+ =item Chad Granum E<lt>exodist@cpan.orgE<gt>
168
+
169
+ =back
170
+
171
+ =head1 COPYRIGHT
172
+
173
+ Copyright Chad Granum E<lt>exodist@cpan.orgE<gt>.
174
+
175
+ This program is free software; you can redistribute it and/or
176
+ modify it under the same terms as Perl itself.
177
+
178
+ See L<https://dev.perl.org/licenses/>
179
+
180
+ =cut
git/usr/share/perl5/core_perl/Test2/API/Context.pm ADDED
@@ -0,0 +1,1036 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package Test2::API::Context;
2
+ use strict;
3
+ use warnings;
4
+
5
+ our $VERSION = '1.302210';
6
+
7
+
8
+ use Carp qw/confess croak/;
9
+ use Scalar::Util qw/weaken blessed/;
10
+ use Test2::Util qw/get_tid try pkg_to_file get_tid/;
11
+
12
+ use Test2::EventFacet::Trace();
13
+ use Test2::API();
14
+
15
+ # Preload some key event types
16
+ my %LOADED = (
17
+ map {
18
+ my $pkg = "Test2::Event::$_";
19
+ my $file = "Test2/Event/$_.pm";
20
+ require $file unless $INC{$file};
21
+ ( $pkg => $pkg, $_ => $pkg )
22
+ } qw/Ok Diag Note Plan Bail Exception Waiting Skip Subtest Pass Fail V2/
23
+ );
24
+
25
+ use Test2::Util::ExternalMeta qw/meta get_meta set_meta delete_meta/;
26
+ use Test2::Util::HashBase qw{
27
+ stack hub trace _on_release _depth _is_canon _is_spawn _aborted
28
+ errno eval_error child_error thrown _failed _start_fail_count
29
+ };
30
+
31
+ # Private, not package vars
32
+ # It is safe to cache these.
33
+ my $ON_RELEASE = Test2::API::_context_release_callbacks_ref();
34
+ my $CONTEXTS = Test2::API::_contexts_ref();
35
+
36
+ sub init {
37
+ my $self = shift;
38
+
39
+ confess "The 'trace' attribute is required"
40
+ unless $self->{+TRACE};
41
+
42
+ confess "The 'hub' attribute is required"
43
+ unless $self->{+HUB};
44
+
45
+ $self->{+_START_FAIL_COUNT} = $self->{+HUB}->{failed} || 0;
46
+
47
+ $self->{+_DEPTH} = 0 unless defined $self->{+_DEPTH};
48
+
49
+ $self->{+ERRNO} = $! unless exists $self->{+ERRNO};
50
+ $self->{+EVAL_ERROR} = $@ unless exists $self->{+EVAL_ERROR};
51
+ $self->{+CHILD_ERROR} = $? unless exists $self->{+CHILD_ERROR};
52
+ }
53
+
54
+ sub snapshot { bless {%{$_[0]}, _is_canon => undef, _is_spawn => undef, _aborted => undef}, __PACKAGE__ }
55
+
56
+ sub restore_error_vars {
57
+ my $self = shift;
58
+ ($!, $@, $?) = @$self{+ERRNO, +EVAL_ERROR, +CHILD_ERROR};
59
+ }
60
+
61
+ sub DESTROY {
62
+ return unless $_[0]->{+_IS_CANON} || $_[0]->{+_IS_SPAWN};
63
+ return if $_[0]->{+_ABORTED} && ${$_[0]->{+_ABORTED}};
64
+ my ($self) = @_;
65
+
66
+ my $hub = $self->{+HUB};
67
+ my $hid = $hub->{hid};
68
+
69
+ $self->{+_FAILED} = ($hub->{failed} || 0) - $self->{+_START_FAIL_COUNT};
70
+
71
+ # Do not show the warning if it looks like an exception has been thrown, or
72
+ # if the context is not local to this process or thread.
73
+ {
74
+ # Sometimes $@ is uninitialized, not a problem in this case so do not
75
+ # show the warning about using eq.
76
+ no warnings 'uninitialized';
77
+ if($self->{+EVAL_ERROR} eq $@ && $hub->is_local) {
78
+ require Carp;
79
+ my $mess = Carp::longmess("Context destroyed");
80
+ my $frame = $self->{+_IS_SPAWN} || $self->{+TRACE}->frame;
81
+ warn <<" EOT";
82
+ A context appears to have been destroyed without first calling release().
83
+ Based on \$@ it does not look like an exception was thrown (this is not always
84
+ a reliable test)
85
+
86
+ This is a problem because the global error variables (\$!, \$@, and \$?) will
87
+ not be restored. In addition some release callbacks will not work properly from
88
+ inside a DESTROY method.
89
+
90
+ Here are the context creation details, just in case a tool forgot to call
91
+ release():
92
+ File: $frame->[1]
93
+ Line: $frame->[2]
94
+ Tool: $frame->[3]
95
+
96
+ Here is a trace to the code that caused the context to be destroyed, this could
97
+ be an exit(), a goto, or simply the end of a scope:
98
+ $mess
99
+
100
+ Cleaning up the CONTEXT stack...
101
+ EOT
102
+ }
103
+ }
104
+
105
+ return if $self->{+_IS_SPAWN};
106
+
107
+ # Remove the key itself to avoid a slow memory leak
108
+ delete $CONTEXTS->{$hid};
109
+ $self->{+_IS_CANON} = undef;
110
+
111
+ if (my $cbk = $self->{+_ON_RELEASE}) {
112
+ $_->($self) for reverse @$cbk;
113
+ }
114
+ if (my $hcbk = $hub->{_context_release}) {
115
+ $_->($self) for reverse @$hcbk;
116
+ }
117
+ $_->($self) for reverse @$ON_RELEASE;
118
+
119
+ if (my @diags = Test2::API::test2_clear_pending_diags()) {
120
+ if ($self->{+_FAILED} || ${$self->{+_ABORTED}}) {
121
+ $self->diag($_) for @diags;
122
+ }
123
+ }
124
+ }
125
+
126
+ # release exists to implement behaviors like die-on-fail. In die-on-fail you
127
+ # want to die after a failure, but only after diagnostics have been reported.
128
+ # The ideal time for the die to happen is when the context is released.
129
+ # Unfortunately die does not work in a DESTROY block.
130
+ sub release {
131
+ my ($self) = @_;
132
+
133
+ ($!, $@, $?) = @$self{+ERRNO, +EVAL_ERROR, +CHILD_ERROR} and return if $self->{+THROWN};
134
+
135
+ ($!, $@, $?) = @$self{+ERRNO, +EVAL_ERROR, +CHILD_ERROR} and return $self->{+_IS_SPAWN} = undef
136
+ if $self->{+_IS_SPAWN};
137
+
138
+ croak "release() should not be called on context that is neither canon nor a child"
139
+ unless $self->{+_IS_CANON};
140
+
141
+ my $hub = $self->{+HUB};
142
+ my $hid = $hub->{hid};
143
+
144
+ $self->{+_FAILED} = ($hub->{failed} || 0) - $self->{+_START_FAIL_COUNT};
145
+
146
+ croak "context thinks it is canon, but it is not"
147
+ unless $CONTEXTS->{$hid} && $CONTEXTS->{$hid} == $self;
148
+
149
+ # Remove the key itself to avoid a slow memory leak
150
+ $self->{+_IS_CANON} = undef;
151
+ delete $CONTEXTS->{$hid};
152
+
153
+ if (my $cbk = $self->{+_ON_RELEASE}) {
154
+ $_->($self) for reverse @$cbk;
155
+ }
156
+ if (my $hcbk = $hub->{_context_release}) {
157
+ $_->($self) for reverse @$hcbk;
158
+ }
159
+ $_->($self) for reverse @$ON_RELEASE;
160
+
161
+ if (my @diags = Test2::API::test2_clear_pending_diags()) {
162
+ if ($self->{+_FAILED} || ${$self->{+_ABORTED}}) {
163
+ $self->diag($_) for @diags;
164
+ }
165
+ }
166
+
167
+ # Do this last so that nothing else changes them.
168
+ # If one of the hooks dies then these do not get restored, this is
169
+ # intentional
170
+ ($!, $@, $?) = @$self{+ERRNO, +EVAL_ERROR, +CHILD_ERROR};
171
+
172
+ return;
173
+ }
174
+
175
+ sub do_in_context {
176
+ my $self = shift;
177
+ my ($sub, @args) = @_;
178
+
179
+ # We need to update the pid/tid and error vars.
180
+ my $clone = $self->snapshot;
181
+ @$clone{+ERRNO, +EVAL_ERROR, +CHILD_ERROR} = ($!, $@, $?);
182
+ $clone->{+TRACE} = $clone->{+TRACE}->snapshot(pid => $$, tid => get_tid());
183
+
184
+ my $hub = $clone->{+HUB};
185
+ my $hid = $hub->hid;
186
+
187
+ my $old = $CONTEXTS->{$hid};
188
+
189
+ $clone->{+_IS_CANON} = 1;
190
+ $CONTEXTS->{$hid} = $clone;
191
+ weaken($CONTEXTS->{$hid});
192
+ my ($ok, $err) = &try($sub, @args);
193
+ my ($rok, $rerr) = try { $clone->release };
194
+ delete $clone->{+_IS_CANON};
195
+
196
+ if ($old) {
197
+ $CONTEXTS->{$hid} = $old;
198
+ weaken($CONTEXTS->{$hid});
199
+ }
200
+ else {
201
+ delete $CONTEXTS->{$hid};
202
+ }
203
+
204
+ die $err unless $ok;
205
+ die $rerr unless $rok;
206
+ }
207
+
208
+ sub done_testing {
209
+ my $self = shift;
210
+ $self->hub->finalize($self->trace, 1);
211
+ return;
212
+ }
213
+
214
+ sub throw {
215
+ my ($self, $msg) = @_;
216
+ $self->{+THROWN} = 1;
217
+ ${$self->{+_ABORTED}}++ if $self->{+_ABORTED};
218
+ $self->release if $self->{+_IS_CANON} || $self->{+_IS_SPAWN};
219
+ $self->trace->throw($msg);
220
+ }
221
+
222
+ sub alert {
223
+ my ($self, $msg) = @_;
224
+ $self->trace->alert($msg);
225
+ }
226
+
227
+ sub send_ev2_and_release {
228
+ my $self = shift;
229
+ my $out = $self->send_ev2(@_);
230
+ $self->release;
231
+ return $out;
232
+ }
233
+
234
+ sub send_ev2 {
235
+ my $self = shift;
236
+
237
+ my $e;
238
+ {
239
+ local $Carp::CarpLevel = $Carp::CarpLevel + 1;
240
+ $e = Test2::Event::V2->new(
241
+ trace => $self->{+TRACE}->snapshot,
242
+ @_,
243
+ );
244
+ }
245
+
246
+ if ($self->{+_ABORTED}) {
247
+ my $f = $e->facet_data;
248
+ ${$self->{+_ABORTED}}++ if $f->{control}->{halt} || defined($f->{control}->{terminate}) || defined($e->terminate);
249
+ }
250
+ $self->{+HUB}->send($e);
251
+ }
252
+
253
+ sub build_ev2 {
254
+ my $self = shift;
255
+
256
+ local $Carp::CarpLevel = $Carp::CarpLevel + 1;
257
+ Test2::Event::V2->new(
258
+ trace => $self->{+TRACE}->snapshot,
259
+ @_,
260
+ );
261
+ }
262
+
263
+ sub send_event_and_release {
264
+ my $self = shift;
265
+ my $out = $self->send_event(@_);
266
+ $self->release;
267
+ return $out;
268
+ }
269
+
270
+ sub send_event {
271
+ my $self = shift;
272
+ my $event = shift;
273
+ my %args = @_;
274
+
275
+ my $pkg = $LOADED{$event} || $self->_parse_event($event);
276
+
277
+ my $e;
278
+ {
279
+ local $Carp::CarpLevel = $Carp::CarpLevel + 1;
280
+ $e = $pkg->new(
281
+ trace => $self->{+TRACE}->snapshot,
282
+ %args,
283
+ );
284
+ }
285
+
286
+ if ($self->{+_ABORTED}) {
287
+ my $f = $e->facet_data;
288
+ ${$self->{+_ABORTED}}++ if $f->{control}->{halt} || defined($f->{control}->{terminate}) || defined($e->terminate);
289
+ }
290
+ $self->{+HUB}->send($e);
291
+ }
292
+
293
+ sub build_event {
294
+ my $self = shift;
295
+ my $event = shift;
296
+ my %args = @_;
297
+
298
+ my $pkg = $LOADED{$event} || $self->_parse_event($event);
299
+
300
+ local $Carp::CarpLevel = $Carp::CarpLevel + 1;
301
+ $pkg->new(
302
+ trace => $self->{+TRACE}->snapshot,
303
+ %args,
304
+ );
305
+ }
306
+
307
+ sub pass {
308
+ my $self = shift;
309
+ my ($name) = @_;
310
+
311
+ my $e = bless(
312
+ {
313
+ trace => bless({%{$self->{+TRACE}}}, 'Test2::EventFacet::Trace'),
314
+ name => $name,
315
+ },
316
+ "Test2::Event::Pass"
317
+ );
318
+
319
+ $self->{+HUB}->send($e);
320
+ return $e;
321
+ }
322
+
323
+ sub pass_and_release {
324
+ my $self = shift;
325
+ my ($name) = @_;
326
+
327
+ my $e = bless(
328
+ {
329
+ trace => bless({%{$self->{+TRACE}}}, 'Test2::EventFacet::Trace'),
330
+ name => $name,
331
+ },
332
+ "Test2::Event::Pass"
333
+ );
334
+
335
+ $self->{+HUB}->send($e);
336
+ $self->release;
337
+ return 1;
338
+ }
339
+
340
+ sub fail {
341
+ my $self = shift;
342
+ my ($name, @diag) = @_;
343
+
344
+ my $e = bless(
345
+ {
346
+ trace => bless({%{$self->{+TRACE}}}, 'Test2::EventFacet::Trace'),
347
+ name => $name,
348
+ },
349
+ "Test2::Event::Fail"
350
+ );
351
+
352
+ for my $msg (@diag) {
353
+ if (ref($msg) eq 'Test2::EventFacet::Info::Table') {
354
+ $e->add_info({tag => 'DIAG', debug => 1, $msg->info_args});
355
+ }
356
+ else {
357
+ $e->add_info({tag => 'DIAG', debug => 1, details => $msg});
358
+ }
359
+ }
360
+
361
+ $self->{+HUB}->send($e);
362
+ return $e;
363
+ }
364
+
365
+ sub fail_and_release {
366
+ my $self = shift;
367
+ my ($name, @diag) = @_;
368
+
369
+ my $e = bless(
370
+ {
371
+ trace => bless({%{$self->{+TRACE}}}, 'Test2::EventFacet::Trace'),
372
+ name => $name,
373
+ },
374
+ "Test2::Event::Fail"
375
+ );
376
+
377
+ for my $msg (@diag) {
378
+ if (ref($msg) eq 'Test2::EventFacet::Info::Table') {
379
+ $e->add_info({tag => 'DIAG', debug => 1, $msg->info_args});
380
+ }
381
+ else {
382
+ $e->add_info({tag => 'DIAG', debug => 1, details => $msg});
383
+ }
384
+ }
385
+
386
+ $self->{+HUB}->send($e);
387
+ $self->release;
388
+ return 0;
389
+ }
390
+
391
+ sub ok {
392
+ my $self = shift;
393
+ my ($pass, $name, $on_fail) = @_;
394
+
395
+ my $hub = $self->{+HUB};
396
+
397
+ my $e = bless {
398
+ trace => bless( {%{$self->{+TRACE}}}, 'Test2::EventFacet::Trace'),
399
+ pass => $pass,
400
+ name => $name,
401
+ }, 'Test2::Event::Ok';
402
+ $e->init;
403
+
404
+ $hub->send($e);
405
+ return $e if $pass;
406
+
407
+ $self->failure_diag($e);
408
+
409
+ if ($on_fail && @$on_fail) {
410
+ $self->diag($_) for @$on_fail;
411
+ }
412
+
413
+ return $e;
414
+ }
415
+
416
+ sub failure_diag {
417
+ my $self = shift;
418
+ my ($e) = @_;
419
+
420
+ # Figure out the debug info, this is typically the file name and line
421
+ # number, but can also be a custom message. If no trace object is provided
422
+ # then we have nothing useful to display.
423
+ my $name = $e->name;
424
+ my $trace = $e->trace;
425
+ my $debug = $trace ? $trace->debug : "[No trace info available]";
426
+
427
+ # Create the initial diagnostics. If the test has a name we put the debug
428
+ # info on a second line, this behavior is inherited from Test::Builder.
429
+ my $msg = defined($name)
430
+ ? qq[Failed test '$name'\n$debug.\n]
431
+ : qq[Failed test $debug.\n];
432
+
433
+ $self->diag($msg);
434
+ }
435
+
436
+ sub skip {
437
+ my $self = shift;
438
+ my ($name, $reason, @extra) = @_;
439
+ $self->send_event(
440
+ 'Skip',
441
+ name => $name,
442
+ reason => $reason,
443
+ pass => 1,
444
+ @extra,
445
+ );
446
+ }
447
+
448
+ sub note {
449
+ my $self = shift;
450
+ my ($message) = @_;
451
+ $self->send_event('Note', message => $message);
452
+ }
453
+
454
+ sub diag {
455
+ my $self = shift;
456
+ my ($message) = @_;
457
+ $self->send_event(
458
+ 'Diag',
459
+ message => $message,
460
+ );
461
+ }
462
+
463
+ sub plan {
464
+ my ($self, $max, $directive, $reason) = @_;
465
+ $self->send_event('Plan', max => $max, directive => $directive, reason => $reason);
466
+ }
467
+
468
+ sub bail {
469
+ my ($self, $reason) = @_;
470
+ $self->send_event('Bail', reason => $reason);
471
+ }
472
+
473
+ sub _parse_event {
474
+ my $self = shift;
475
+ my $event = shift;
476
+
477
+ my $pkg;
478
+ if ($event =~ m/^\+(.*)/) {
479
+ $pkg = $1;
480
+ }
481
+ else {
482
+ $pkg = "Test2::Event::$event";
483
+ }
484
+
485
+ unless ($LOADED{$pkg}) {
486
+ my $file = pkg_to_file($pkg);
487
+ my ($ok, $err) = try { require $file };
488
+ $self->throw("Could not load event module '$pkg': $err")
489
+ unless $ok;
490
+
491
+ $LOADED{$pkg} = $pkg;
492
+ }
493
+
494
+ confess "'$pkg' is not a subclass of 'Test2::Event'"
495
+ unless $pkg->isa('Test2::Event');
496
+
497
+ $LOADED{$event} = $pkg;
498
+
499
+ return $pkg;
500
+ }
501
+
502
+ 1;
503
+
504
+ __END__
505
+
506
+ =pod
507
+
508
+ =encoding UTF-8
509
+
510
+ =head1 NAME
511
+
512
+ Test2::API::Context - Object to represent a testing context.
513
+
514
+ =head1 DESCRIPTION
515
+
516
+ The context object is the primary interface for authors of testing tools
517
+ written with L<Test2>. The context object represents the context in
518
+ which a test takes place (File and Line Number), and provides a quick way to
519
+ generate events from that context. The context object also takes care of
520
+ sending events to the correct L<Test2::Hub> instance.
521
+
522
+ =head1 SYNOPSIS
523
+
524
+ In general you will not be creating contexts directly. To obtain a context you
525
+ should always use C<context()> which is exported by the L<Test2::API> module.
526
+
527
+ use Test2::API qw/context/;
528
+
529
+ sub my_ok {
530
+ my ($bool, $name) = @_;
531
+ my $ctx = context();
532
+
533
+ if ($bool) {
534
+ $ctx->pass($name);
535
+ }
536
+ else {
537
+ $ctx->fail($name);
538
+ }
539
+
540
+ $ctx->release; # You MUST do this!
541
+ return $bool;
542
+ }
543
+
544
+ Context objects make it easy to wrap other tools that also use context. Once
545
+ you grab a context, any tool you call before releasing your context will
546
+ inherit it:
547
+
548
+ sub wrapper {
549
+ my ($bool, $name) = @_;
550
+ my $ctx = context();
551
+ $ctx->diag("wrapping my_ok");
552
+
553
+ my $out = my_ok($bool, $name);
554
+ $ctx->release; # You MUST do this!
555
+ return $out;
556
+ }
557
+
558
+ =head1 CRITICAL DETAILS
559
+
560
+ =over 4
561
+
562
+ =item you MUST always use the context() sub from Test2::API
563
+
564
+ Creating your own context via C<< Test2::API::Context->new() >> will almost never
565
+ produce a desirable result. Use C<context()> which is exported by L<Test2::API>.
566
+
567
+ There are a handful of cases where a tool author may want to create a new
568
+ context by hand, which is why the C<new> method exists. Unless you really know
569
+ what you are doing you should avoid this.
570
+
571
+ =item You MUST always release the context when done with it
572
+
573
+ Releasing the context tells the system you are done with it. This gives it a
574
+ chance to run any necessary callbacks or cleanup tasks. If you forget to
575
+ release the context it will try to detect the problem and warn you about it.
576
+
577
+ =item You MUST NOT pass context objects around
578
+
579
+ When you obtain a context object it is made specifically for your tool and any
580
+ tools nested within. If you pass a context around you run the risk of polluting
581
+ other tools with incorrect context information.
582
+
583
+ If you are certain that you want a different tool to use the same context you
584
+ may pass it a snapshot. C<< $ctx->snapshot >> will give you a shallow clone of
585
+ the context that is safe to pass around or store.
586
+
587
+ =item You MUST NOT store or cache a context for later
588
+
589
+ As long as a context exists for a given hub, all tools that try to get a
590
+ context will get the existing instance. If you try to store the context you
591
+ will pollute other tools with incorrect context information.
592
+
593
+ If you are certain that you want to save the context for later, you can use a
594
+ snapshot. C<< $ctx->snapshot >> will give you a shallow clone of the context
595
+ that is safe to pass around or store.
596
+
597
+ C<context()> has some mechanisms to protect you if you do cause a context to
598
+ persist beyond the scope in which it was obtained. In practice you should not
599
+ rely on these protections, and they are fairly noisy with warnings.
600
+
601
+ =item You SHOULD obtain your context as soon as possible in a given tool
602
+
603
+ You never know what tools you call from within your own tool will need a
604
+ context. Obtaining the context early ensures that nested tools can find the
605
+ context you want them to find.
606
+
607
+ =back
608
+
609
+ =head1 METHODS
610
+
611
+ =over 4
612
+
613
+ =item $ctx->done_testing;
614
+
615
+ Note that testing is finished. If no plan has been set this will generate a
616
+ Plan event.
617
+
618
+ =item $clone = $ctx->snapshot()
619
+
620
+ This will return a shallow clone of the context. The shallow clone is safe to
621
+ store for later.
622
+
623
+ =item $ctx->release()
624
+
625
+ This will release the context. This runs cleanup tasks, and several important
626
+ hooks. It will also restore C<$!>, C<$?>, and C<$@> to what they were when the
627
+ context was created.
628
+
629
+ B<Note:> If a context is acquired more than once an internal refcount is kept.
630
+ C<release()> decrements the ref count, none of the other actions of
631
+ C<release()> will occur unless the refcount hits 0. This means only the last
632
+ call to C<release()> will reset C<$?>, C<$!>, C<$@>, and run the cleanup tasks.
633
+
634
+ =item $ctx->throw($message)
635
+
636
+ This will throw an exception reporting to the file and line number of the
637
+ context. This will also release the context for you.
638
+
639
+ =item $ctx->alert($message)
640
+
641
+ This will issue a warning from the file and line number of the context.
642
+
643
+ =item $stack = $ctx->stack()
644
+
645
+ This will return the L<Test2::API::Stack> instance the context used to find
646
+ the current hub.
647
+
648
+ =item $hub = $ctx->hub()
649
+
650
+ This will return the L<Test2::Hub> instance the context recognizes as the
651
+ current one to which all events should be sent.
652
+
653
+ =item $dbg = $ctx->trace()
654
+
655
+ This will return the L<Test2::EventFacet::Trace> instance used by the context.
656
+
657
+ =item $ctx->do_in_context(\&code, @args);
658
+
659
+ Sometimes you have a context that is not current, and you want things to use it
660
+ as the current one. In these cases you can call
661
+ C<< $ctx->do_in_context(sub { ... }) >>. The codeblock will be run, and
662
+ anything inside of it that looks for a context will find the one on which the
663
+ method was called.
664
+
665
+ This B<DOES NOT> affect context on other hubs, only the hub used by the context
666
+ will be affected.
667
+
668
+ my $ctx = ...;
669
+ $ctx->do_in_context(sub {
670
+ my $ctx = context(); # returns the $ctx the sub is called on
671
+ });
672
+
673
+ B<Note:> The context will actually be cloned, the clone will be used instead of
674
+ the original. This allows the thread id, process id, and error variables to be correct without
675
+ modifying the original context.
676
+
677
+ =item $ctx->restore_error_vars()
678
+
679
+ This will set C<$!>, C<$?>, and C<$@> to what they were when the context was
680
+ created. There is no localization or anything done here, calling this method
681
+ will actually set these vars.
682
+
683
+ =item $! = $ctx->errno()
684
+
685
+ The (numeric) value of C<$!> when the context was created.
686
+
687
+ =item $? = $ctx->child_error()
688
+
689
+ The value of C<$?> when the context was created.
690
+
691
+ =item $@ = $ctx->eval_error()
692
+
693
+ The value of C<$@> when the context was created.
694
+
695
+ =back
696
+
697
+ =head2 EVENT PRODUCTION METHODS
698
+
699
+ B<Which one do I use?>
700
+
701
+ The C<pass*> and C<fail*> are optimal if they meet your situation, using one of
702
+ them will always be the most optimal. That said they are optimal by eliminating
703
+ many features.
704
+
705
+ Method such as C<ok>, and C<note> are shortcuts for generating common 1-task
706
+ events based on the old API, however they are forward compatible, and easy to
707
+ use. If these meet your needs then go ahead and use them, but please check back
708
+ often for alternatives that may be added.
709
+
710
+ If you want to generate new style events, events that do many things at once,
711
+ then you want the C<*ev2*> methods. These let you directly specify which facets
712
+ you wish to use.
713
+
714
+ =over 4
715
+
716
+ =item $event = $ctx->pass()
717
+
718
+ =item $event = $ctx->pass($name)
719
+
720
+ This will send and return an L<Test2::Event::Pass> event. You may optionally
721
+ provide a C<$name> for the assertion.
722
+
723
+ The L<Test2::Event::Pass> is a specially crafted and optimized event, using
724
+ this will help the performance of passing tests.
725
+
726
+ =item $true = $ctx->pass_and_release()
727
+
728
+ =item $true = $ctx->pass_and_release($name)
729
+
730
+ This is a combination of C<pass()> and C<release()>. You can use this if you do
731
+ not plan to do anything with the context after sending the event. This helps
732
+ write more clear and compact code.
733
+
734
+ sub shorthand {
735
+ my ($bool, $name) = @_;
736
+ my $ctx = context();
737
+ return $ctx->pass_and_release($name) if $bool;
738
+
739
+ ... Handle a failure ...
740
+ }
741
+
742
+ sub longform {
743
+ my ($bool, $name) = @_;
744
+ my $ctx = context();
745
+
746
+ if ($bool) {
747
+ $ctx->pass($name);
748
+ $ctx->release;
749
+ return 1;
750
+ }
751
+
752
+ ... Handle a failure ...
753
+ }
754
+
755
+ =item my $event = $ctx->fail()
756
+
757
+ =item my $event = $ctx->fail($name)
758
+
759
+ =item my $event = $ctx->fail($name, @diagnostics)
760
+
761
+ This lets you send an L<Test2::Event::Fail> event. You may optionally provide a
762
+ C<$name> and C<@diagnostics> messages.
763
+
764
+ Diagnostics messages can be simple strings, data structures, or instances of
765
+ L<Test2::EventFacet::Info::Table> (which are converted inline into the
766
+ L<Test2::EventFacet::Info> structure).
767
+
768
+ =item my $false = $ctx->fail_and_release()
769
+
770
+ =item my $false = $ctx->fail_and_release($name)
771
+
772
+ =item my $false = $ctx->fail_and_release($name, @diagnostics)
773
+
774
+ This is a combination of C<fail()> and C<release()>. This can be used to write
775
+ clearer and shorter code.
776
+
777
+ sub shorthand {
778
+ my ($bool, $name) = @_;
779
+ my $ctx = context();
780
+ return $ctx->fail_and_release($name) unless $bool;
781
+
782
+ ... Handle a success ...
783
+ }
784
+
785
+ sub longform {
786
+ my ($bool, $name) = @_;
787
+ my $ctx = context();
788
+
789
+ unless ($bool) {
790
+ $ctx->pass($name);
791
+ $ctx->release;
792
+ return 1;
793
+ }
794
+
795
+ ... Handle a success ...
796
+ }
797
+
798
+
799
+ =item $event = $ctx->ok($bool, $name)
800
+
801
+ =item $event = $ctx->ok($bool, $name, \@on_fail)
802
+
803
+ B<NOTE:> Use of this method is discouraged in favor of C<pass()> and C<fail()>
804
+ which produce L<Test2::Event::Pass> and L<Test2::Event::Fail> events. These
805
+ newer event types are faster and less crufty.
806
+
807
+ This will create an L<Test2::Event::Ok> object for you. If C<$bool> is false
808
+ then an L<Test2::Event::Diag> event will be sent as well with details about the
809
+ failure. If you do not want automatic diagnostics you should use the
810
+ C<send_event()> method directly.
811
+
812
+ The third argument C<\@on_fail>) is an optional set of diagnostics to be sent in
813
+ the event of a test failure. Unlike with C<fail()> these diagnostics must be
814
+ plain strings, data structures are not supported.
815
+
816
+ =item $event = $ctx->note($message)
817
+
818
+ Send an L<Test2::Event::Note>. This event prints a message to STDOUT.
819
+
820
+ =item $event = $ctx->diag($message)
821
+
822
+ Send an L<Test2::Event::Diag>. This event prints a message to STDERR.
823
+
824
+ =item $event = $ctx->plan($max)
825
+
826
+ =item $event = $ctx->plan(0, 'SKIP', $reason)
827
+
828
+ This can be used to send an L<Test2::Event::Plan> event. This event
829
+ usually takes either a number of tests you expect to run. Optionally you can
830
+ set the expected count to 0 and give the 'SKIP' directive with a reason to
831
+ cause all tests to be skipped.
832
+
833
+ =item $event = $ctx->skip($name, $reason);
834
+
835
+ Send an L<Test2::Event::Skip> event.
836
+
837
+ =item $event = $ctx->bail($reason)
838
+
839
+ This sends an L<Test2::Event::Bail> event. This event will completely
840
+ terminate all testing.
841
+
842
+ =item $event = $ctx->send_ev2(%facets)
843
+
844
+ This lets you build and send a V2 event directly from facets. The event is
845
+ returned after it is sent.
846
+
847
+ This example sends a single assertion, a note (comment for stdout in
848
+ Test::Builder talk) and sets the plan to 1.
849
+
850
+ my $event = $ctx->send_event(
851
+ plan => {count => 1},
852
+ assert => {pass => 1, details => "A passing assert"},
853
+ info => [{tag => 'NOTE', details => "This is a note"}],
854
+ );
855
+
856
+ =item $event = $ctx->build_e2(%facets)
857
+
858
+ This is the same as C<send_ev2()>, except it builds and returns the event
859
+ without sending it.
860
+
861
+ =item $event = $ctx->send_ev2_and_release($Type, %parameters)
862
+
863
+ This is a combination of C<send_ev2()> and C<release()>.
864
+
865
+ sub shorthand {
866
+ my $ctx = context();
867
+ return $ctx->send_ev2_and_release(assert => {pass => 1, details => 'foo'});
868
+ }
869
+
870
+ sub longform {
871
+ my $ctx = context();
872
+ my $event = $ctx->send_ev2(assert => {pass => 1, details => 'foo'});
873
+ $ctx->release;
874
+ return $event;
875
+ }
876
+
877
+ =item $event = $ctx->send_event($Type, %parameters)
878
+
879
+ B<It is better to use send_ev2() in new code.>
880
+
881
+ This lets you build and send an event of any type. The C<$Type> argument should
882
+ be the event package name with C<Test2::Event::> left off, or a fully
883
+ qualified package name prefixed with a '+'. The event is returned after it is
884
+ sent.
885
+
886
+ my $event = $ctx->send_event('Ok', ...);
887
+
888
+ or
889
+
890
+ my $event = $ctx->send_event('+Test2::Event::Ok', ...);
891
+
892
+ =item $event = $ctx->build_event($Type, %parameters)
893
+
894
+ B<It is better to use build_ev2() in new code.>
895
+
896
+ This is the same as C<send_event()>, except it builds and returns the event
897
+ without sending it.
898
+
899
+ =item $event = $ctx->send_event_and_release($Type, %parameters)
900
+
901
+ B<It is better to use send_ev2_and_release() in new code.>
902
+
903
+ This is a combination of C<send_event()> and C<release()>.
904
+
905
+ sub shorthand {
906
+ my $ctx = context();
907
+ return $ctx->send_event_and_release(Pass => { name => 'foo' });
908
+ }
909
+
910
+ sub longform {
911
+ my $ctx = context();
912
+ my $event = $ctx->send_event(Pass => { name => 'foo' });
913
+ $ctx->release;
914
+ return $event;
915
+ }
916
+
917
+ =back
918
+
919
+ =head1 HOOKS
920
+
921
+ There are 2 types of hooks, init hooks, and release hooks. As the names
922
+ suggest, these hooks are triggered when contexts are created or released.
923
+
924
+ =head2 INIT HOOKS
925
+
926
+ These are called whenever a context is initialized. That means when a new
927
+ instance is created. These hooks are B<NOT> called every time something
928
+ requests a context, just when a new one is created.
929
+
930
+ =head3 GLOBAL
931
+
932
+ This is how you add a global init callback. Global callbacks happen for every
933
+ context for any hub or stack.
934
+
935
+ Test2::API::test2_add_callback_context_init(sub {
936
+ my $ctx = shift;
937
+ ...
938
+ });
939
+
940
+ =head3 PER HUB
941
+
942
+ This is how you add an init callback for all contexts created for a given hub.
943
+ These callbacks will not run for other hubs.
944
+
945
+ $hub->add_context_init(sub {
946
+ my $ctx = shift;
947
+ ...
948
+ });
949
+
950
+ =head3 PER CONTEXT
951
+
952
+ This is how you specify an init hook that will only run if your call to
953
+ C<context()> generates a new context. The callback will be ignored if
954
+ C<context()> is returning an existing context.
955
+
956
+ my $ctx = context(on_init => sub {
957
+ my $ctx = shift;
958
+ ...
959
+ });
960
+
961
+ =head2 RELEASE HOOKS
962
+
963
+ These are called whenever a context is released. That means when the last
964
+ reference to the instance is about to be destroyed. These hooks are B<NOT>
965
+ called every time C<< $ctx->release >> is called.
966
+
967
+ =head3 GLOBAL
968
+
969
+ This is how you add a global release callback. Global callbacks happen for every
970
+ context for any hub or stack.
971
+
972
+ Test2::API::test2_add_callback_context_release(sub {
973
+ my $ctx = shift;
974
+ ...
975
+ });
976
+
977
+ =head3 PER HUB
978
+
979
+ This is how you add a release callback for all contexts created for a given
980
+ hub. These callbacks will not run for other hubs.
981
+
982
+ $hub->add_context_release(sub {
983
+ my $ctx = shift;
984
+ ...
985
+ });
986
+
987
+ =head3 PER CONTEXT
988
+
989
+ This is how you add release callbacks directly to a context. The callback will
990
+ B<ALWAYS> be added to the context that gets returned, it does not matter if a
991
+ new one is generated, or if an existing one is returned.
992
+
993
+ my $ctx = context(on_release => sub {
994
+ my $ctx = shift;
995
+ ...
996
+ });
997
+
998
+ =head1 THIRD PARTY META-DATA
999
+
1000
+ This object consumes L<Test2::Util::ExternalMeta> which provides a consistent
1001
+ way for you to attach meta-data to instances of this class. This is useful for
1002
+ tools, plugins, and other extensions.
1003
+
1004
+ =head1 SOURCE
1005
+
1006
+ The source code repository for Test2 can be found at
1007
+ L<https://github.com/Test-More/test-more/>.
1008
+
1009
+ =head1 MAINTAINERS
1010
+
1011
+ =over 4
1012
+
1013
+ =item Chad Granum E<lt>exodist@cpan.orgE<gt>
1014
+
1015
+ =back
1016
+
1017
+ =head1 AUTHORS
1018
+
1019
+ =over 4
1020
+
1021
+ =item Chad Granum E<lt>exodist@cpan.orgE<gt>
1022
+
1023
+ =item Kent Fredric E<lt>kentnl@cpan.orgE<gt>
1024
+
1025
+ =back
1026
+
1027
+ =head1 COPYRIGHT
1028
+
1029
+ Copyright Chad Granum E<lt>exodist@cpan.orgE<gt>.
1030
+
1031
+ This program is free software; you can redistribute it and/or
1032
+ modify it under the same terms as Perl itself.
1033
+
1034
+ See L<https://dev.perl.org/licenses/>
1035
+
1036
+ =cut
git/usr/share/perl5/core_perl/Test2/API/Instance.pm ADDED
@@ -0,0 +1,830 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package Test2::API::Instance;
2
+ use strict;
3
+ use warnings;
4
+
5
+ our $VERSION = '1.302210';
6
+
7
+ our @CARP_NOT = qw/Test2::API Test2::API::Instance Test2::IPC::Driver Test2::Formatter/;
8
+ use Carp qw/confess carp/;
9
+ use Scalar::Util qw/reftype/;
10
+
11
+ use Test2::Util qw/get_tid USE_THREADS CAN_FORK pkg_to_file try/;
12
+
13
+ use Test2::EventFacet::Trace();
14
+ use Test2::API::Stack();
15
+
16
+ use Test2::Util::HashBase qw{
17
+ _pid _tid
18
+ no_wait
19
+ finalized loaded
20
+ ipc stack formatter
21
+ contexts
22
+
23
+ add_uuid_via
24
+
25
+ -preload
26
+
27
+ ipc_disabled
28
+ ipc_polling
29
+ ipc_drivers
30
+ ipc_timeout
31
+ formatters
32
+
33
+ exit_callbacks
34
+ post_load_callbacks
35
+ context_acquire_callbacks
36
+ context_init_callbacks
37
+ context_release_callbacks
38
+ pre_subtest_callbacks
39
+
40
+ trace_stamps
41
+ };
42
+
43
+ sub DEFAULT_IPC_TIMEOUT() { 30 }
44
+
45
+ sub test2_enable_trace_stamps { $_[0]->{+TRACE_STAMPS} = 1 }
46
+ sub test2_disable_trace_stamps { $_[0]->{+TRACE_STAMPS} = 0 }
47
+ sub test2_trace_stamps_enabled { $_[0]->{+TRACE_STAMPS} }
48
+
49
+ sub pid { $_[0]->{+_PID} }
50
+ sub tid { $_[0]->{+_TID} }
51
+
52
+ # Wrap around the getters that should call _finalize.
53
+ BEGIN {
54
+ for my $finalizer (IPC, FORMATTER) {
55
+ my $orig = __PACKAGE__->can($finalizer);
56
+ my $new = sub {
57
+ my $self = shift;
58
+ $self->_finalize unless $self->{+FINALIZED};
59
+ $self->$orig;
60
+ };
61
+
62
+ no strict 'refs';
63
+ no warnings 'redefine';
64
+ *{$finalizer} = $new;
65
+ }
66
+ }
67
+
68
+ sub has_ipc { !!$_[0]->{+IPC} }
69
+
70
+ sub import {
71
+ my $class = shift;
72
+ return unless @_;
73
+ my ($ref) = @_;
74
+ $$ref = $class->new;
75
+ }
76
+
77
+ sub init { $_[0]->reset }
78
+
79
+ sub start_preload {
80
+ my $self = shift;
81
+
82
+ confess "preload cannot be started, Test2::API has already been initialized"
83
+ if $self->{+FINALIZED} || $self->{+LOADED};
84
+
85
+ return $self->{+PRELOAD} = 1;
86
+ }
87
+
88
+ sub stop_preload {
89
+ my $self = shift;
90
+
91
+ return 0 unless $self->{+PRELOAD};
92
+ $self->{+PRELOAD} = 0;
93
+
94
+ $self->post_preload_reset();
95
+
96
+ return 1;
97
+ }
98
+
99
+ sub post_preload_reset {
100
+ my $self = shift;
101
+
102
+ delete $self->{+_PID};
103
+ delete $self->{+_TID};
104
+
105
+ $self->{+ADD_UUID_VIA} = undef unless exists $self->{+ADD_UUID_VIA};
106
+
107
+ $self->{+CONTEXTS} = {};
108
+
109
+ $self->{+FORMATTERS} = [];
110
+
111
+ $self->{+FINALIZED} = undef;
112
+ $self->{+IPC} = undef;
113
+ $self->{+IPC_DISABLED} = $ENV{T2_NO_IPC} ? 1 : 0;
114
+
115
+ $self->{+IPC_TIMEOUT} = DEFAULT_IPC_TIMEOUT() unless defined $self->{+IPC_TIMEOUT};
116
+
117
+ $self->{+LOADED} = 0;
118
+
119
+ $self->{+STACK} ||= Test2::API::Stack->new;
120
+ }
121
+
122
+ sub reset {
123
+ my $self = shift;
124
+
125
+ delete $self->{+_PID};
126
+ delete $self->{+_TID};
127
+
128
+ $self->{+TRACE_STAMPS} = $ENV{T2_TRACE_STAMPS} || 0;
129
+
130
+ $self->{+ADD_UUID_VIA} = undef;
131
+
132
+ $self->{+CONTEXTS} = {};
133
+
134
+ $self->{+IPC_DRIVERS} = [];
135
+ $self->{+IPC_POLLING} = undef;
136
+
137
+ $self->{+FORMATTERS} = [];
138
+ $self->{+FORMATTER} = undef;
139
+
140
+ $self->{+FINALIZED} = undef;
141
+ $self->{+IPC} = undef;
142
+ $self->{+IPC_DISABLED} = $ENV{T2_NO_IPC} ? 1 : 0;
143
+
144
+ $self->{+IPC_TIMEOUT} = DEFAULT_IPC_TIMEOUT() unless defined $self->{+IPC_TIMEOUT};
145
+
146
+ $self->{+NO_WAIT} = 0;
147
+ $self->{+LOADED} = 0;
148
+
149
+ $self->{+EXIT_CALLBACKS} = [];
150
+ $self->{+POST_LOAD_CALLBACKS} = [];
151
+ $self->{+CONTEXT_ACQUIRE_CALLBACKS} = [];
152
+ $self->{+CONTEXT_INIT_CALLBACKS} = [];
153
+ $self->{+CONTEXT_RELEASE_CALLBACKS} = [];
154
+ $self->{+PRE_SUBTEST_CALLBACKS} = [];
155
+
156
+ $self->{+STACK} = Test2::API::Stack->new;
157
+ }
158
+
159
+ sub _finalize {
160
+ my $self = shift;
161
+ my ($caller) = @_;
162
+ $caller ||= [caller(1)];
163
+
164
+ confess "Attempt to initialize Test2::API during preload"
165
+ if $self->{+PRELOAD};
166
+
167
+ $self->{+FINALIZED} = $caller;
168
+
169
+ $self->{+_PID} = $$ unless defined $self->{+_PID};
170
+ $self->{+_TID} = get_tid() unless defined $self->{+_TID};
171
+
172
+ unless ($self->{+FORMATTER}) {
173
+ my ($formatter, $source);
174
+ if ($ENV{T2_FORMATTER}) {
175
+ $source = "set by the 'T2_FORMATTER' environment variable";
176
+
177
+ if ($ENV{T2_FORMATTER} =~ m/^(\+)?(.*)$/) {
178
+ $formatter = $1 ? $2 : "Test2::Formatter::$2"
179
+ }
180
+ else {
181
+ $formatter = '';
182
+ }
183
+ }
184
+ elsif (@{$self->{+FORMATTERS}}) {
185
+ ($formatter) = @{$self->{+FORMATTERS}};
186
+ $source = "Most recently added";
187
+ }
188
+ else {
189
+ $formatter = 'Test2::Formatter::TAP';
190
+ $source = 'default formatter';
191
+ }
192
+
193
+ unless (ref($formatter) || $formatter->can('write')) {
194
+ my $file = pkg_to_file($formatter);
195
+ my ($ok, $err) = try { require $file };
196
+ unless ($ok) {
197
+ my $line = "* COULD NOT LOAD FORMATTER '$formatter' ($source) *";
198
+ my $border = '*' x length($line);
199
+ die "\n\n $border\n $line\n $border\n\n$err";
200
+ }
201
+ }
202
+
203
+ $self->{+FORMATTER} = $formatter;
204
+ }
205
+
206
+ # Turn on IPC if threads are on, drivers are registered, or the Test2::IPC
207
+ # module is loaded.
208
+ return if $self->{+IPC_DISABLED};
209
+ return unless USE_THREADS || $INC{'Test2/IPC.pm'} || @{$self->{+IPC_DRIVERS}};
210
+
211
+ # Turn on polling by default, people expect it.
212
+ $self->enable_ipc_polling;
213
+
214
+ unless (@{$self->{+IPC_DRIVERS}}) {
215
+ my ($ok, $error) = try { require Test2::IPC::Driver::Files };
216
+ die $error unless $ok;
217
+ push @{$self->{+IPC_DRIVERS}} => 'Test2::IPC::Driver::Files';
218
+ }
219
+
220
+ for my $driver (@{$self->{+IPC_DRIVERS}}) {
221
+ next unless $driver->can('is_viable') && $driver->is_viable;
222
+ $self->{+IPC} = $driver->new or next;
223
+ return;
224
+ }
225
+
226
+ die "IPC has been requested, but no viable drivers were found. Aborting...\n";
227
+ }
228
+
229
+ sub formatter_set { $_[0]->{+FORMATTER} ? 1 : 0 }
230
+
231
+ sub add_formatter {
232
+ my $self = shift;
233
+ my ($formatter) = @_;
234
+ unshift @{$self->{+FORMATTERS}} => $formatter;
235
+
236
+ return unless $self->{+FINALIZED};
237
+
238
+ # Why is the @CARP_NOT entry not enough?
239
+ local %Carp::Internal = %Carp::Internal;
240
+ $Carp::Internal{'Test2::Formatter'} = 1;
241
+
242
+ carp "Formatter $formatter loaded too late to be used as the global formatter";
243
+ }
244
+
245
+ sub add_context_acquire_callback {
246
+ my $self = shift;
247
+ my ($code) = @_;
248
+
249
+ my $rtype = reftype($code) || "";
250
+
251
+ confess "Context-acquire callbacks must be coderefs"
252
+ unless $code && $rtype eq 'CODE';
253
+
254
+ push @{$self->{+CONTEXT_ACQUIRE_CALLBACKS}} => $code;
255
+ }
256
+
257
+ sub add_context_init_callback {
258
+ my $self = shift;
259
+ my ($code) = @_;
260
+
261
+ my $rtype = reftype($code) || "";
262
+
263
+ confess "Context-init callbacks must be coderefs"
264
+ unless $code && $rtype eq 'CODE';
265
+
266
+ push @{$self->{+CONTEXT_INIT_CALLBACKS}} => $code;
267
+ }
268
+
269
+ sub add_context_release_callback {
270
+ my $self = shift;
271
+ my ($code) = @_;
272
+
273
+ my $rtype = reftype($code) || "";
274
+
275
+ confess "Context-release callbacks must be coderefs"
276
+ unless $code && $rtype eq 'CODE';
277
+
278
+ push @{$self->{+CONTEXT_RELEASE_CALLBACKS}} => $code;
279
+ }
280
+
281
+ sub add_post_load_callback {
282
+ my $self = shift;
283
+ my ($code) = @_;
284
+
285
+ my $rtype = reftype($code) || "";
286
+
287
+ confess "Post-load callbacks must be coderefs"
288
+ unless $code && $rtype eq 'CODE';
289
+
290
+ push @{$self->{+POST_LOAD_CALLBACKS}} => $code;
291
+ $code->() if $self->{+LOADED};
292
+ }
293
+
294
+ sub add_pre_subtest_callback {
295
+ my $self = shift;
296
+ my ($code) = @_;
297
+
298
+ my $rtype = reftype($code) || "";
299
+
300
+ confess "Pre-subtest callbacks must be coderefs"
301
+ unless $code && $rtype eq 'CODE';
302
+
303
+ push @{$self->{+PRE_SUBTEST_CALLBACKS}} => $code;
304
+ }
305
+
306
+ sub load {
307
+ my $self = shift;
308
+ unless ($self->{+LOADED}) {
309
+ confess "Attempt to initialize Test2::API during preload"
310
+ if $self->{+PRELOAD};
311
+
312
+ $self->{+_PID} = $$ unless defined $self->{+_PID};
313
+ $self->{+_TID} = get_tid() unless defined $self->{+_TID};
314
+
315
+ # This is for https://github.com/Test-More/test-more/issues/16
316
+ # and https://rt.perl.org/Public/Bug/Display.html?id=127774
317
+ # END blocks run in reverse order. This insures the END block is loaded
318
+ # as late as possible. It will not solve all cases, but it helps.
319
+ eval "END { Test2::API::test2_set_is_end() }; 1" or die $@;
320
+
321
+ $self->{+LOADED} = 1;
322
+ $_->() for @{$self->{+POST_LOAD_CALLBACKS}};
323
+ }
324
+ return $self->{+LOADED};
325
+ }
326
+
327
+ sub add_exit_callback {
328
+ my $self = shift;
329
+ my ($code) = @_;
330
+ my $rtype = reftype($code) || "";
331
+
332
+ confess "End callbacks must be coderefs"
333
+ unless $code && $rtype eq 'CODE';
334
+
335
+ push @{$self->{+EXIT_CALLBACKS}} => $code;
336
+ }
337
+
338
+ sub ipc_disable {
339
+ my $self = shift;
340
+
341
+ confess "Attempt to disable IPC after it has been initialized"
342
+ if $self->{+IPC};
343
+
344
+ $self->{+IPC_DISABLED} = 1;
345
+ }
346
+
347
+ sub add_ipc_driver {
348
+ my $self = shift;
349
+ my ($driver) = @_;
350
+ unshift @{$self->{+IPC_DRIVERS}} => $driver;
351
+
352
+ return unless $self->{+FINALIZED};
353
+
354
+ # Why is the @CARP_NOT entry not enough?
355
+ local %Carp::Internal = %Carp::Internal;
356
+ $Carp::Internal{'Test2::IPC::Driver'} = 1;
357
+
358
+ carp "IPC driver $driver loaded too late to be used as the global ipc driver";
359
+ }
360
+
361
+ sub enable_ipc_polling {
362
+ my $self = shift;
363
+
364
+ $self->{+_PID} = $$ unless defined $self->{+_PID};
365
+ $self->{+_TID} = get_tid() unless defined $self->{+_TID};
366
+
367
+ $self->add_context_init_callback(
368
+ # This is called every time a context is created, it needs to be fast.
369
+ # $_[0] is a context object
370
+ sub {
371
+ return unless $self->{+IPC_POLLING};
372
+ return unless $self->{+IPC};
373
+ return unless $self->{+IPC}->pending();
374
+ return $_[0]->{hub}->cull;
375
+ }
376
+ ) unless defined $self->ipc_polling;
377
+
378
+ $self->set_ipc_polling(1);
379
+ }
380
+
381
+ sub get_ipc_pending {
382
+ my $self = shift;
383
+ return -1 unless $self->{+IPC};
384
+ $self->{+IPC}->pending();
385
+ }
386
+
387
+ sub _check_pid {
388
+ my $self = shift;
389
+ my ($pid) = @_;
390
+ return kill(0, $pid);
391
+ }
392
+
393
+ sub set_ipc_pending {
394
+ my $self = shift;
395
+ return unless $self->{+IPC};
396
+ my ($val) = @_;
397
+
398
+ confess "value is required for set_ipc_pending"
399
+ unless $val;
400
+
401
+ $self->{+IPC}->set_pending($val);
402
+ }
403
+
404
+ sub disable_ipc_polling {
405
+ my $self = shift;
406
+ return unless defined $self->{+IPC_POLLING};
407
+ $self->{+IPC_POLLING} = 0;
408
+ }
409
+
410
+ sub _ipc_wait {
411
+ my ($timeout) = @_;
412
+ my $fail = 0;
413
+
414
+ $timeout = DEFAULT_IPC_TIMEOUT() unless defined $timeout;
415
+
416
+ my $ok = eval {
417
+ if (CAN_FORK) {
418
+ local $SIG{ALRM} = sub { die "Timeout waiting on child processes" };
419
+ alarm $timeout;
420
+
421
+ while (1) {
422
+ my $pid = CORE::wait();
423
+ my $err = $?;
424
+ last if $pid == -1;
425
+ next unless $err;
426
+ $fail++;
427
+
428
+ my $sig = $err & 127;
429
+ my $exit = $err >> 8;
430
+ warn "Process $pid did not exit cleanly (wstat: $err, exit: $exit, sig: $sig)\n";
431
+ }
432
+
433
+ alarm 0;
434
+ }
435
+
436
+ if (USE_THREADS) {
437
+ my $start = time;
438
+
439
+ while (1) {
440
+ last unless threads->list();
441
+ die "Timeout waiting on child thread" if time - $start >= $timeout;
442
+ sleep 1;
443
+ for my $t (threads->list) {
444
+ # threads older than 1.34 do not have this :-(
445
+ next if $t->can('is_joinable') && !$t->is_joinable;
446
+ $t->join;
447
+ # In older threads we cannot check if a thread had an error unless
448
+ # we control it and its return.
449
+ my $err = $t->can('error') ? $t->error : undef;
450
+ next unless $err;
451
+ my $tid = $t->tid();
452
+ $fail++;
453
+ chomp($err);
454
+ warn "Thread $tid did not end cleanly: $err\n";
455
+ }
456
+ }
457
+ }
458
+
459
+ 1;
460
+ };
461
+ my $error = $@;
462
+
463
+ return 0 if $ok && !$fail;
464
+ warn $error unless $ok;
465
+ return 255;
466
+ }
467
+
468
+ sub set_exit {
469
+ my $self = shift;
470
+
471
+ return if $self->{+PRELOAD};
472
+
473
+ my $exit = $?;
474
+ my $new_exit = $exit;
475
+
476
+ if ($INC{'Test/Builder.pm'} && $Test::Builder::VERSION ne $Test2::API::VERSION) {
477
+ print STDERR <<" EOT";
478
+
479
+ ********************************************************************************
480
+ * *
481
+ * Test::Builder -- Test2::API version mismatch detected *
482
+ * *
483
+ ********************************************************************************
484
+ Test2::API Version: $Test2::API::VERSION
485
+ Test::Builder Version: $Test::Builder::VERSION
486
+
487
+ This is not a supported configuration, you will have problems.
488
+
489
+ EOT
490
+ }
491
+
492
+ for my $ctx (values %{$self->{+CONTEXTS}}) {
493
+ next unless $ctx;
494
+
495
+ next if $ctx->_aborted && ${$ctx->_aborted};
496
+
497
+ # Only worry about contexts in this PID
498
+ my $trace = $ctx->trace || next;
499
+ next unless $trace->pid && $trace->pid == $$;
500
+
501
+ # Do not worry about contexts that have no hub
502
+ my $hub = $ctx->hub || next;
503
+
504
+ # Do not worry if the state came to a sudden end.
505
+ next if $hub->bailed_out;
506
+ next if defined $hub->skip_reason;
507
+
508
+ # now we worry
509
+ $trace->alert("context object was never released! This means a testing tool is behaving very badly");
510
+
511
+ $exit = 255;
512
+ $new_exit = 255;
513
+ }
514
+
515
+ if (!defined($self->{+_PID}) or !defined($self->{+_TID}) or $self->{+_PID} != $$ or $self->{+_TID} != get_tid()) {
516
+ $? = $exit;
517
+ return;
518
+ }
519
+
520
+ my @hubs = $self->{+STACK} ? $self->{+STACK}->all : ();
521
+
522
+ if (@hubs and $self->{+IPC} and !$self->{+NO_WAIT}) {
523
+ local $?;
524
+ my %seen;
525
+ for my $hub (reverse @hubs) {
526
+ my $ipc = $hub->ipc or next;
527
+ next if $seen{$ipc}++;
528
+ $ipc->waiting();
529
+ }
530
+
531
+ my $ipc_exit = _ipc_wait($self->{+IPC_TIMEOUT});
532
+ $new_exit ||= $ipc_exit;
533
+ }
534
+
535
+ # None of this is necessary if we never got a root hub
536
+ if(my $root = shift @hubs) {
537
+ my $trace = Test2::EventFacet::Trace->new(
538
+ frame => [__PACKAGE__, __FILE__, 0, __PACKAGE__ . '::END'],
539
+ detail => __PACKAGE__ . ' END Block finalization',
540
+ );
541
+ my $ctx = Test2::API::Context->new(
542
+ trace => $trace,
543
+ hub => $root,
544
+ );
545
+
546
+ if (@hubs) {
547
+ $ctx->diag("Test ended with extra hubs on the stack!");
548
+ $new_exit = 255;
549
+ }
550
+
551
+ unless ($root->no_ending) {
552
+ local $?;
553
+ $root->finalize($trace) unless $root->ended;
554
+ $_->($ctx, $exit, \$new_exit) for @{$self->{+EXIT_CALLBACKS}};
555
+ $new_exit ||= $root->failed;
556
+ $new_exit ||= 255 unless $root->is_passing;
557
+ }
558
+ }
559
+
560
+ $new_exit = 255 if $new_exit > 255;
561
+
562
+ if ($new_exit && eval { require Test2::API::Breakage; 1 }) {
563
+ my @warn = Test2::API::Breakage->report();
564
+
565
+ if (@warn) {
566
+ print STDERR "\nYou have loaded versions of test modules known to have problems with Test2.\nThis could explain some test failures.\n";
567
+ print STDERR "$_\n" for @warn;
568
+ print STDERR "\n";
569
+ }
570
+ }
571
+
572
+ $? = $new_exit;
573
+ }
574
+
575
+ 1;
576
+
577
+ __END__
578
+
579
+ =pod
580
+
581
+ =encoding UTF-8
582
+
583
+ =head1 NAME
584
+
585
+ Test2::API::Instance - Object used by Test2::API under the hood
586
+
587
+ =head1 DESCRIPTION
588
+
589
+ This object encapsulates the global shared state tracked by
590
+ L<Test2>. A single global instance of this package is stored (and
591
+ obscured) by the L<Test2::API> package.
592
+
593
+ There is no reason to directly use this package. This package is documented for
594
+ completeness. This package can change, or go away completely at any time.
595
+ Directly using, or monkeypatching this package is not supported in any way
596
+ shape or form.
597
+
598
+ =head1 SYNOPSIS
599
+
600
+ use Test2::API::Instance;
601
+
602
+ my $obj = Test2::API::Instance->new;
603
+
604
+ =over 4
605
+
606
+ =item $pid = $obj->pid
607
+
608
+ PID of this instance.
609
+
610
+ =item $obj->tid
611
+
612
+ Thread ID of this instance.
613
+
614
+ =item $obj->reset()
615
+
616
+ Reset the object to defaults.
617
+
618
+ =item $obj->load()
619
+
620
+ Set the internal state to loaded, and run and stored post-load callbacks.
621
+
622
+ =item $bool = $obj->loaded
623
+
624
+ Check if the state is set to loaded.
625
+
626
+ =item $arrayref = $obj->post_load_callbacks
627
+
628
+ Get the post-load callbacks.
629
+
630
+ =item $obj->add_post_load_callback(sub { ... })
631
+
632
+ Add a post-load callback. If C<load()> has already been called then the callback will
633
+ be immediately executed. If C<load()> has not been called then the callback will be
634
+ stored and executed later when C<load()> is called.
635
+
636
+ =item $hashref = $obj->contexts()
637
+
638
+ Get a hashref of all active contexts keyed by hub id.
639
+
640
+ =item $arrayref = $obj->context_acquire_callbacks
641
+
642
+ Get all context acquire callbacks.
643
+
644
+ =item $arrayref = $obj->context_init_callbacks
645
+
646
+ Get all context init callbacks.
647
+
648
+ =item $arrayref = $obj->context_release_callbacks
649
+
650
+ Get all context release callbacks.
651
+
652
+ =item $arrayref = $obj->pre_subtest_callbacks
653
+
654
+ Get all pre-subtest callbacks.
655
+
656
+ =item $obj->add_context_init_callback(sub { ... })
657
+
658
+ Add a context init callback. Subs are called every time a context is created. Subs
659
+ get the newly created context as their only argument.
660
+
661
+ =item $obj->add_context_release_callback(sub { ... })
662
+
663
+ Add a context release callback. Subs are called every time a context is released. Subs
664
+ get the released context as their only argument. These callbacks should not
665
+ call release on the context.
666
+
667
+ =item $obj->add_pre_subtest_callback(sub { ... })
668
+
669
+ Add a pre-subtest callback. Subs are called every time a subtest is
670
+ going to be run. Subs get the subtest name, coderef, and any
671
+ arguments.
672
+
673
+ =item $obj->set_exit()
674
+
675
+ This is intended to be called in an C<END { ... }> block. This will look at
676
+ test state and set $?. This will also call any end callbacks, and wait on child
677
+ processes/threads.
678
+
679
+ =item $obj->set_ipc_pending($val)
680
+
681
+ Tell other processes and threads there is a pending event. C<$val> should be a
682
+ unique value no other thread/process will generate.
683
+
684
+ B<Note:> This will also make the current process see a pending event.
685
+
686
+ =item $pending = $obj->get_ipc_pending()
687
+
688
+ This returns -1 if it is not possible to know.
689
+
690
+ This returns 0 if there are no pending events.
691
+
692
+ This returns 1 if there are pending events.
693
+
694
+ =item $timeout = $obj->ipc_timeout;
695
+
696
+ =item $obj->set_ipc_timeout($timeout);
697
+
698
+ How long to wait for child processes and threads before aborting.
699
+
700
+ =item $drivers = $obj->ipc_drivers
701
+
702
+ Get the list of IPC drivers.
703
+
704
+ =item $obj->add_ipc_driver($DRIVER_CLASS)
705
+
706
+ Add an IPC driver to the list. The most recently added IPC driver will become
707
+ the global one during initialization. If a driver is added after initialization
708
+ has occurred a warning will be generated:
709
+
710
+ "IPC driver $driver loaded too late to be used as the global ipc driver"
711
+
712
+ =item $bool = $obj->ipc_polling
713
+
714
+ Check if polling is enabled.
715
+
716
+ =item $obj->enable_ipc_polling
717
+
718
+ Turn on polling. This will cull events from other processes and threads every
719
+ time a context is created.
720
+
721
+ =item $obj->disable_ipc_polling
722
+
723
+ Turn off IPC polling.
724
+
725
+ =item $bool = $obj->no_wait
726
+
727
+ =item $bool = $obj->set_no_wait($bool)
728
+
729
+ Get/Set no_wait. This option is used to turn off process/thread waiting at exit.
730
+
731
+ =item $arrayref = $obj->exit_callbacks
732
+
733
+ Get the exit callbacks.
734
+
735
+ =item $obj->add_exit_callback(sub { ... })
736
+
737
+ Add an exit callback. This callback will be called by C<set_exit()>.
738
+
739
+ =item $bool = $obj->finalized
740
+
741
+ Check if the object is finalized. Finalization happens when either C<ipc()>,
742
+ C<stack()>, or C<format()> are called on the object. Once finalization happens
743
+ these fields are considered unchangeable (not enforced here, enforced by
744
+ L<Test2>).
745
+
746
+ =item $ipc = $obj->ipc
747
+
748
+ Get the one true IPC instance.
749
+
750
+ =item $obj->ipc_disable
751
+
752
+ Turn IPC off
753
+
754
+ =item $bool = $obj->ipc_disabled
755
+
756
+ Check if IPC is disabled
757
+
758
+ =item $stack = $obj->stack
759
+
760
+ Get the one true hub stack.
761
+
762
+ =item $formatter = $obj->formatter
763
+
764
+ Get the global formatter. By default this is the C<'Test2::Formatter::TAP'>
765
+ package. This could be any package that implements the C<write()> method. This
766
+ can also be an instantiated object.
767
+
768
+ =item $bool = $obj->formatter_set()
769
+
770
+ Check if a formatter has been set.
771
+
772
+ =item $obj->add_formatter($class)
773
+
774
+ =item $obj->add_formatter($obj)
775
+
776
+ Add a formatter. The most recently added formatter will become the global one
777
+ during initialization. If a formatter is added after initialization has occurred
778
+ a warning will be generated:
779
+
780
+ "Formatter $formatter loaded too late to be used as the global formatter"
781
+
782
+ =item $obj->set_add_uuid_via(sub { ... })
783
+
784
+ =item $sub = $obj->add_uuid_via()
785
+
786
+ This allows you to provide a UUID generator. If provided UUIDs will be attached
787
+ to all events, hubs, and contexts. This is useful for storing, tracking, and
788
+ linking these objects.
789
+
790
+ The sub you provide should always return a unique identifier. Most things will
791
+ expect a proper UUID string, however nothing in Test2::API enforces this.
792
+
793
+ The sub will receive exactly 1 argument, the type of thing being tagged
794
+ 'context', 'hub', or 'event'. In the future additional things may be tagged, in
795
+ which case new strings will be passed in. These are purely informative, you can
796
+ (and usually should) ignore them.
797
+
798
+ =back
799
+
800
+ =head1 SOURCE
801
+
802
+ The source code repository for Test2 can be found at
803
+ L<https://github.com/Test-More/test-more/>.
804
+
805
+ =head1 MAINTAINERS
806
+
807
+ =over 4
808
+
809
+ =item Chad Granum E<lt>exodist@cpan.orgE<gt>
810
+
811
+ =back
812
+
813
+ =head1 AUTHORS
814
+
815
+ =over 4
816
+
817
+ =item Chad Granum E<lt>exodist@cpan.orgE<gt>
818
+
819
+ =back
820
+
821
+ =head1 COPYRIGHT
822
+
823
+ Copyright Chad Granum E<lt>exodist@cpan.orgE<gt>.
824
+
825
+ This program is free software; you can redistribute it and/or
826
+ modify it under the same terms as Perl itself.
827
+
828
+ See L<https://dev.perl.org/licenses/>
829
+
830
+ =cut
git/usr/share/perl5/core_perl/Test2/API/InterceptResult.pm ADDED
@@ -0,0 +1,634 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package Test2::API::InterceptResult;
2
+ use strict;
3
+ use warnings;
4
+
5
+ our $VERSION = '1.302210';
6
+
7
+ use Scalar::Util qw/blessed/;
8
+ use Test2::Util qw/pkg_to_file/;
9
+ use Storable qw/dclone/;
10
+ use Carp qw/croak/;
11
+
12
+ use Test2::API::InterceptResult::Squasher;
13
+ use Test2::API::InterceptResult::Event;
14
+ use Test2::API::InterceptResult::Hub;
15
+
16
+ sub new {
17
+ croak "Called a method that creates a new instance in void context" unless defined wantarray;
18
+ my $class = shift;
19
+ bless([@_], $class);
20
+ }
21
+
22
+ sub new_from_ref {
23
+ croak "Called a method that creates a new instance in void context" unless defined wantarray;
24
+ bless($_[1], $_[0]);
25
+ }
26
+
27
+ sub clone { blessed($_[0])->new(@{dclone($_[0])}) }
28
+
29
+ sub event_list { @{$_[0]} }
30
+
31
+ sub _upgrade {
32
+ my $self = shift;
33
+ my ($event, %params) = @_;
34
+
35
+ my $blessed = blessed($event);
36
+
37
+ my $upgrade_class = $params{upgrade_class} ||= 'Test2::API::InterceptResult::Event';
38
+
39
+ return $event if $blessed && $event->isa($upgrade_class) && !$params{_upgrade_clone};
40
+
41
+ my $fd = dclone($blessed ? $event->facet_data : $event);
42
+
43
+ my $class = $params{result_class} ||= blessed($self);
44
+
45
+ if (my $parent = $fd->{parent}) {
46
+ $parent->{children} = $class->new_from_ref($parent->{children} || [])->upgrade(%params);
47
+ }
48
+
49
+ my $uc_file = pkg_to_file($upgrade_class);
50
+ require($uc_file) unless $INC{$uc_file};
51
+ return $upgrade_class->new(facet_data => $fd, result_class => $class);
52
+ }
53
+
54
+ sub hub {
55
+ my $self = shift;
56
+
57
+ my $hub = Test2::API::InterceptResult::Hub->new();
58
+ $hub->process($_) for @$self;
59
+ $hub->set_ended(1);
60
+
61
+ return $hub;
62
+ }
63
+
64
+ sub state {
65
+ my $self = shift;
66
+ my %params = @_;
67
+
68
+ my $hub = $self->hub;
69
+
70
+ my $out = {
71
+ map {($_ => scalar $hub->$_)} qw/count failed is_passing plan bailed_out skip_reason/
72
+ };
73
+
74
+ $out->{bailed_out} = $self->_upgrade($out->{bailed_out}, %params)->bailout_reason || 1
75
+ if $out->{bailed_out};
76
+
77
+ $out->{follows_plan} = $hub->check_plan;
78
+
79
+ return $out;
80
+ }
81
+
82
+ sub upgrade {
83
+ my $self = shift;
84
+ my %params = @_;
85
+
86
+ my @out = map { $self->_upgrade($_, %params, _upgrade_clone => 1) } @$self;
87
+
88
+ return blessed($self)->new_from_ref(\@out)
89
+ unless $params{in_place};
90
+
91
+ @$self = @out;
92
+ return $self;
93
+ }
94
+
95
+ sub squash_info {
96
+ my $self = shift;
97
+ my %params = @_;
98
+
99
+ my @out;
100
+
101
+ {
102
+ my $squasher = Test2::API::InterceptResult::Squasher->new(events => \@out);
103
+ # Clone to make sure we do not indirectly modify an existing one if it
104
+ # is already upgraded
105
+ $squasher->process($self->_upgrade($_, %params)->clone) for @$self;
106
+ $squasher->flush_down();
107
+ }
108
+
109
+ return blessed($self)->new_from_ref(\@out)
110
+ unless $params{in_place};
111
+
112
+ @$self = @out;
113
+ return $self;
114
+ }
115
+
116
+ sub asserts { shift->grep(has_assert => @_) }
117
+ sub subtests { shift->grep(has_subtest => @_) }
118
+ sub diags { shift->grep(has_diags => @_) }
119
+ sub notes { shift->grep(has_notes => @_) }
120
+ sub errors { shift->grep(has_errors => @_) }
121
+ sub plans { shift->grep(has_plan => @_) }
122
+ sub causes_fail { shift->grep(causes_fail => @_) }
123
+ sub causes_failure { shift->grep(causes_failure => @_) }
124
+
125
+ sub flatten { shift->map(flatten => @_) }
126
+ sub briefs { shift->map(brief => @_) }
127
+ sub summaries { shift->map(summary => @_) }
128
+ sub subtest_results { shift->map(subtest_result => @_) }
129
+ sub diag_messages { shift->map(diag_messages => @_) }
130
+ sub note_messages { shift->map(note_messages => @_) }
131
+ sub error_messages { shift->map(error_messages => @_) }
132
+
133
+ no warnings 'once';
134
+
135
+ *map = sub {
136
+ my $self = shift;
137
+ my ($call, %params) = @_;
138
+
139
+ my $args = $params{args} ||= [];
140
+
141
+ return [map { local $_ = $self->_upgrade($_, %params); $_->$call(@$args) } @$self];
142
+ };
143
+
144
+ *grep = sub {
145
+ my $self = shift;
146
+ my ($call, %params) = @_;
147
+
148
+ my $args = $params{args} ||= [];
149
+
150
+ my @out = grep { local $_ = $self->_upgrade($_, %params); $_->$call(@$args) } @$self;
151
+
152
+ return blessed($self)->new_from_ref(\@out)
153
+ unless $params{in_place};
154
+
155
+ @$self = @out;
156
+ return $self;
157
+ };
158
+
159
+ 1;
160
+
161
+ __END__
162
+
163
+ =pod
164
+
165
+ =encoding UTF-8
166
+
167
+ =head1 NAME
168
+
169
+ Test2::API::InterceptResult - Representation of a list of events.
170
+
171
+ =head1 DESCRIPTION
172
+
173
+ This class represents a list of events, normally obtained using C<intercept()>
174
+ from L<Test2::API>.
175
+
176
+ This class is intended for people who with to verify the results of test tools
177
+ they write.
178
+
179
+ This class provides methods to normalize, summarize, or map the list of events.
180
+ The output of these operations makes verifying your testing tools and the
181
+ events they generate significantly easier. In most cases this spares you from
182
+ needing a deep understanding of the event/facet model.
183
+
184
+ =head1 SYNOPSIS
185
+
186
+ Usually you get an instance of this class when you use C<intercept()> from
187
+ L<Test2::API>.
188
+
189
+ use Test2::V0;
190
+ use Test2::API qw/intercept/;
191
+
192
+ my $events = intercept {
193
+ ok(1, "pass");
194
+ ok(0, "fail");
195
+ todo "broken" => sub { ok(0, "fixme") };
196
+ plan 3;
197
+ };
198
+
199
+ # This is typically the most useful construct
200
+ # squash_info() merges assertions and diagnostics that are associated
201
+ # (and returns a new instance with the modifications)
202
+ # flatten() condenses the facet data into the key details for each event
203
+ # (and returns those structures in an arrayref)
204
+ is(
205
+ $events->squash_info->flatten(),
206
+ [
207
+ {
208
+ causes_failure => 0,
209
+
210
+ name => 'pass',
211
+ pass => 1,
212
+
213
+ trace_file => 'xxx.t',
214
+ trace_line => 5,
215
+ },
216
+ {
217
+ causes_failure => 1,
218
+
219
+ name => 'fail',
220
+ pass => 0,
221
+
222
+ trace_file => 'xxx.t',
223
+ trace_line => 6,
224
+
225
+ # There can be more than one diagnostics message so this is
226
+ # always an array when present.
227
+ diag => ["Failed test 'fail'\nat xxx.t line 6."],
228
+ },
229
+ {
230
+ causes_failure => 0,
231
+
232
+ name => 'fixme',
233
+ pass => 0,
234
+
235
+ trace_file => 'xxx.t',
236
+ trace_line => 7,
237
+
238
+ # There can be more than one diagnostics message or todo
239
+ # reason, so these are always an array when present.
240
+ todo => ['broken'],
241
+
242
+ # Diag message was turned into a note since the assertion was
243
+ # TODO
244
+ note => ["Failed test 'fixme'\nat xxx.t line 7."],
245
+ },
246
+ {
247
+ causes_failure => 0,
248
+
249
+ plan => 3,
250
+
251
+ trace_file => 'xxx.t',
252
+ trace_line => 8,
253
+ },
254
+ ],
255
+ "Flattened events look like we expect"
256
+ );
257
+
258
+ See L<Test2::API::InterceptResult::Event> for a full description of what
259
+ C<flatten()> provides for each event.
260
+
261
+ =head1 METHODS
262
+
263
+ Please note that no methods modify the original instance unless asked to do so.
264
+
265
+ =head2 CONSTRUCTION
266
+
267
+ =over 4
268
+
269
+ =item $events = Test2::API::InterceptResult->new(@EVENTS)
270
+
271
+ =item $events = Test2::API::InterceptResult->new_from_ref(\@EVENTS)
272
+
273
+ These create a new instance of Test2::API::InterceptResult from the given
274
+ events.
275
+
276
+ In the first form a new blessed arrayref is returned. In the 'new_from_ref'
277
+ form the reference you pass in is directly blessed.
278
+
279
+ Both of these will throw an exception if called in void context. This is mainly
280
+ important for the 'filtering' methods listed below which normally return a new
281
+ instance, they throw an exception in such cases as it probably means someone
282
+ meant to filter the original in place.
283
+
284
+ =item $clone = $events->clone()
285
+
286
+ Make a clone of the original events. Note that this is a deep copy, the entire
287
+ structure is duplicated. This uses C<dclone> from L<Storable> to achieve the
288
+ deep clone.
289
+
290
+ =back
291
+
292
+ =head2 NORMALIZATION
293
+
294
+ =over 4
295
+
296
+ =item @events = $events->event_list
297
+
298
+ This returns all the events in list-form.
299
+
300
+ =item $hub = $events->hub
301
+
302
+ This returns a new L<Test2::Hub> instance that has processed all the events
303
+ contained in the instance. This gives you a simple way to inspect the state
304
+ changes your events cause.
305
+
306
+ =item $state = $events->state
307
+
308
+ This returns a summary of the state of a hub after processing all the events.
309
+
310
+ {
311
+ count => 2, # Number of assertions made
312
+ failed => 1, # Number of test failures seen
313
+ is_passing => 0, # Boolean, true if the test would be passing
314
+ # after the events are processed.
315
+
316
+ plan => 2, # Plan, either a number, undef, 'SKIP', or 'NO PLAN'
317
+ follows_plan => 1, # True if there is a plan and it was followed.
318
+ # False if the plan and assertions did not
319
+ # match, undef if no plan was present in the
320
+ # event list.
321
+
322
+ bailed_out => undef, # undef unless there was a bail-out in the
323
+ # events in which case this will be a string
324
+ # explaining why there was a bailout, if no
325
+ # reason was given this will simply be set to
326
+ # true (1).
327
+
328
+ skip_reason => undef, # If there was a skip_all this will give the
329
+ # reason.
330
+ }
331
+
332
+
333
+ =item $new = $events->upgrade
334
+
335
+ =item $events->upgrade(in_place => $BOOL)
336
+
337
+ B<Note:> This normally returns a new instance, leaving the original unchanged.
338
+ If you call it in void context it will throw an exception. If you want to
339
+ modify the original you must pass in the C<< in_place => 1 >> option. You may
340
+ call this in void context when you ask to modify it in place. The in-place form
341
+ returns the instance that was modified so you can chain methods.
342
+
343
+ This will create a clone of the list where all events have been converted into
344
+ L<Test2::API::InterceptResult::Event> instances. This is extremely helpful as
345
+ L<Test2::API::InterceptResult::Event> provide a much better interface for
346
+ working with events. This allows you to avoid thinking about legacy event
347
+ types.
348
+
349
+ This also means your tests against the list are not fragile if the tool
350
+ you are testing randomly changes what type of events it generates (IE Changing
351
+ from L<Test2::Event::Ok> to L<Test2::Event::Pass>, both make assertions and
352
+ both will normalize to identical (or close enough)
353
+ L<Test2::API::InterceptResult::Event> instances.
354
+
355
+ Really you almost always want this, the only reason it is not done
356
+ automatically is to make sure the C<intercept()> tool is backwards compatible.
357
+
358
+ =item $new = $events->squash_info
359
+
360
+ =item $events->squash_info(in_place => $BOOL)
361
+
362
+ B<Note:> This normally returns a new instance, leaving the original unchanged.
363
+ If you call it in void context it will throw an exception. If you want to
364
+ modify the original you must pass in the C<< in_place => 1 >> option. You may
365
+ call this in void context when you ask to modify it in place. The in-place form
366
+ returns the instance that was modified so you can chain methods.
367
+
368
+ B<Note:> All events in the new or modified instance will be converted to
369
+ L<Test2::API::InterceptResult::Event> instances. There is no way to avoid this,
370
+ the squash operation requires the upgraded event class.
371
+
372
+ L<Test::More> and many other legacy tools would send notes, diags, and
373
+ assertions as separate events. A subtest in L<Test::More> would send a note
374
+ with the subtest name, the subtest assertion, and finally a diagnostics event
375
+ if the subtest failed. This method will normalize things by squashing the note
376
+ and diag into the same event as the subtest (This is different from putting
377
+ them into the subtest, which is not what happens).
378
+
379
+ =back
380
+
381
+ =head2 FILTERING
382
+
383
+ B<Note:> These normally return new instances, leaving the originals unchanged.
384
+ If you call them in void context they will throw exceptions. If you want to
385
+ modify the originals you must pass in the C<< in_place => 1 >> option. You may
386
+ call these in void context when you ask to modify them in place. The in-place
387
+ forms return the instance that was modified so you can chain methods.
388
+
389
+ =head3 %PARAMS
390
+
391
+ These all accept the same 2 optional parameters:
392
+
393
+ =over 4
394
+
395
+ =item in_place => $BOOL
396
+
397
+ When true the method will modify the instance in place instead of returning a
398
+ new instance.
399
+
400
+ =item args => \@ARGS
401
+
402
+ If you wish to pass parameters into the event method being used for filtering,
403
+ you may do so here.
404
+
405
+ =back
406
+
407
+ =head3 METHODS
408
+
409
+ =over 4
410
+
411
+ =item $events->grep($CALL, %PARAMS)
412
+
413
+ This is essentially:
414
+
415
+ Test2::API::InterceptResult->new(
416
+ grep { $_->$CALL( @{$PARAMS{args}} ) } $self->event_list,
417
+ );
418
+
419
+ B<Note:> that $CALL is called on an upgraded version of the event, though
420
+ the events returned will be the original ones, not the upgraded ones.
421
+
422
+ $CALL may be either the name of a method on
423
+ L<Test2::API::InterceptResult::Event>, or a coderef.
424
+
425
+ =item $events->asserts(%PARAMS)
426
+
427
+ This is essentially:
428
+
429
+ $events->grep(has_assert => @{$PARAMS{args}})
430
+
431
+ It returns a new instance containing only the events that made assertions.
432
+
433
+ =item $events->subtests(%PARAMS)
434
+
435
+ This is essentially:
436
+
437
+ $events->grep(has_subtest => @{$PARAMS{args}})
438
+
439
+ It returns a new instance containing only the events that have subtests.
440
+
441
+ =item $events->diags(%PARAMS)
442
+
443
+ This is essentially:
444
+
445
+ $events->grep(has_diags => @{$PARAMS{args}})
446
+
447
+ It returns a new instance containing only the events that have diags.
448
+
449
+ =item $events->notes(%PARAMS)
450
+
451
+ This is essentially:
452
+
453
+ $events->grep(has_notes => @{$PARAMS{args}})
454
+
455
+ It returns a new instance containing only the events that have notes.
456
+
457
+ =item $events->errors(%PARAMS)
458
+
459
+ B<Note:> Errors are NOT failing assertions. Failing assertions are a different
460
+ thing.
461
+
462
+ This is essentially:
463
+
464
+ $events->grep(has_errors => @{$PARAMS{args}})
465
+
466
+ It returns a new instance containing only the events that have errors.
467
+
468
+ =item $events->plans(%PARAMS)
469
+
470
+ This is essentially:
471
+
472
+ $events->grep(has_plan => @{$PARAMS{args}})
473
+
474
+ It returns a new instance containing only the events that set the plan.
475
+
476
+ =item $events->causes_fail(%PARAMS)
477
+
478
+ =item $events->causes_failure(%PARAMS)
479
+
480
+ These are essentially:
481
+
482
+ $events->grep(causes_fail => @{$PARAMS{args}})
483
+ $events->grep(causes_failure => @{$PARAMS{args}})
484
+
485
+ B<Note:> C<causes_fail()> and C<causes_failure()> are both aliases for
486
+ eachother in events, so these methods are effectively aliases here as well.
487
+
488
+ It returns a new instance containing only the events that cause failure.
489
+
490
+ =back
491
+
492
+ =head2 MAPPING
493
+
494
+ These methods B<ALWAYS> return an arrayref.
495
+
496
+ B<Note:> No methods on L<Test2::API::InterceptResult::Event> alter the event in
497
+ any way.
498
+
499
+ B<Important Notes about Events>:
500
+
501
+ L<Test2::API::InterceptResult::Event> was tailor-made to be used in
502
+ event-lists. Most methods that are not applicable to a given event will return
503
+ an empty list, so you normally do not need to worry about unwanted C<undef>
504
+ values or exceptions being thrown. Mapping over event methods is an intended
505
+ use, so it works well to produce lists.
506
+
507
+ B<Exceptions to the rule:>
508
+
509
+ Some methods such as C<causes_fail> always return a boolean true or false for
510
+ all events. Any method prefixed with C<the_> conveys the intent that the event
511
+ should have exactly 1 of something, so those will throw an exception when that
512
+ condition is not true.
513
+
514
+ =over 4
515
+
516
+ =item $arrayref = $events->map($CALL, %PARAMS)
517
+
518
+ This is essentially:
519
+
520
+ [ map { $_->$CALL(@{ $PARAMS{args} }) } $events->upgrade->event_list ];
521
+
522
+ $CALL may be either the name of a method on
523
+ L<Test2::API::InterceptResult::Event>, or a coderef.
524
+
525
+ =item $arrayref = $events->flatten(%PARAMS)
526
+
527
+ This is essentially:
528
+
529
+ [ map { $_->flatten(@{ $PARAMS{args} }) } $events->upgrade->event_list ];
530
+
531
+ It returns a new list of flattened structures.
532
+
533
+ See L<Test2::API::InterceptResult::Event> for details on what C<flatten()>
534
+ returns.
535
+
536
+ =item $arrayref = $events->briefs(%PARAMS)
537
+
538
+ This is essentially:
539
+
540
+ [ map { $_->briefs(@{ $PARAMS{args} }) } $events->upgrade->event_list ];
541
+
542
+ It returns a new list of event briefs.
543
+
544
+ See L<Test2::API::InterceptResult::Event> for details on what C<brief()>
545
+ returns.
546
+
547
+ =item $arrayref = $events->summaries(%PARAMS)
548
+
549
+ This is essentially:
550
+
551
+ [ map { $_->summaries(@{ $PARAMS{args} }) } $events->upgrade->event_list ];
552
+
553
+ It returns a new list of event summaries.
554
+
555
+ See L<Test2::API::InterceptResult::Event> for details on what C<summary()>
556
+ returns.
557
+
558
+ =item $arrayref = $events->subtest_results(%PARAMS)
559
+
560
+ This is essentially:
561
+
562
+ [ map { $_->subtest_result(@{ $PARAMS{args} }) } $events->upgrade->event_list ];
563
+
564
+ It returns a new list of event summaries.
565
+
566
+ See L<Test2::API::InterceptResult::Event> for details on what
567
+ C<subtest_result()> returns.
568
+
569
+ =item $arrayref = $events->diag_messages(%PARAMS)
570
+
571
+ This is essentially:
572
+
573
+ [ map { $_->diag_messages(@{ $PARAMS{args} }) } $events->upgrade->event_list ];
574
+
575
+ It returns a new list of diagnostic messages (strings).
576
+
577
+ See L<Test2::API::InterceptResult::Event> for details on what
578
+ C<diag_messages()> returns.
579
+
580
+ =item $arrayref = $events->note_messages(%PARAMS)
581
+
582
+ This is essentially:
583
+
584
+ [ map { $_->note_messages(@{ $PARAMS{args} }) } $events->upgrade->event_list ];
585
+
586
+ It returns a new list of notification messages (strings).
587
+
588
+ See L<Test2::API::InterceptResult::Event> for details on what
589
+ C<note_messages()> returns.
590
+
591
+ =item $arrayref = $events->error_messages(%PARAMS)
592
+
593
+ This is essentially:
594
+
595
+ [ map { $_->error_messages(@{ $PARAMS{args} }) } $events->upgrade->event_list ];
596
+
597
+ It returns a new list of error messages (strings).
598
+
599
+ See L<Test2::API::InterceptResult::Event> for details on what
600
+ C<error_messages()> returns.
601
+
602
+ =back
603
+
604
+ =head1 SOURCE
605
+
606
+ The source code repository for Test2 can be found at
607
+ L<https://github.com/Test-More/test-more/>.
608
+
609
+ =head1 MAINTAINERS
610
+
611
+ =over 4
612
+
613
+ =item Chad Granum E<lt>exodist@cpan.orgE<gt>
614
+
615
+ =back
616
+
617
+ =head1 AUTHORS
618
+
619
+ =over 4
620
+
621
+ =item Chad Granum E<lt>exodist@cpan.orgE<gt>
622
+
623
+ =back
624
+
625
+ =head1 COPYRIGHT
626
+
627
+ Copyright Chad Granum E<lt>exodist@cpan.orgE<gt>.
628
+
629
+ This program is free software; you can redistribute it and/or
630
+ modify it under the same terms as Perl itself.
631
+
632
+ See L<https://dev.perl.org/licenses/>
633
+
634
+ =cut
git/usr/share/perl5/core_perl/Test2/API/InterceptResult/Event.pm ADDED
@@ -0,0 +1,1088 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package Test2::API::InterceptResult::Event;
2
+ use strict;
3
+ use warnings;
4
+
5
+ our $VERSION = '1.302210';
6
+
7
+ use List::Util qw/first/;
8
+ use Test2::Util qw/pkg_to_file/;
9
+ use Scalar::Util qw/reftype blessed/;
10
+
11
+ use Storable qw/dclone/;
12
+ use Carp qw/confess croak/;
13
+
14
+ use Test2::API::InterceptResult::Facet;
15
+ use Test2::API::InterceptResult::Hub;
16
+
17
+ use Test2::Util::HashBase qw{
18
+ +causes_failure
19
+ <facet_data
20
+ <result_class
21
+ };
22
+
23
+ my %FACETS;
24
+ BEGIN {
25
+ local $@;
26
+ local *plugins;
27
+ if (eval { require Module::Pluggable; 1 }) {
28
+ Module::Pluggable->import(
29
+ # We will replace the sub later
30
+ require => 1,
31
+ on_require_error => sub { 1 },
32
+ search_path => ['Test2::EventFacet'],
33
+ max_depth => 3,
34
+ min_depth => 3,
35
+ );
36
+
37
+ for my $facet_type (__PACKAGE__->plugins) {
38
+ my ($key, $list);
39
+ eval {
40
+ $key = $facet_type->facet_key;
41
+ $list = $facet_type->is_list;
42
+ };
43
+ next unless $key && defined($list);
44
+
45
+ $FACETS{$key} = {list => $list, class => $facet_type, loaded => 1};
46
+ }
47
+ }
48
+
49
+ $FACETS{__GENERIC__} = {class => 'Test2::API::InterceptResult::Facet', loaded => 1};
50
+ }
51
+
52
+ sub facet_map { \%FACETS }
53
+
54
+ sub facet_info {
55
+ my $facet = pop;
56
+
57
+ return $FACETS{$facet} if exists $FACETS{$facet};
58
+
59
+ my $mname = ucfirst(lc($facet));
60
+ $mname =~ s/s$//;
61
+
62
+ for my $name ($mname, "${mname}s") {
63
+ my $file = "Test2/EventFacet/$name.pm";
64
+ my $class = "Test2::EventFacet::$name";
65
+
66
+ local $@;
67
+ my $ok = eval {
68
+ require $file;
69
+
70
+ my $key = $class->facet_key;
71
+ my $list = $class->is_list;
72
+
73
+ $FACETS{$key} = {list => $list, class => $class, loaded => 1};
74
+ $FACETS{$facet} = $FACETS{$key} if $facet ne $key;
75
+
76
+ 1;
77
+ };
78
+
79
+ return $FACETS{$facet} if $ok && $FACETS{$facet};
80
+ }
81
+
82
+ return $FACETS{$facet} = $FACETS{__GENERIC__};
83
+ }
84
+
85
+ sub init {
86
+ my $self = shift;
87
+
88
+ my $rc = $self->{+RESULT_CLASS} ||= 'Test2::API::InterceptResult';
89
+ my $rc_file = pkg_to_file($rc);
90
+ require($rc_file) unless $INC{$rc_file};
91
+
92
+ my $fd = $self->{+FACET_DATA} ||= {};
93
+
94
+ for my $facet (keys %$fd) {
95
+ my $finfo = $self->facet_info($facet);
96
+ my $is_list = $finfo->{list};
97
+ next unless defined $is_list;
98
+
99
+ my $type = reftype($fd->{$facet});
100
+
101
+ if ($is_list) {
102
+ confess "Facet '$facet' is a list facet, but got '$type' instead of an arrayref"
103
+ unless $type eq 'ARRAY';
104
+
105
+ for my $item (@{$fd->{$facet}}) {
106
+ my $itype = reftype($item);
107
+ next if $itype eq 'HASH';
108
+
109
+ confess "Got item type '$itype' in list-facet '$facet', all items must be hashrefs";
110
+ }
111
+ }
112
+ else {
113
+ confess "Facet '$facet' is an only-one facet, but got '$type' instead of a hashref"
114
+ unless $type eq 'HASH';
115
+ }
116
+ }
117
+ }
118
+
119
+ sub clone {
120
+ my $self = shift;
121
+ my $class = blessed($self);
122
+
123
+ my %data = %$self;
124
+
125
+ $data{+FACET_DATA} = dclone($data{+FACET_DATA});
126
+
127
+ return bless(\%data, $class);
128
+ }
129
+
130
+ sub _facet_class {
131
+ my $self = shift;
132
+ my ($name) = @_;
133
+
134
+ my $spec = $self->facet_info($name);
135
+ my $class = $spec->{class};
136
+ unless ($spec->{loaded}) {
137
+ my $file = pkg_to_file($class);
138
+ require $file unless $INC{$file};
139
+ $spec->{loaded} = 1;
140
+ }
141
+
142
+ return $class;
143
+ }
144
+
145
+ sub the_facet {
146
+ my $self = shift;
147
+ my ($name) = @_;
148
+
149
+ return undef unless defined $self->{+FACET_DATA}->{$name};
150
+
151
+ my $data = $self->{+FACET_DATA}->{$name};
152
+
153
+ my $type = reftype($data) or confess "Facet '$name' has a value that is not a reference, this should not happen";
154
+
155
+ return $self->_facet_class($name)->new(%{dclone($data)})
156
+ if $type eq 'HASH';
157
+
158
+ if ($type eq 'ARRAY') {
159
+ return undef unless @$data;
160
+ croak "'the_facet' called for facet '$name', but '$name' has '" . @$data . "' items" if @$data != 1;
161
+ return $self->_facet_class($name)->new(%{dclone($data->[0])});
162
+ }
163
+
164
+ die "Invalid facet data type: $type";
165
+ }
166
+
167
+ sub facet {
168
+ my $self = shift;
169
+ my ($name) = @_;
170
+
171
+ return () unless exists $self->{+FACET_DATA}->{$name};
172
+
173
+ my $data = $self->{+FACET_DATA}->{$name};
174
+
175
+ my $type = reftype($data) or confess "Facet '$name' has a value that is not a reference, this should not happen";
176
+
177
+ my @out;
178
+ @out = ($data) if $type eq 'HASH';
179
+ @out = (@$data) if $type eq 'ARRAY';
180
+
181
+ my $class = $self->_facet_class($name);
182
+
183
+ return map { $class->new(%{dclone($_)}) } @out;
184
+ }
185
+
186
+ sub causes_failure {
187
+ my $self = shift;
188
+
189
+ return $self->{+CAUSES_FAILURE}
190
+ if exists $self->{+CAUSES_FAILURE};
191
+
192
+ my $hub = Test2::API::InterceptResult::Hub->new();
193
+ $hub->process($self);
194
+
195
+ return $self->{+CAUSES_FAILURE} = ($hub->is_passing ? 0 : 1);
196
+ }
197
+
198
+ sub causes_fail { shift->causes_failure }
199
+
200
+ sub trace { $_[0]->facet('trace') }
201
+ sub the_trace { $_[0]->the_facet('trace') }
202
+ sub frame { my $t = $_[0]->the_trace or return undef; $t->{frame} || undef }
203
+ sub trace_details { my $t = $_[0]->the_trace or return undef; $t->{details} || undef }
204
+ sub trace_stamp { my $f = $_[0]->the_trace or return undef; $f->{stamp} || undef }
205
+ sub trace_package { my $f = $_[0]->frame or return undef; $f->[0] || undef }
206
+ sub trace_file { my $f = $_[0]->frame or return undef; $f->[1] || undef }
207
+ sub trace_line { my $f = $_[0]->frame or return undef; $f->[2] || undef }
208
+ sub trace_subname { my $f = $_[0]->frame or return undef; $f->[3] || undef }
209
+ sub trace_tool { my $f = $_[0]->frame or return undef; $f->[3] || undef }
210
+
211
+ sub trace_signature { my $t = $_[0]->the_trace or return undef; Test2::EventFacet::Trace::signature($t) || undef }
212
+
213
+ sub brief {
214
+ my $self = shift;
215
+
216
+ my @try = qw{
217
+ bailout_brief
218
+ error_brief
219
+ assert_brief
220
+ plan_brief
221
+ };
222
+
223
+ for my $meth (@try) {
224
+ my $got = $self->$meth or next;
225
+ return $got;
226
+ }
227
+
228
+ return;
229
+ }
230
+
231
+ sub flatten {
232
+ my $self = shift;
233
+ my %params = @_;
234
+
235
+ my $todo = {%{$self->{+FACET_DATA}}};
236
+ delete $todo->{hubs};
237
+ delete $todo->{meta};
238
+ delete $todo->{trace};
239
+
240
+ my $out = $self->summary;
241
+ delete $out->{brief};
242
+ delete $out->{facets};
243
+ delete $out->{trace_tool};
244
+ delete $out->{trace_details} unless defined($out->{trace_details});
245
+
246
+ for my $tagged (grep { my $finfo = $self->facet_info($_); $finfo->{list} && $finfo->{class}->can('tag') } keys %FACETS, keys %$todo) {
247
+ my $set = delete $todo->{$tagged} or next;
248
+
249
+ my $fd = $self->{+FACET_DATA};
250
+ my $has_assert = $self->has_assert;
251
+ my $has_parent = $self->has_subtest;
252
+ my $has_fatal_error = $self->has_errors && grep { $_->{fail} } $self->errors;
253
+
254
+ next if $tagged eq 'amnesty' && !($has_assert || $has_parent || $has_fatal_error);
255
+
256
+ for my $item (@$set) {
257
+ push @{$out->{lc($item->{tag})}} => $item->{fail} ? "FATAL: $item->{details}" : $item->{details};
258
+ }
259
+ }
260
+
261
+ if (my $assert = delete $todo->{assert}) {
262
+ $out->{pass} = $assert->{pass};
263
+ $out->{name} = $assert->{details};
264
+ }
265
+
266
+ if (my $parent = delete $todo->{parent}) {
267
+ delete $out->{subtest}->{bailed_out} unless defined $out->{subtest}->{bailed_out};
268
+ delete $out->{subtest}->{skip_reason} unless defined $out->{subtest}->{skip_reason};
269
+
270
+ if (my $res = $self->subtest_result) {
271
+ my $state = $res->state;
272
+ delete $state->{$_} for grep { !defined($state->{$_}) } keys %$state;
273
+ $out->{subtest} = $state;
274
+ $out->{subevents} = $res->flatten(%params)
275
+ if $params{include_subevents};
276
+ }
277
+ }
278
+
279
+ if (my $control = delete $todo->{control}) {
280
+ if ($control->{halt}) {
281
+ $out->{bailed_out} = $control->{details} || 1;
282
+ }
283
+ elsif(defined $control->{details}) {
284
+ $out->{control} = $control->{details};
285
+ }
286
+ }
287
+
288
+ if (my $plan = delete $todo->{plan}) {
289
+ $out->{plan} = $self->plan_brief;
290
+ $out->{plan} =~ s/^PLAN\s*//;
291
+ }
292
+
293
+ for my $other (keys %$todo) {
294
+ my $data = $todo->{$other} or next;
295
+
296
+ if (reftype($data) eq 'ARRAY') {
297
+ if (!$out->{$other} || reftype($out->{$other}) eq 'ARRAY') {
298
+ for my $item (@$data) {
299
+ push @{$out->{$other}} => $item->{details} if defined $item->{details};
300
+ }
301
+ }
302
+ }
303
+ else {
304
+ $out->{$other} = $data->{details} if defined($data->{details}) && !defined($out->{$other});
305
+ }
306
+ }
307
+
308
+ if (my $fields = $params{fields}) {
309
+ $out = { map {exists($out->{$_}) ? ($_ => $out->{$_}) : ()} @$fields };
310
+ }
311
+
312
+ if (my $remove = $params{remove}) {
313
+ delete $out->{$_} for @$remove;
314
+ }
315
+
316
+ return $out;
317
+ }
318
+
319
+ sub summary {
320
+ my $self = shift;
321
+ my %params = @_;
322
+
323
+ my $out = {
324
+ brief => $self->brief || '',
325
+
326
+ causes_failure => $self->causes_failure,
327
+
328
+ trace_line => $self->trace_line,
329
+ trace_file => $self->trace_file,
330
+ trace_tool => $self->trace_subname,
331
+ trace_details => $self->trace_details,
332
+
333
+ facets => [ sort keys(%{$self->{+FACET_DATA}}) ],
334
+ };
335
+
336
+ if (my $fields = $params{fields}) {
337
+ $out = { map {exists($out->{$_}) ? ($_ => $out->{$_}) : ()} @$fields };
338
+ }
339
+
340
+ if (my $remove = $params{remove}) {
341
+ delete $out->{$_} for @$remove;
342
+ }
343
+
344
+ return $out;
345
+ }
346
+
347
+ sub has_assert { $_[0]->{+FACET_DATA}->{assert} ? 1 : 0 }
348
+ sub the_assert { $_[0]->the_facet('assert') }
349
+ sub assert { $_[0]->facet('assert') }
350
+
351
+ sub assert_brief {
352
+ my $self = shift;
353
+
354
+ my $fd = $self->{+FACET_DATA};
355
+ my $as = $fd->{assert} or return;
356
+ my $am = $fd->{amnesty};
357
+
358
+ my $out = $as->{pass} ? "PASS" : "FAIL";
359
+ $out .= " with amnesty" if $am;
360
+ return $out;
361
+ }
362
+
363
+ sub has_subtest { $_[0]->{+FACET_DATA}->{parent} ? 1 : 0 }
364
+ sub the_subtest { $_[0]->the_facet('parent') }
365
+ sub subtest { $_[0]->facet('parent') }
366
+
367
+ sub subtest_result {
368
+ my $self = shift;
369
+
370
+ my $parent = $self->{+FACET_DATA}->{parent} or return;
371
+ my $children = $parent->{children} || [];
372
+
373
+ $children = $self->{+RESULT_CLASS}->new(@$children)->upgrade
374
+ unless blessed($children) && $children->isa($self->{+RESULT_CLASS});
375
+
376
+ return $children;
377
+ }
378
+
379
+ sub has_bailout { $_[0]->bailout ? 1 : 0 }
380
+ sub the_bailout { my ($b) = $_[0]->bailout; $b }
381
+
382
+ sub bailout {
383
+ my $self = shift;
384
+ my $control = $self->{+FACET_DATA}->{control} or return;
385
+ return $control if $control->{halt};
386
+ return;
387
+ }
388
+
389
+ sub bailout_brief {
390
+ my $self = shift;
391
+ my $bo = $self->bailout or return;
392
+
393
+ my $reason = $bo->{details} or return "BAILED OUT";
394
+ return "BAILED OUT: $reason";
395
+ }
396
+
397
+ sub bailout_reason {
398
+ my $self = shift;
399
+ my $bo = $self->bailout or return;
400
+ return $bo->{details} || '';
401
+ }
402
+
403
+ sub has_plan { $_[0]->{+FACET_DATA}->{plan} ? 1 : 0 }
404
+ sub the_plan { $_[0]->the_facet('plan') }
405
+ sub plan { $_[0]->facet('plan') }
406
+
407
+ sub plan_brief {
408
+ my $self = shift;
409
+
410
+ my $plan = $self->{+FACET_DATA}->{plan} or return;
411
+
412
+ my $base = $self->_plan_brief($plan);
413
+
414
+ my $reason = $plan->{details} or return $base;
415
+ return "$base: $reason";
416
+ }
417
+
418
+ sub _plan_brief {
419
+ my $self = shift;
420
+ my ($plan) = @_;
421
+
422
+ return 'NO PLAN' if $plan->{none};
423
+ return "SKIP ALL" if $plan->{skip} || !$plan->{count};
424
+ return "PLAN $plan->{count}";
425
+ }
426
+
427
+ sub has_amnesty { $_[0]->{+FACET_DATA}->{amnesty} ? 1 : 0 }
428
+ sub the_amnesty { $_[0]->the_facet('amnesty') }
429
+ sub amnesty { $_[0]->facet('amnesty') }
430
+ sub amnesty_reasons { map { $_->{details} } $_[0]->amnesty }
431
+
432
+ sub has_todos { &first(sub { uc($_->{tag}) eq 'TODO' }, $_[0]->amnesty) ? 1 : 0 }
433
+ sub todos { grep { uc($_->{tag}) eq 'TODO' } $_[0]->amnesty }
434
+ sub todo_reasons { map { $_->{details} || 'TODO' } $_[0]->todos }
435
+
436
+ sub has_skips { &first(sub { uc($_->{tag}) eq 'SKIP' }, $_[0]->amnesty) ? 1 : 0 }
437
+ sub skips { grep { uc($_->{tag}) eq 'SKIP' } $_[0]->amnesty }
438
+ sub skip_reasons { map { $_->{details} || 'SKIP' } $_[0]->skips }
439
+
440
+ my %TODO_OR_SKIP = (SKIP => 1, TODO => 1);
441
+ sub has_other_amnesty { &first( sub { !$TODO_OR_SKIP{uc($_->{tag})} }, $_[0]->amnesty) ? 1 : 0 }
442
+ sub other_amnesty { grep { !$TODO_OR_SKIP{uc($_->{tag})} } $_[0]->amnesty }
443
+ sub other_amnesty_reasons { map { $_->{details} || $_->{tag} || 'AMNESTY' } $_[0]->other_amnesty }
444
+
445
+ sub has_errors { $_[0]->{+FACET_DATA}->{errors} ? 1 : 0 }
446
+ sub the_errors { $_[0]->the_facet('errors') }
447
+ sub errors { $_[0]->facet('errors') }
448
+ sub error_messages { map { $_->{details} || $_->{tag} || 'ERROR' } $_[0]->errors }
449
+
450
+ sub error_brief {
451
+ my $self = shift;
452
+
453
+ my $errors = $self->{+FACET_DATA}->{errors} or return;
454
+
455
+ my $base = @$errors > 1 ? "ERRORS" : "ERROR";
456
+
457
+ return $base unless @$errors;
458
+
459
+ my ($msg, @extra) = split /[\n\r]+/, $errors->[0]->{details};
460
+
461
+ my $out = "$base: $msg";
462
+
463
+ $out .= " [...]" if @extra || @$errors > 1;
464
+
465
+ return $out;
466
+ }
467
+
468
+ sub has_info { $_[0]->{+FACET_DATA}->{info} ? 1 : 0 }
469
+ sub the_info { $_[0]->the_facet('info') }
470
+ sub info { $_[0]->facet('info') }
471
+ sub info_messages { map { $_->{details} } $_[0]->info }
472
+
473
+ sub has_diags { &first(sub { uc($_->{tag}) eq 'DIAG' }, $_[0]->info) ? 1 : 0 }
474
+ sub diags { grep { uc($_->{tag}) eq 'DIAG' } $_[0]->info }
475
+ sub diag_messages { map { $_->{details} || 'DIAG' } $_[0]->diags }
476
+
477
+ sub has_notes { &first(sub { uc($_->{tag}) eq 'NOTE' }, $_[0]->info) ? 1 : 0 }
478
+ sub notes { grep { uc($_->{tag}) eq 'NOTE' } $_[0]->info }
479
+ sub note_messages { map { $_->{details} || 'NOTE' } $_[0]->notes }
480
+
481
+ my %NOTE_OR_DIAG = (NOTE => 1, DIAG => 1);
482
+ sub has_other_info { &first(sub { !$NOTE_OR_DIAG{uc($_->{tag})} }, $_[0]->info) ? 1 : 0 }
483
+ sub other_info { grep { !$NOTE_OR_DIAG{uc($_->{tag})} } $_[0]->info }
484
+ sub other_info_messages { map { $_->{details} || $_->{tag} || 'INFO' } $_[0]->other_info }
485
+
486
+ 1;
487
+
488
+ __END__
489
+
490
+ =pod
491
+
492
+ =encoding UTF-8
493
+
494
+ =head1 NAME
495
+
496
+ Test2::API::InterceptResult::Event - Representation of an event for use in
497
+ testing other test tools.
498
+
499
+ =head1 DESCRIPTION
500
+
501
+ C<intercept { ... }> from L<Test2::API> returns an instance of
502
+ L<Test2::API::InterceptResult> which is a blessed arrayref of
503
+ L<Test2::API::InterceptResult::Event> objects.
504
+
505
+ This POD documents the methods of these events, which are mainly provided for
506
+ you to use when testing your test tools.
507
+
508
+ =head1 SYNOPSIS
509
+
510
+ use Test2::V0;
511
+ use Test2::API qw/intercept/;
512
+
513
+ my $events = intercept {
514
+ ok(1, "A passing assertion");
515
+ plan(1);
516
+ };
517
+
518
+ # This will convert all events into instances of
519
+ # Test2::API::InterceptResult::Event. Until we do this they are the
520
+ # original Test::Event::* instances
521
+ $events->upgrade(in_place => 1);
522
+
523
+ # Now we can get individual events in this form
524
+ my $assert = $events->[0];
525
+ my $plan = $events->[1];
526
+
527
+ # Or we can operate on all events at once:
528
+ my $flattened = $events->flatten;
529
+ is(
530
+ $flattened,
531
+ [
532
+ {
533
+ causes_failure => 0,
534
+
535
+ name => 'A passing assertion',
536
+ pass => 1,
537
+
538
+ trace_file => 'xxx.t',
539
+ trace_line => 5,
540
+ },
541
+ {
542
+ causes_failure => 0,
543
+
544
+ plan => 1,
545
+
546
+ trace_file => 'xxx.t',
547
+ trace_line => 6,
548
+ },
549
+ ],
550
+ "Flattened both events and returned an arrayref of the results
551
+ );
552
+
553
+ =head1 METHODS
554
+
555
+ =head2 !!! IMPORTANT NOTES ON DESIGN !!!
556
+
557
+ Please pay attention to what these return, many return a scalar when
558
+ applicable or an empty list when not (as opposed to undef). Many also always
559
+ return a list of 0 or more items. Some always return a scalar. Note that none
560
+ of the methods care about context, their behavior is consistent regardless of
561
+ scalar, list, or void context.
562
+
563
+ This was done because this class was specifically designed to be used in a list
564
+ and generate more lists in bulk operations. Sometimes in a map you want nothing
565
+ to show up for the event, and you do not want an undef in its place. In general
566
+ single event instances are not going to be used alone, though that is allowed.
567
+
568
+ As a general rule any method prefixed with C<the_> implies the event should
569
+ have exactly 1 of the specified item, and and exception will be thrown if there
570
+ are 0, or more than 1 of the item.
571
+
572
+ =head2 ATTRIBUTES
573
+
574
+ =over 4
575
+
576
+ =item $hashref = $event->facet_data
577
+
578
+ This will return the facet data hashref, which is all Test2 cares about for any
579
+ given event.
580
+
581
+ =item $class = $event->result_class
582
+
583
+ This is normally L<Test2::API::InterceptResult>. This is set at construction so
584
+ that subtest results can be turned into instances of it on demand.
585
+
586
+ =back
587
+
588
+ =head2 DUPLICATION
589
+
590
+ =over 4
591
+
592
+ =item $copy = $event->clone
593
+
594
+ Create a deep copy of the event. Modifying either event will not affect the
595
+ other.
596
+
597
+ =back
598
+
599
+ =head2 CONDENSED MULTI-FACET DATA
600
+
601
+ =over 4
602
+
603
+ =item $bool = $event->causes_failure
604
+
605
+ =item $bool = $event->causes_fail
606
+
607
+ These are both aliases of the same functionality.
608
+
609
+ This will always return either a true value, or a false value. This never
610
+ returns a list.
611
+
612
+ This method may be relatively slow (still super fast) because it determines
613
+ pass or fail by creating an instance of L<Test2::Hub> and asking it to process
614
+ the event, and then asks the hub for its pass/fail state. This is slower than
615
+ building in logic to do the check, but it is more reliable as it will always
616
+ tell you what the hub thinks, so the logic will never be out of date relative
617
+ to the Test2 logic that actually cares.
618
+
619
+ =item STRING_OR_EMPTY_LIST = $event->brief
620
+
621
+ Not all events have a brief, some events are not rendered by the formatter,
622
+ others have no "brief" data worth seeing. When this is the case an empty list
623
+ is returned. This is done intentionally so it can be used in a map operation
624
+ without having C<undef> being included in the result.
625
+
626
+ When a brief can be generated it is always a single 1-line string, and is
627
+ returned as-is, not in a list.
628
+
629
+ Possible briefs:
630
+
631
+ # From control facets
632
+ "BAILED OUT"
633
+ "BAILED OUT: $why"
634
+
635
+ # From error facets
636
+ "ERROR"
637
+ "ERROR: $message"
638
+ "ERROR: $partial_message [...]"
639
+ "ERRORS: $first_error_message [...]"
640
+
641
+ # From assert facets
642
+ "PASS"
643
+ "FAIL"
644
+ "PASS with amnesty"
645
+ "FAIL with amnesty"
646
+
647
+ # From plan facets
648
+ "PLAN $count"
649
+ "NO PLAN"
650
+ "SKIP ALL"
651
+ "SKIP ALL: $why"
652
+
653
+ Note that only the first applicable brief is returned. This is essentially a
654
+ poor-mans TAP that only includes facets that could (but not necessarily do)
655
+ cause a failure.
656
+
657
+ =item $hashref = $event->flatten
658
+
659
+ =item $hashref = $event->flatten(include_subevents => 1)
660
+
661
+ This ALWAYS returns a hashref. This puts all the most useful data for the most
662
+ interesting facets into a single hashref for easy validation.
663
+
664
+ If there are no meaningful facets this will return an empty hashref.
665
+
666
+ If given the 'include_subevents' parameter it will also include subtest data:
667
+
668
+ Here is a list of EVERY possible field. If a field is not applicable it will
669
+ not be present.
670
+
671
+ =over 4
672
+
673
+ =item always present
674
+
675
+ causes_failure => 1, # Always present
676
+
677
+ =item Present if the event has a trace facet
678
+
679
+ trace_line => 42,
680
+ trace_file => 'Foo/Bar.pm',
681
+ trace_details => 'Extra trace details', # usually not present
682
+
683
+ =item If an assertion is present
684
+
685
+ pass => 0,
686
+ name => "1 + 1 = 2, so math works",
687
+
688
+ =item If a plan is present:
689
+
690
+ plan => $count_or_SKIP_ALL_or_NO_PLAN,
691
+
692
+ =item If amnesty facets are present
693
+
694
+ You get an array for each type that is present.
695
+
696
+ todo => [ # Yes you could be under multiple todos, this will list them all.
697
+ "I will fix this later",
698
+ "I promise to fix these",
699
+ ],
700
+
701
+ skip => ["This will format the main drive, do not run"],
702
+
703
+ ... => ["Other amnesty"]
704
+
705
+ =item If Info (note/diag) facets are present
706
+
707
+ You get an arrayref for any that are present, the key is not defined if they are not present.
708
+
709
+ diag => [
710
+ "Test failed at Foo/Bar.pm line 42",
711
+ "You forgot to tie your boots",
712
+ ],
713
+
714
+ note => ["Your boots are red"],
715
+
716
+ ... => ["Other info"],
717
+
718
+ =item If error facets are present
719
+
720
+ Always an arrayref
721
+
722
+ error => [
723
+ "non fatal error (does not cause test failure, just an FYI",
724
+ "FATAL: This is a fatal error (causes failure)",
725
+ ],
726
+
727
+ # Errors can have alternative tags, but in practice are always 'error',
728
+ # listing this for completeness.
729
+ ... => [ ... ]
730
+
731
+ =item Present if the event is a subtest
732
+
733
+ subtest => {
734
+ count => 2, # Number of assertions made
735
+ failed => 1, # Number of test failures seen
736
+ is_passing => 0, # Boolean, true if the test would be passing
737
+ # after the events are processed.
738
+
739
+ plan => 2, # Plan, either a number, undef, 'SKIP', or 'NO PLAN'
740
+ follows_plan => 1, # True if there is a plan and it was followed.
741
+ # False if the plan and assertions did not
742
+ # match, undef if no plan was present in the
743
+ # event list.
744
+
745
+ bailed_out => "foo", # if there was a bail-out in the
746
+ # events in this will be a string explaining
747
+ # why there was a bailout, if no reason was
748
+ # given this will simply be set to true (1).
749
+
750
+ skip_reason => "foo", # If there was a skip_all this will give the
751
+ # reason.
752
+ },
753
+
754
+ if C<< (include_subtest => 1) >> was provided as a parameter then the following
755
+ will be included. This is the result of turning all subtest child events into
756
+ an L<Test2::API::InterceptResult> instance and calling the C<flatten> method on
757
+ it.
758
+
759
+ subevents => Test2::API::InterceptResult->new(@child_events)->flatten(...),
760
+
761
+ =item If a bail-out is being requested
762
+
763
+ If no reason was given this will be set to 1.
764
+
765
+ bailed_out => "reason",
766
+
767
+ =back
768
+
769
+ =item $hashref = $event->summary()
770
+
771
+ This returns a limited summary. See C<flatten()>, which is usually a better
772
+ option.
773
+
774
+ {
775
+ brief => $event->brief || '',
776
+
777
+ causes_failure => $event->causes_failure,
778
+
779
+ trace_line => $event->trace_line,
780
+ trace_file => $event->trace_file,
781
+ trace_tool => $event->trace_subname,
782
+ trace_details => $event->trace_details,
783
+
784
+ facets => [ sort keys(%{$event->{+FACET_DATA}}) ],
785
+ }
786
+
787
+ =back
788
+
789
+ =head2 DIRECT ARBITRARY FACET ACCESS
790
+
791
+ =over 4
792
+
793
+ =item @list_of_facets = $event->facet($name)
794
+
795
+ This always returns a list of 0 or more items. This fetches the facet instances
796
+ from the event. For facets like 'assert' this will always return 0 or 1
797
+ item. For events like 'info' (diags, notes) this will return 0 or more
798
+ instances, once for each instance of the facet.
799
+
800
+ These will be blessed into the proper L<Test2::EventFacet> subclass. If no
801
+ subclass can be found it will be blessed as an
802
+ L<Test2::API::InterceptResult::Facet> generic facet class.
803
+
804
+ =item $undef_or_facet = $event->the_facet($name)
805
+
806
+ If you know you will have exactly 1 instance of a facet you can call this.
807
+
808
+ If you are correct and there is exactly one instance of the facet it will
809
+ always return the hashref.
810
+
811
+ If there are 0 instances of the facet this will return undef, not an empty
812
+ list.
813
+
814
+ If there are more than 1 instance this will throw an exception because your
815
+ assumption was incorrect.
816
+
817
+ =back
818
+
819
+ =head2 TRACE FACET
820
+
821
+ =over 4
822
+
823
+ =item @list_of_facets = $event->trace
824
+
825
+ TODO
826
+
827
+ =item $undef_or_hashref = $event->the_trace
828
+
829
+ This returns the trace hashref, or undef if it is not present.
830
+
831
+ =item $undef_or_arrayref = $event->frame
832
+
833
+ If a trace is present, and has a caller frame, this will be an arrayref:
834
+
835
+ [$package, $file, $line, $subname]
836
+
837
+ If the trace is not present, or has no caller frame this will return undef.
838
+
839
+ =item $undef_or_string = $event->trace_details
840
+
841
+ This is usually undef, but occasionally has a string that overrides the
842
+ file/line number debugging a trace usually provides on test failure.
843
+
844
+ =item $undef_or_string = $event->trace_package
845
+
846
+ Same as C<(caller())[0]>, the first element of the trace frame.
847
+
848
+ Will be undef if not present.
849
+
850
+ =item $undef_or_string = $event->trace_file
851
+
852
+ Same as C<(caller())[1]>, the second element of the trace frame.
853
+
854
+ Will be undef if not present.
855
+
856
+ =item $undef_or_integer = $event->trace_line
857
+
858
+ Same as C<(caller())[2]>, the third element of the trace frame.
859
+
860
+ Will be undef if not present.
861
+
862
+ =item $undef_or_string = $event->trace_subname
863
+
864
+ =item $undef_or_string = $event->trace_tool
865
+
866
+ Aliases for the same thing
867
+
868
+ Same as C<(caller($level))[4]>, the fourth element of the trace frame.
869
+
870
+ Will be undef if not present.
871
+
872
+ =item $undef_or_string = $event->trace_signature
873
+
874
+ A string that is a unique signature for the trace. If a single context
875
+ generates multiple events they will all have the same signature. This can be
876
+ used to tie assertions and diagnostics sent as separate events together after
877
+ the fact.
878
+
879
+ =back
880
+
881
+ =head2 ASSERT FACET
882
+
883
+ =over 4
884
+
885
+ =item $bool = $event->has_assert
886
+
887
+ Returns true if the event has an assert facet, false if it does not.
888
+
889
+ =item $undef_or_hashref = $event->the_assert
890
+
891
+ Returns the assert facet if present, undef if it is not.
892
+
893
+ =item @list_of_facets = $event->assert
894
+
895
+ TODO
896
+
897
+ =item EMPTY_LIST_OR_STRING = $event->assert_brief
898
+
899
+ Returns a string giving a brief of the assertion if an assertion is present.
900
+ Returns an empty list if no assertion is present.
901
+
902
+ =back
903
+
904
+ =head2 SUBTESTS (PARENT FACET)
905
+
906
+ =over 4
907
+
908
+ =item $bool = $event->has_subtest
909
+
910
+ True if a subetest is present in this event.
911
+
912
+ =item $undef_or_hashref = $event->the_subtest
913
+
914
+ Get the one subtest if present, otherwise undef.
915
+
916
+ =item @list_of_facets = $event->subtest
917
+
918
+ TODO
919
+
920
+ =item EMPTY_LIST_OR_OBJECT = $event->subtest_result
921
+
922
+ Returns an empty list if there is no subtest.
923
+
924
+ Get an instance of L<Test2::API::InterceptResult> representing the subtest.
925
+
926
+ =back
927
+
928
+ =head2 CONTROL FACET (BAILOUT, ENCODING)
929
+
930
+ =over 4
931
+
932
+ =item $bool = $event->has_bailout
933
+
934
+ True if there was a bailout
935
+
936
+ =item $undef_hashref = $event->the_bailout
937
+
938
+ Return the control facet if it requested a bailout.
939
+
940
+ =item EMPTY_LIST_OR_HASHREF = $event->bailout
941
+
942
+ Get a list of 0 or 1 hashrefs. The hashref will be the control facet if a
943
+ bail-out was requested.
944
+
945
+ =item EMPTY_LIST_OR_STRING = $event->bailout_brief
946
+
947
+ Get the brief of the bailout if present.
948
+
949
+ =item EMPTY_LIST_OR_STRING = $event->bailout_reason
950
+
951
+ Get the reason for the bailout, an empty string if no reason was provided, or
952
+ an empty list if there was no bailout.
953
+
954
+ =back
955
+
956
+ =head2 PLAN FACET
957
+
958
+ TODO
959
+
960
+ =over 4
961
+
962
+ =item $bool = $event->has_plan
963
+
964
+ =item $undef_or_hashref = $event->the_plan
965
+
966
+ =item @list_if_hashrefs = $event->plan
967
+
968
+ =item EMPTY_LIST_OR_STRING $event->plan_brief
969
+
970
+ =back
971
+
972
+ =head2 AMNESTY FACET (TODO AND SKIP)
973
+
974
+ TODO
975
+
976
+ =over 4
977
+
978
+ =item $event->has_amnesty
979
+
980
+ =item $event->the_amnesty
981
+
982
+ =item $event->amnesty
983
+
984
+ =item $event->amnesty_reasons
985
+
986
+ =item $event->has_todos
987
+
988
+ =item $event->todos
989
+
990
+ =item $event->todo_reasons
991
+
992
+ =item $event->has_skips
993
+
994
+ =item $event->skips
995
+
996
+ =item $event->skip_reasons
997
+
998
+ =item $event->has_other_amnesty
999
+
1000
+ =item $event->other_amnesty
1001
+
1002
+ =item $event->other_amnesty_reasons
1003
+
1004
+ =back
1005
+
1006
+ =head2 ERROR FACET (CAPTURED EXCEPTIONS)
1007
+
1008
+ TODO
1009
+
1010
+ =over 4
1011
+
1012
+ =item $event->has_errors
1013
+
1014
+ =item $event->the_errors
1015
+
1016
+ =item $event->errors
1017
+
1018
+ =item $event->error_messages
1019
+
1020
+ =item $event->error_brief
1021
+
1022
+ =back
1023
+
1024
+ =head2 INFO FACET (DIAG, NOTE)
1025
+
1026
+ TODO
1027
+
1028
+ =over 4
1029
+
1030
+ =item $event->has_info
1031
+
1032
+ =item $event->the_info
1033
+
1034
+ =item $event->info
1035
+
1036
+ =item $event->info_messages
1037
+
1038
+ =item $event->has_diags
1039
+
1040
+ =item $event->diags
1041
+
1042
+ =item $event->diag_messages
1043
+
1044
+ =item $event->has_notes
1045
+
1046
+ =item $event->notes
1047
+
1048
+ =item $event->note_messages
1049
+
1050
+ =item $event->has_other_info
1051
+
1052
+ =item $event->other_info
1053
+
1054
+ =item $event->other_info_messages
1055
+
1056
+ =back
1057
+
1058
+ =head1 SOURCE
1059
+
1060
+ The source code repository for Test2 can be found at
1061
+ L<https://github.com/Test-More/test-more/>.
1062
+
1063
+ =head1 MAINTAINERS
1064
+
1065
+ =over 4
1066
+
1067
+ =item Chad Granum E<lt>exodist@cpan.orgE<gt>
1068
+
1069
+ =back
1070
+
1071
+ =head1 AUTHORS
1072
+
1073
+ =over 4
1074
+
1075
+ =item Chad Granum E<lt>exodist@cpan.orgE<gt>
1076
+
1077
+ =back
1078
+
1079
+ =head1 COPYRIGHT
1080
+
1081
+ Copyright Chad Granum E<lt>exodist@cpan.orgE<gt>.
1082
+
1083
+ This program is free software; you can redistribute it and/or
1084
+ modify it under the same terms as Perl itself.
1085
+
1086
+ See L<https://dev.perl.org/licenses/>
1087
+
1088
+ =cut
git/usr/share/perl5/core_perl/Test2/API/InterceptResult/Facet.pm ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package Test2::API::InterceptResult::Facet;
2
+ use strict;
3
+ use warnings;
4
+
5
+ our $VERSION = '1.302210';
6
+
7
+ BEGIN {
8
+ require Test2::EventFacet;
9
+ our @ISA = ('Test2::EventFacet');
10
+ }
11
+
12
+ our $AUTOLOAD;
13
+ sub AUTOLOAD {
14
+ my $self = shift;
15
+
16
+ my $name = $AUTOLOAD;
17
+ $name =~ s/^.*:://g;
18
+
19
+ return undef unless exists $self->{$name};
20
+ return $self->{$name};
21
+ }
22
+
23
+ sub DESTROY {}
24
+
25
+ 1;
git/usr/share/perl5/core_perl/Test2/API/InterceptResult/Hub.pm ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package Test2::API::InterceptResult::Hub;
2
+ use strict;
3
+ use warnings;
4
+
5
+ our $VERSION = '1.302210';
6
+
7
+ BEGIN { require Test2::Hub; our @ISA = qw(Test2::Hub) }
8
+ use Test2::Util::HashBase;
9
+
10
+ sub init {
11
+ my $self = shift;
12
+ $self->SUPER::init();
13
+ $self->{+NESTED} = 0;
14
+ }
15
+
16
+ sub inherit {
17
+ my $self = shift;
18
+
19
+ $self->{+NESTED} = 0;
20
+ }
21
+
22
+ sub terminate { }
23
+
24
+ 1;
25
+
26
+ __END__
27
+
28
+ =pod
29
+
30
+ =encoding UTF-8
31
+
32
+ =head1 NAME
33
+
34
+ Test2::API::InterceptResult::Hub - Hub used by InterceptResult.
35
+
36
+ =head1 SOURCE
37
+
38
+ The source code repository for Test2 can be found at
39
+ L<https://github.com/Test-More/test-more/>.
40
+
41
+ =head1 MAINTAINERS
42
+
43
+ =over 4
44
+
45
+ =item Chad Granum E<lt>exodist@cpan.orgE<gt>
46
+
47
+ =back
48
+
49
+ =head1 AUTHORS
50
+
51
+ =over 4
52
+
53
+ =item Chad Granum E<lt>exodist@cpan.orgE<gt>
54
+
55
+ =back
56
+
57
+ =head1 COPYRIGHT
58
+
59
+ Copyright Chad Granum E<lt>exodist@cpan.orgE<gt>.
60
+
61
+ This program is free software; you can redistribute it and/or
62
+ modify it under the same terms as Perl itself.
63
+
64
+ See L<https://dev.perl.org/licenses/>
65
+
66
+ =cut
git/usr/share/perl5/core_perl/Test2/API/InterceptResult/Squasher.pm ADDED
@@ -0,0 +1,196 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package Test2::API::InterceptResult::Squasher;
2
+ use strict;
3
+ use warnings;
4
+
5
+ our $VERSION = '1.302210';
6
+
7
+ use Carp qw/croak/;
8
+ use List::Util qw/first/;
9
+
10
+ use Test2::Util::HashBase qw{
11
+ <events
12
+
13
+ +down_sig +down_buffer
14
+
15
+ +up_into +up_sig +up_clear
16
+ };
17
+
18
+ sub init {
19
+ my $self = shift;
20
+
21
+ croak "'events' is a required attribute" unless $self->{+EVENTS};
22
+ }
23
+
24
+ sub can_squash {
25
+ my $self = shift;
26
+ my ($event) = @_;
27
+
28
+ # No info, no squash
29
+ return unless $event->has_info;
30
+
31
+ # Do not merge up if one of these is true
32
+ return if first { $event->$_ } 'causes_fail', 'has_assert', 'has_bailout', 'has_errors', 'has_plan', 'has_subtest';
33
+
34
+ # Signature if we can squash
35
+ return $event->trace_signature;
36
+ }
37
+
38
+ sub process {
39
+ my $self = shift;
40
+ my ($event) = @_;
41
+
42
+ return if $self->squash_up($event);
43
+ return if $self->squash_down($event);
44
+
45
+ $self->flush_down($event);
46
+
47
+ push @{$self->{+EVENTS}} => $event;
48
+
49
+ return;
50
+ }
51
+
52
+ sub squash_down {
53
+ my $self = shift;
54
+ my ($event) = @_;
55
+
56
+ my $sig = $self->can_squash($event)
57
+ or return;
58
+
59
+ $self->flush_down()
60
+ if $self->{+DOWN_SIG} && $self->{+DOWN_SIG} ne $sig;
61
+
62
+ $self->{+DOWN_SIG} ||= $sig;
63
+ push @{$self->{+DOWN_BUFFER}} => $event;
64
+
65
+ return 1;
66
+ }
67
+
68
+ sub flush_down {
69
+ my $self = shift;
70
+ my ($into) = @_;
71
+
72
+ my $sig = delete $self->{+DOWN_SIG};
73
+ my $buffer = delete $self->{+DOWN_BUFFER};
74
+
75
+ return unless $buffer && @$buffer;
76
+
77
+ my $fsig = $into ? $into->trace_signature : undef;
78
+
79
+ if ($fsig && $fsig eq $sig) {
80
+ $self->squash($into, @$buffer);
81
+ }
82
+ else {
83
+ push @{$self->{+EVENTS}} => @$buffer if $buffer;
84
+ }
85
+ }
86
+
87
+ sub clear_up {
88
+ my $self = shift;
89
+
90
+ return unless $self->{+UP_CLEAR};
91
+
92
+ delete $self->{+UP_INTO};
93
+ delete $self->{+UP_SIG};
94
+ delete $self->{+UP_CLEAR};
95
+ }
96
+
97
+ sub squash_up {
98
+ my $self = shift;
99
+ my ($event) = @_;
100
+ no warnings 'uninitialized';
101
+
102
+ $self->clear_up;
103
+
104
+ if ($event->has_assert) {
105
+ if(my $sig = $event->trace_signature) {
106
+ $self->{+UP_INTO} = $event;
107
+ $self->{+UP_SIG} = $sig;
108
+ $self->{+UP_CLEAR} = 0;
109
+ }
110
+ else {
111
+ $self->{+UP_CLEAR} = 1;
112
+ $self->clear_up;
113
+ }
114
+
115
+ return;
116
+ }
117
+
118
+ my $into = $self->{+UP_INTO} or return;
119
+
120
+ # Next iteration should clear unless something below changes that
121
+ $self->{+UP_CLEAR} = 1;
122
+
123
+ # Only merge into matching trace signatres
124
+ my $sig = $self->can_squash($event);
125
+ return unless $sig eq $self->{+UP_SIG};
126
+
127
+ # OK Merge! Do not clear merge in case the return event is also a matching sig diag-only
128
+ $self->{+UP_CLEAR} = 0;
129
+
130
+ $self->squash($into, $event);
131
+
132
+ return 1;
133
+ }
134
+
135
+ sub squash {
136
+ my $self = shift;
137
+ my ($into, @from) = @_;
138
+ push @{$into->facet_data->{info}} => $_->info for @from;
139
+ }
140
+
141
+ sub DESTROY {
142
+ my $self = shift;
143
+
144
+ return unless $self->{+EVENTS};
145
+ $self->flush_down();
146
+ return;
147
+ }
148
+
149
+ 1;
150
+
151
+ __END__
152
+
153
+ =pod
154
+
155
+ =encoding UTF-8
156
+
157
+ =head1 NAME
158
+
159
+ Test2::API::InterceptResult::Squasher - Encapsulation of the algorithm that
160
+ squashes diags into assertions.
161
+
162
+ =head1 DESCRIPTION
163
+
164
+ Internal use only, please ignore.
165
+
166
+ =head1 SOURCE
167
+
168
+ The source code repository for Test2 can be found at
169
+ L<https://github.com/Test-More/test-more/>.
170
+
171
+ =head1 MAINTAINERS
172
+
173
+ =over 4
174
+
175
+ =item Chad Granum E<lt>exodist@cpan.orgE<gt>
176
+
177
+ =back
178
+
179
+ =head1 AUTHORS
180
+
181
+ =over 4
182
+
183
+ =item Chad Granum E<lt>exodist@cpan.orgE<gt>
184
+
185
+ =back
186
+
187
+ =head1 COPYRIGHT
188
+
189
+ Copyright Chad Granum E<lt>exodist@cpan.orgE<gt>.
190
+
191
+ This program is free software; you can redistribute it and/or
192
+ modify it under the same terms as Perl itself.
193
+
194
+ See L<https://dev.perl.org/licenses/>
195
+
196
+ =cut
git/usr/share/perl5/core_perl/Test2/API/Stack.pm ADDED
@@ -0,0 +1,226 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package Test2::API::Stack;
2
+ use strict;
3
+ use warnings;
4
+
5
+ our $VERSION = '1.302210';
6
+
7
+
8
+ use Test2::Hub();
9
+
10
+ use Carp qw/confess/;
11
+
12
+ sub new {
13
+ my $class = shift;
14
+ return bless [], $class;
15
+ }
16
+
17
+ sub new_hub {
18
+ my $self = shift;
19
+ my %params = @_;
20
+
21
+ my $class = delete $params{class} || 'Test2::Hub';
22
+
23
+ my $hub = $class->new(%params);
24
+
25
+ if (@$self) {
26
+ $hub->inherit($self->[-1], %params);
27
+ }
28
+ else {
29
+ require Test2::API;
30
+ $hub->format(Test2::API::test2_formatter()->new_root)
31
+ unless $hub->format || exists($params{formatter});
32
+
33
+ my $ipc = Test2::API::test2_ipc();
34
+ if ($ipc && !$hub->ipc && !exists($params{ipc})) {
35
+ $hub->set_ipc($ipc);
36
+ $ipc->add_hub($hub->hid);
37
+ }
38
+ }
39
+
40
+ push @$self => $hub;
41
+
42
+ $hub;
43
+ }
44
+
45
+ sub top {
46
+ my $self = shift;
47
+ return $self->new_hub unless @$self;
48
+ return $self->[-1];
49
+ }
50
+
51
+ sub peek {
52
+ my $self = shift;
53
+ return @$self ? $self->[-1] : undef;
54
+ }
55
+
56
+ sub cull {
57
+ my $self = shift;
58
+ $_->cull for reverse @$self;
59
+ }
60
+
61
+ sub all {
62
+ my $self = shift;
63
+ return @$self;
64
+ }
65
+
66
+ sub root {
67
+ my $self = shift;
68
+ return unless @$self;
69
+ return $self->[0];
70
+ }
71
+
72
+ sub clear {
73
+ my $self = shift;
74
+ @$self = ();
75
+ }
76
+
77
+ # Do these last without keywords in order to prevent them from getting used
78
+ # when we want the real push/pop.
79
+
80
+ {
81
+ no warnings 'once';
82
+
83
+ *push = sub {
84
+ my $self = shift;
85
+ my ($hub) = @_;
86
+ $hub->inherit($self->[-1]) if @$self;
87
+ push @$self => $hub;
88
+ };
89
+
90
+ *pop = sub {
91
+ my $self = shift;
92
+ my ($hub) = @_;
93
+ confess "No hubs on the stack"
94
+ unless @$self;
95
+ confess "You cannot pop the root hub"
96
+ if 1 == @$self;
97
+ confess "Hub stack mismatch, attempted to pop incorrect hub"
98
+ unless $self->[-1] == $hub;
99
+ pop @$self;
100
+ };
101
+ }
102
+
103
+ 1;
104
+
105
+ __END__
106
+
107
+ =pod
108
+
109
+ =encoding UTF-8
110
+
111
+ =head1 NAME
112
+
113
+ Test2::API::Stack - Object to manage a stack of L<Test2::Hub>
114
+ instances.
115
+
116
+ =head1 ***INTERNALS NOTE***
117
+
118
+ B<The internals of this package are subject to change at any time!> The public
119
+ methods provided will not change in backwards incompatible ways, but the
120
+ underlying implementation details might. B<Do not break encapsulation here!>
121
+
122
+ =head1 DESCRIPTION
123
+
124
+ This module is used to represent and manage a stack of L<Test2::Hub>
125
+ objects. Hubs are usually in a stack so that you can push a new hub into place
126
+ that can intercept and handle events differently than the primary hub.
127
+
128
+ =head1 SYNOPSIS
129
+
130
+ my $stack = Test2::API::Stack->new;
131
+ my $hub = $stack->top;
132
+
133
+ =head1 METHODS
134
+
135
+ =over 4
136
+
137
+ =item $stack = Test2::API::Stack->new()
138
+
139
+ This will create a new empty stack instance. All arguments are ignored.
140
+
141
+ =item $hub = $stack->new_hub()
142
+
143
+ =item $hub = $stack->new_hub(%params)
144
+
145
+ =item $hub = $stack->new_hub(%params, class => $class)
146
+
147
+ This will generate a new hub and push it to the top of the stack. Optionally
148
+ you can provide arguments that will be passed into the constructor for the
149
+ L<Test2::Hub> object.
150
+
151
+ If you specify the C<< 'class' => $class >> argument, the new hub will be an
152
+ instance of the specified class.
153
+
154
+ Unless your parameters specify C<'formatter'> or C<'ipc'> arguments, the
155
+ formatter and IPC instance will be inherited from the current top hub. You can
156
+ set the parameters to C<undef> to avoid having a formatter or IPC instance.
157
+
158
+ If there is no top hub, and you do not ask to leave IPC and formatter undef,
159
+ then a new formatter will be created, and the IPC instance from
160
+ L<Test2::API> will be used.
161
+
162
+ =item $hub = $stack->top()
163
+
164
+ This will return the top hub from the stack. If there is no top hub yet this
165
+ will create it.
166
+
167
+ =item $hub = $stack->peek()
168
+
169
+ This will return the top hub from the stack. If there is no top hub yet this
170
+ will return undef.
171
+
172
+ =item $stack->cull
173
+
174
+ This will call C<< $hub->cull >> on all hubs in the stack.
175
+
176
+ =item @hubs = $stack->all
177
+
178
+ This will return all the hubs in the stack as a list.
179
+
180
+ =item $stack->clear
181
+
182
+ This will completely remove all hubs from the stack. Normally you do not want
183
+ to do this, but there are a few valid reasons for it.
184
+
185
+ =item $stack->push($hub)
186
+
187
+ This will push the new hub onto the stack.
188
+
189
+ =item $stack->pop($hub)
190
+
191
+ This will pop a hub from the stack, if the hub at the top of the stack does not
192
+ match the hub you expect (passed in as an argument) it will throw an exception.
193
+
194
+ =back
195
+
196
+ =head1 SOURCE
197
+
198
+ The source code repository for Test2 can be found at
199
+ L<https://github.com/Test-More/test-more/>.
200
+
201
+ =head1 MAINTAINERS
202
+
203
+ =over 4
204
+
205
+ =item Chad Granum E<lt>exodist@cpan.orgE<gt>
206
+
207
+ =back
208
+
209
+ =head1 AUTHORS
210
+
211
+ =over 4
212
+
213
+ =item Chad Granum E<lt>exodist@cpan.orgE<gt>
214
+
215
+ =back
216
+
217
+ =head1 COPYRIGHT
218
+
219
+ Copyright Chad Granum E<lt>exodist@cpan.orgE<gt>.
220
+
221
+ This program is free software; you can redistribute it and/or
222
+ modify it under the same terms as Perl itself.
223
+
224
+ See L<https://dev.perl.org/licenses/>
225
+
226
+ =cut
git/usr/share/perl5/core_perl/Test2/AsyncSubtest/Event/Attach.pm ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package Test2::AsyncSubtest::Event::Attach;
2
+ use strict;
3
+ use warnings;
4
+
5
+ our $VERSION = '1.302210';
6
+
7
+ use base 'Test2::Event';
8
+ use Test2::Util::HashBase qw/id/;
9
+
10
+ sub no_display { 1 }
11
+
12
+ sub callback {
13
+ my $self = shift;
14
+ my ($hub) = @_;
15
+
16
+ my $id = $self->{+ID};
17
+ my $ids = $hub->ast_ids;
18
+
19
+ unless (defined $ids->{$id}) {
20
+ require Test2::Event::Exception;
21
+ my $trace = $self->trace;
22
+ $hub->send(
23
+ Test2::Event::Exception->new(
24
+ trace => $trace,
25
+ error => "Invalid AsyncSubtest attach ID: $id at " . $trace->debug . "\n",
26
+ )
27
+ );
28
+ return;
29
+ }
30
+
31
+ if ($ids->{$id}++) {
32
+ require Test2::Event::Exception;
33
+ my $trace = $self->trace;
34
+ $hub->send(
35
+ Test2::Event::Exception->new(
36
+ trace => $trace,
37
+ error => "AsyncSubtest ID $id already attached at " . $trace->debug . "\n",
38
+ )
39
+ );
40
+ return;
41
+ }
42
+ }
43
+
44
+ 1;
45
+
46
+ __END__
47
+
48
+ =pod
49
+
50
+ =encoding UTF-8
51
+
52
+ =head1 NAME
53
+
54
+ Test2::AsyncSubtest::Event::Attach - Event to attach a subtest to the parent.
55
+
56
+ =head1 DESCRIPTION
57
+
58
+ Used internally by L<Test2::AsyncSubtest>. No user serviceable parts inside.
59
+
60
+ =head1 SOURCE
61
+
62
+ The source code repository for Test2-AsyncSubtest can be found at
63
+ F<https://github.com/Test-More/test-more/>.
64
+
65
+ =head1 MAINTAINERS
66
+
67
+ =over 4
68
+
69
+ =item Chad Granum E<lt>exodist@cpan.orgE<gt>
70
+
71
+ =back
72
+
73
+ =head1 AUTHORS
74
+
75
+ =over 4
76
+
77
+ =item Chad Granum E<lt>exodist@cpan.orgE<gt>
78
+
79
+ =back
80
+
81
+ =head1 COPYRIGHT
82
+
83
+ Copyright Chad Granum E<lt>exodist7@gmail.comE<gt>.
84
+
85
+ This program is free software; you can redistribute it and/or
86
+ modify it under the same terms as Perl itself.
87
+
88
+ See F<http://dev.perl.org/licenses/>
89
+
90
+ =cut
git/usr/share/perl5/core_perl/Test2/AsyncSubtest/Event/Detach.pm ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package Test2::AsyncSubtest::Event::Detach;
2
+ use strict;
3
+ use warnings;
4
+
5
+ our $VERSION = '1.302210';
6
+
7
+ use base 'Test2::Event';
8
+ use Test2::Util::HashBase qw/id/;
9
+
10
+ sub no_display { 1 }
11
+
12
+ sub callback {
13
+ my $self = shift;
14
+ my ($hub) = @_;
15
+
16
+ my $id = $self->{+ID};
17
+ my $ids = $hub->ast_ids;
18
+
19
+ unless (defined $ids->{$id}) {
20
+ require Test2::Event::Exception;
21
+ my $trace = $self->trace;
22
+ $hub->send(
23
+ Test2::Event::Exception->new(
24
+ trace => $trace,
25
+ error => "Invalid AsyncSubtest detach ID: $id at " . $trace->debug . "\n",
26
+ )
27
+ );
28
+ return;
29
+ }
30
+
31
+ unless (delete $ids->{$id}) {
32
+ require Test2::Event::Exception;
33
+ my $trace = $self->trace;
34
+ $hub->send(
35
+ Test2::Event::Exception->new(
36
+ trace => $trace,
37
+ error => "AsyncSubtest ID $id is not attached at " . $trace->debug . "\n",
38
+ )
39
+ );
40
+ return;
41
+ }
42
+ }
43
+
44
+ 1;
45
+
46
+ __END__
47
+
48
+ =pod
49
+
50
+ =encoding UTF-8
51
+
52
+ =head1 NAME
53
+
54
+ Test2::AsyncSubtest::Event::Detach - Event to detach a subtest from the parent.
55
+
56
+ =head1 DESCRIPTION
57
+
58
+ Used internally by L<Test2::AsyncSubtest>. No user serviceable parts inside.
59
+
60
+ =head1 SOURCE
61
+
62
+ The source code repository for Test2-AsyncSubtest can be found at
63
+ F<https://github.com/Test-More/test-more/>.
64
+
65
+ =head1 MAINTAINERS
66
+
67
+ =over 4
68
+
69
+ =item Chad Granum E<lt>exodist@cpan.orgE<gt>
70
+
71
+ =back
72
+
73
+ =head1 AUTHORS
74
+
75
+ =over 4
76
+
77
+ =item Chad Granum E<lt>exodist@cpan.orgE<gt>
78
+
79
+ =back
80
+
81
+ =head1 COPYRIGHT
82
+
83
+ Copyright Chad Granum E<lt>exodist7@gmail.comE<gt>.
84
+
85
+ This program is free software; you can redistribute it and/or
86
+ modify it under the same terms as Perl itself.
87
+
88
+ See F<http://dev.perl.org/licenses/>
89
+
90
+ =cut
git/usr/share/perl5/core_perl/Test2/AsyncSubtest/Formatter.pm ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ package Test2::AsyncSubtest::Formatter;
2
+ use strict;
3
+ use warnings;
4
+
5
+ our $VERSION = '1.302210';
6
+
7
+ die "Should not load this anymore";
8
+
9
+ 1;
git/usr/share/perl5/core_perl/Test2/AsyncSubtest/Hub.pm ADDED
@@ -0,0 +1,119 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package Test2::AsyncSubtest::Hub;
2
+ use strict;
3
+ use warnings;
4
+
5
+ our $VERSION = '1.302210';
6
+
7
+ use base 'Test2::Hub::Subtest';
8
+ use Test2::Util::HashBase qw/ast_ids ast/;
9
+ use Test2::Util qw/get_tid/;
10
+
11
+ sub init {
12
+ my $self = shift;
13
+
14
+ $self->SUPER::init();
15
+
16
+ if (my $format = $self->format) {
17
+ my $hide = $format->can('hide_buffered') ? $format->hide_buffered : 1;
18
+ $self->format(undef) if $hide;
19
+ }
20
+ }
21
+
22
+ sub inherit {
23
+ my $self = shift;
24
+ my ($from, %params) = @_;
25
+
26
+ if (my $ls = $from->{+_LISTENERS}) {
27
+ push @{$self->{+_LISTENERS}} => grep { $_->{inherit} } @$ls;
28
+ }
29
+
30
+ if (my $pfs = $from->{+_PRE_FILTERS}) {
31
+ push @{$self->{+_PRE_FILTERS}} => grep { $_->{inherit} } @$pfs;
32
+ }
33
+
34
+ if (my $fs = $from->{+_FILTERS}) {
35
+ push @{$self->{+_FILTERS}} => grep { $_->{inherit} } @$fs;
36
+ }
37
+ }
38
+
39
+ sub send {
40
+ my $self = shift;
41
+ my ($e) = @_;
42
+
43
+ if (my $ast = $self->ast) {
44
+ if ($$ != $ast->pid || get_tid != $ast->tid) {
45
+ if (my $plan = $e->facet_data->{plan}) {
46
+ unless ($plan->{skip}) {
47
+ my $trace = $e->facet_data->{trace};
48
+ bless($trace, 'Test2::EventFacet::Trace');
49
+ $trace->alert("A plan should not be set inside an async-subtest (did you call done_testing()?)");
50
+ return;
51
+ }
52
+ }
53
+ }
54
+ }
55
+
56
+ return $self->SUPER::send($e);
57
+ }
58
+
59
+ 1;
60
+
61
+ __END__
62
+
63
+ =pod
64
+
65
+ =encoding UTF-8
66
+
67
+ =head1 NAME
68
+
69
+ Test2::AsyncSubtest::Hub - Hub used by async subtests.
70
+
71
+ =head1 DESCRIPTION
72
+
73
+ This is a subclass of L<Test2::Hub::Subtest> used for async subtests.
74
+
75
+ =head1 SYNOPSIS
76
+
77
+ You should not use this directly.
78
+
79
+ =head1 METHODS
80
+
81
+ =over 4
82
+
83
+ =item $ast = $hub->ast
84
+
85
+ Get the L<Test2::AsyncSubtest> object to which this hub is bound.
86
+
87
+ =back
88
+
89
+ =head1 SOURCE
90
+
91
+ The source code repository for Test2-AsyncSubtest can be found at
92
+ F<https://github.com/Test-More/test-more/>.
93
+
94
+ =head1 MAINTAINERS
95
+
96
+ =over 4
97
+
98
+ =item Chad Granum E<lt>exodist@cpan.orgE<gt>
99
+
100
+ =back
101
+
102
+ =head1 AUTHORS
103
+
104
+ =over 4
105
+
106
+ =item Chad Granum E<lt>exodist@cpan.orgE<gt>
107
+
108
+ =back
109
+
110
+ =head1 COPYRIGHT
111
+
112
+ Copyright Chad Granum E<lt>exodist7@gmail.comE<gt>.
113
+
114
+ This program is free software; you can redistribute it and/or
115
+ modify it under the same terms as Perl itself.
116
+
117
+ See F<http://dev.perl.org/licenses/>
118
+
119
+ =cut
git/usr/share/perl5/core_perl/Test2/Bundle/Extended.pm ADDED
@@ -0,0 +1,487 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package Test2::Bundle::Extended;
2
+ use strict;
3
+ use warnings;
4
+
5
+ use Test2::V0;
6
+
7
+ our $VERSION = '1.302210';
8
+
9
+ BEGIN {
10
+ push @Test2::Bundle::Extended::ISA => 'Test2::V0';
11
+ no warnings 'once';
12
+ *EXPORT = \@Test2::V0::EXPORT;
13
+ }
14
+
15
+ our %EXPORT_TAGS = (
16
+ 'v1' => \@Test2::Bundle::Extended::EXPORT,
17
+ );
18
+
19
+ 1;
20
+
21
+ __END__
22
+
23
+ =pod
24
+
25
+ =encoding UTF-8
26
+
27
+ =head1 NAME
28
+
29
+ Test2::Bundle::Extended - Old name for Test2::V0
30
+
31
+ =head1 *** DEPRECATED ***
32
+
33
+ This bundle has been renamed to L<Test2::V0>, in which the C<':v1'> tag has
34
+ been removed as unnecessary.
35
+
36
+ =head1 DESCRIPTION
37
+
38
+ This is the big-daddy bundle. This bundle includes nearly every tool, and
39
+ several plugins, that the Test2 author uses. This bundle is used
40
+ extensively to test L<Test2::Suite> itself.
41
+
42
+ =head1 SYNOPSIS
43
+
44
+ use Test2::Bundle::Extended ':v1';
45
+
46
+ ok(1, "pass");
47
+
48
+ ...
49
+
50
+ done_testing;
51
+
52
+ =head1 RESOLVING CONFLICTS WITH MOOSE
53
+
54
+ use Test2::Bundle::Extended '!meta';
55
+
56
+ L<Moose> and L<Test2::Bundle::Extended> both export very different C<meta()>
57
+ subs. Adding C<'!meta'> to the import args will prevent the sub from being
58
+ imported. This bundle also exports the sub under the name C<meta_check()> so
59
+ you can use that spelling as an alternative.
60
+
61
+ =head2 TAGS
62
+
63
+ =over 4
64
+
65
+ =item :v1
66
+
67
+ =item :DEFAULT
68
+
69
+ The following are all identical:
70
+
71
+ use Test2::Bundle::Extended;
72
+
73
+ use Test2::Bundle::Extended ':v1';
74
+
75
+ use Test2::Bundle::Extended ':DEFAULT';
76
+
77
+ =back
78
+
79
+ =head2 RENAMING ON IMPORT
80
+
81
+ use Test2::Bundle::Extended ':v1', '!ok', ok => {-as => 'my_ok'};
82
+
83
+ This bundle uses L<Importer> for exporting, as such you can use any arguments
84
+ it accepts.
85
+
86
+ Explanation:
87
+
88
+ =over 4
89
+
90
+ =item ':v1'
91
+
92
+ Use the default tag, all default exports.
93
+
94
+ =item '!ok'
95
+
96
+ Do not export C<ok()>
97
+
98
+ =item ok => {-as => 'my_ok'}
99
+
100
+ Actually, go ahead and import C<ok()> but under the name C<my_ok()>.
101
+
102
+ =back
103
+
104
+ If you did not add the C<'!ok'> argument then you would have both C<ok()> and
105
+ C<my_ok()>
106
+
107
+ =head1 PRAGMAS
108
+
109
+ All of these can be disabled via individual import arguments, or by the
110
+ C<-no_pragmas> argument.
111
+
112
+ use Test2::Bundle::Extended -no_pragmas => 1;
113
+
114
+ =head2 STRICT
115
+
116
+ L<strict> is turned on for you. You can disable this with the C<-no_strict> or
117
+ C<-no_pragmas> import arguments:
118
+
119
+ use Test2::Bundle::Extended -no_strict => 1;
120
+
121
+ =head2 WARNINGS
122
+
123
+ L<warnings> are turned on for you. You can disable this with the
124
+ C<-no_warnings> or C<-no_pragmas> import arguments:
125
+
126
+ use Test2::Bundle::Extended -no_warnings => 1;
127
+
128
+ =head2 UTF8
129
+
130
+ This is actually done via the L<Test2::Plugin::UTF8> plugin, see the
131
+ L</PLUGINS> section for details.
132
+
133
+ B<Note:> C<< -no_pragmas => 1 >> will turn off the entire plugin.
134
+
135
+ =head1 PLUGINS
136
+
137
+ =head2 SRAND
138
+
139
+ See L<Test2::Plugin::SRand>.
140
+
141
+ This will set the random seed to today's date. You can provide an alternate seed
142
+ with the C<-srand> import option:
143
+
144
+ use Test2::Bundle::Extended -srand => 1234;
145
+
146
+ =head2 UTF8
147
+
148
+ See L<Test2::Plugin::UTF8>.
149
+
150
+ This will set the file, and all output handles (including formatter handles), to
151
+ utf8. This will turn on the utf8 pragma for the current scope.
152
+
153
+ This can be disabled using the C<< -no_utf8 => 1 >> or C<< -no_pragmas => 1 >>
154
+ import arguments.
155
+
156
+ use Test2::Bundle::Extended -no_utf8 => 1;
157
+
158
+ =head2 EXIT SUMMARY
159
+
160
+ See L<Test2::Plugin::ExitSummary>.
161
+
162
+ This plugin has no configuration.
163
+
164
+ =head1 API FUNCTIONS
165
+
166
+ See L<Test2::API> for these
167
+
168
+ =over 4
169
+
170
+ =item $ctx = context()
171
+
172
+ =item $events = intercept { ... }
173
+
174
+ =back
175
+
176
+ =head1 TOOLS
177
+
178
+ =head2 TARGET
179
+
180
+ See L<Test2::Tools::Target>.
181
+
182
+ You can specify a target class with the C<-target> import argument. If you do
183
+ not provide a target then C<$CLASS> and C<CLASS()> will not be imported.
184
+
185
+ use Test2::Bundle::Extended -target => 'My::Class';
186
+
187
+ print $CLASS; # My::Class
188
+ print CLASS(); # My::Class
189
+
190
+ Or you can specify names:
191
+
192
+ use Test2::Bundle::Extended -target => { pkg => 'Some::Package' };
193
+
194
+ pkg()->xxx; # Call 'xxx' on Some::Package
195
+ $pkg->xxx; # Same
196
+
197
+ =over 4
198
+
199
+ =item $CLASS
200
+
201
+ Package variable that contains the target class name.
202
+
203
+ =item $class = CLASS()
204
+
205
+ Constant function that returns the target class name.
206
+
207
+ =back
208
+
209
+ =head2 DEFER
210
+
211
+ See L<Test2::Tools::Defer>.
212
+
213
+ =over 4
214
+
215
+ =item def $func => @args;
216
+
217
+ =item do_def()
218
+
219
+ =back
220
+
221
+ =head2 BASIC
222
+
223
+ See L<Test2::Tools::Basic>.
224
+
225
+ =over 4
226
+
227
+ =item ok($bool, $name)
228
+
229
+ =item pass($name)
230
+
231
+ =item fail($name)
232
+
233
+ =item diag($message)
234
+
235
+ =item note($message)
236
+
237
+ =item $todo = todo($reason)
238
+
239
+ =item todo $reason => sub { ... }
240
+
241
+ =item skip($reason, $count)
242
+
243
+ =item plan($count)
244
+
245
+ =item skip_all($reason)
246
+
247
+ =item done_testing()
248
+
249
+ =item bail_out($reason)
250
+
251
+ =back
252
+
253
+ =head2 COMPARE
254
+
255
+ See L<Test2::Tools::Compare>.
256
+
257
+ =over 4
258
+
259
+ =item is($got, $want, $name)
260
+
261
+ =item isnt($got, $do_not_want, $name)
262
+
263
+ =item like($got, qr/match/, $name)
264
+
265
+ =item unlike($got, qr/mismatch/, $name)
266
+
267
+ =item $check = match(qr/pattern/)
268
+
269
+ =item $check = mismatch(qr/pattern/)
270
+
271
+ =item $check = validator(sub { return $bool })
272
+
273
+ =item $check = hash { ... }
274
+
275
+ =item $check = array { ... }
276
+
277
+ =item $check = bag { ... }
278
+
279
+ =item $check = object { ... }
280
+
281
+ =item $check = meta { ... }
282
+
283
+ =item $check = number($num)
284
+
285
+ =item $check = string($str)
286
+
287
+ =item $check = check_isa($class_name)
288
+
289
+ =item $check = in_set(@things)
290
+
291
+ =item $check = not_in_set(@things)
292
+
293
+ =item $check = check_set(@things)
294
+
295
+ =item $check = item($thing)
296
+
297
+ =item $check = item($idx => $thing)
298
+
299
+ =item $check = field($name => $val)
300
+
301
+ =item $check = call($method => $expect)
302
+
303
+ =item $check = call_list($method => $expect)
304
+
305
+ =item $check = call_hash($method => $expect)
306
+
307
+ =item $check = prop($name => $expect)
308
+
309
+ =item $check = check($thing)
310
+
311
+ =item $check = T()
312
+
313
+ =item $check = F()
314
+
315
+ =item $check = D()
316
+
317
+ =item $check = DF()
318
+
319
+ =item $check = E()
320
+
321
+ =item $check = DNE()
322
+
323
+ =item $check = FDNE()
324
+
325
+ =item $check = U()
326
+
327
+ =item $check = L()
328
+
329
+ =item $check = exact_ref($ref)
330
+
331
+ =item end()
332
+
333
+ =item etc()
334
+
335
+ =item filter_items { grep { ... } @_ }
336
+
337
+ =item $check = event $type => ...
338
+
339
+ =item @checks = fail_events $type => ...
340
+
341
+ =back
342
+
343
+ =head2 CLASSIC COMPARE
344
+
345
+ See L<Test2::Tools::ClassicCompare>.
346
+
347
+ =over 4
348
+
349
+ =item cmp_ok($got, $op, $want, $name)
350
+
351
+ =back
352
+
353
+ =head2 SUBTEST
354
+
355
+ See L<Test2::Tools::Subtest>.
356
+
357
+ =over 4
358
+
359
+ =item subtest $name => sub { ... }
360
+
361
+ (Note: This is called C<subtest_buffered()> in the Tools module.)
362
+
363
+ =back
364
+
365
+ =head2 CLASS
366
+
367
+ See L<Test2::Tools::Class>.
368
+
369
+ =over 4
370
+
371
+ =item can_ok($thing, @methods)
372
+
373
+ =item isa_ok($thing, @classes)
374
+
375
+ =item DOES_ok($thing, @roles)
376
+
377
+ =back
378
+
379
+ =head2 ENCODING
380
+
381
+ See L<Test2::Tools::Encoding>.
382
+
383
+ =over 4
384
+
385
+ =item set_encoding($encoding)
386
+
387
+ =back
388
+
389
+ =head2 EXPORTS
390
+
391
+ See L<Test2::Tools::Exports>.
392
+
393
+ =over 4
394
+
395
+ =item imported_ok('function', '$scalar', ...)
396
+
397
+ =item not_imported_ok('function', '$scalar', ...)
398
+
399
+ =back
400
+
401
+ =head2 REF
402
+
403
+ See L<Test2::Tools::Ref>.
404
+
405
+ =over 4
406
+
407
+ =item ref_ok($ref, $type)
408
+
409
+ =item ref_is($got, $want)
410
+
411
+ =item ref_is_not($got, $do_not_want)
412
+
413
+ =back
414
+
415
+ =head2 MOCK
416
+
417
+ See L<Test2::Tools::Mock>.
418
+
419
+ =over 4
420
+
421
+ =item $control = mock ...
422
+
423
+ =item $bool = mocked($thing)
424
+
425
+ =back
426
+
427
+ =head2 EXCEPTION
428
+
429
+ See L<Test2::Tools::Exception>.
430
+
431
+ =over 4
432
+
433
+ =item $exception = dies { ... }
434
+
435
+ =item $bool = lives { ... }
436
+
437
+ =item $bool = try_ok { ... }
438
+
439
+ =back
440
+
441
+ =head2 WARNINGS
442
+
443
+ See L<Test2::Tools::Warnings>.
444
+
445
+ =over 4
446
+
447
+ =item $count = warns { ... }
448
+
449
+ =item $warning = warning { ... }
450
+
451
+ =item $warnings_ref = warnings { ... }
452
+
453
+ =item $bool = no_warnings { ... }
454
+
455
+ =back
456
+
457
+ =head1 SOURCE
458
+
459
+ The source code repository for Test2-Suite can be found at
460
+ F<https://github.com/Test-More/test-more/>.
461
+
462
+ =head1 MAINTAINERS
463
+
464
+ =over 4
465
+
466
+ =item Chad Granum E<lt>exodist@cpan.orgE<gt>
467
+
468
+ =back
469
+
470
+ =head1 AUTHORS
471
+
472
+ =over 4
473
+
474
+ =item Chad Granum E<lt>exodist@cpan.orgE<gt>
475
+
476
+ =back
477
+
478
+ =head1 COPYRIGHT
479
+
480
+ Copyright Chad Granum E<lt>exodist@cpan.orgE<gt>.
481
+
482
+ This program is free software; you can redistribute it and/or
483
+ modify it under the same terms as Perl itself.
484
+
485
+ See F<http://dev.perl.org/licenses/>
486
+
487
+ =cut
git/usr/share/perl5/core_perl/Test2/Bundle/More.pm ADDED
@@ -0,0 +1,241 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package Test2::Bundle::More;
2
+ use strict;
3
+ use warnings;
4
+
5
+ our $VERSION = '1.302210';
6
+
7
+ use Test2::Plugin::ExitSummary;
8
+
9
+ use Test2::Tools::Basic qw{
10
+ ok pass fail skip todo diag note
11
+ plan skip_all done_testing bail_out
12
+ };
13
+
14
+ use Test2::Tools::ClassicCompare qw{
15
+ is is_deeply isnt like unlike cmp_ok
16
+ };
17
+
18
+ use Test2::Tools::Class qw/can_ok isa_ok/;
19
+ use Test2::Tools::Subtest qw/subtest_streamed/;
20
+
21
+ BEGIN {
22
+ *BAIL_OUT = \&bail_out;
23
+ *subtest = \&subtest_streamed;
24
+ }
25
+
26
+ our @EXPORT = qw{
27
+ ok pass fail skip todo diag note
28
+ plan skip_all done_testing BAIL_OUT
29
+
30
+ is isnt like unlike is_deeply cmp_ok
31
+
32
+ isa_ok can_ok
33
+
34
+ subtest
35
+ };
36
+ use base 'Exporter';
37
+
38
+ 1;
39
+
40
+ __END__
41
+
42
+ =pod
43
+
44
+ =encoding UTF-8
45
+
46
+ =head1 NAME
47
+
48
+ Test2::Bundle::More - ALMOST a drop-in replacement for Test::More.
49
+
50
+ =head1 DESCRIPTION
51
+
52
+ This bundle is intended to be a (mostly) drop-in replacement for
53
+ L<Test::More>. See L<"KEY DIFFERENCES FROM Test::More"> for details.
54
+
55
+ =head1 SYNOPSIS
56
+
57
+ use Test2::Bundle::More;
58
+
59
+ ok(1, "pass");
60
+
61
+ ...
62
+
63
+ done_testing;
64
+
65
+ =head1 PLUGINS
66
+
67
+ This loads L<Test2::Plugin::ExitSummary>.
68
+
69
+ =head1 TOOLS
70
+
71
+ These are from L<Test2::Tools::Basic>. See L<Test2::Tools::Basic> for details.
72
+
73
+ =over 4
74
+
75
+ =item ok($bool, $name)
76
+
77
+ =item pass($name)
78
+
79
+ =item fail($name)
80
+
81
+ =item skip($why, $count)
82
+
83
+ =item $todo = todo($why)
84
+
85
+ =item diag($message)
86
+
87
+ =item note($message)
88
+
89
+ =item plan($count)
90
+
91
+ =item skip_all($why)
92
+
93
+ =item done_testing()
94
+
95
+ =item BAIL_OUT($why)
96
+
97
+ =back
98
+
99
+ These are from L<Test2::Tools::ClassicCompare>. See
100
+ L<Test2::Tools::ClassicCompare> for details.
101
+
102
+ =over 4
103
+
104
+ =item is($got, $want, $name)
105
+
106
+ =item isnt($got, $donotwant, $name)
107
+
108
+ =item like($got, qr/match/, $name)
109
+
110
+ =item unlike($got, qr/mismatch/, $name)
111
+
112
+ =item is_deeply($got, $want, "Deep compare")
113
+
114
+ =item cmp_ok($got, $op, $want, $name)
115
+
116
+ =back
117
+
118
+ These are from L<Test2::Tools::Class>. See L<Test2::Tools::Class> for details.
119
+
120
+ =over 4
121
+
122
+ =item isa_ok($thing, @classes)
123
+
124
+ =item can_ok($thing, @subs)
125
+
126
+ =back
127
+
128
+ This is from L<Test2::Tools::Subtest>. It is called C<subtest_streamed()> in
129
+ that package.
130
+
131
+ =over 4
132
+
133
+ =item subtest $name => sub { ... }
134
+
135
+ =back
136
+
137
+ =head1 KEY DIFFERENCES FROM Test::More
138
+
139
+ =over 4
140
+
141
+ =item You cannot plan at import.
142
+
143
+ THIS WILL B<NOT> WORK:
144
+
145
+ use Test2::Bundle::More tests => 5;
146
+
147
+ Instead you must plan in a separate statement:
148
+
149
+ use Test2::Bundle::More;
150
+ plan 5;
151
+
152
+ =item You have three subs imported for use in planning
153
+
154
+ Use C<plan($count)>, C<skip_all($reason)>, or C<done_testing()> for your
155
+ planning.
156
+
157
+ =item isa_ok accepts different arguments
158
+
159
+ C<isa_ok> in Test::More was:
160
+
161
+ isa_ok($thing, $isa, $alt_thing_name);
162
+
163
+ This was very inconsistent with tools like C<can_ok($thing, @subs)>.
164
+
165
+ In Test2::Bundle::More, C<isa_ok()> takes a C<$thing> and a list of C<@isa>.
166
+
167
+ isa_ok($thing, $class1, $class2, ...);
168
+
169
+ =back
170
+
171
+ =head2 THESE FUNCTIONS AND VARIABLES HAVE BEEN REMOVED
172
+
173
+ =over 4
174
+
175
+ =item $TODO
176
+
177
+ See C<todo()>.
178
+
179
+ =item use_ok()
180
+
181
+ =item require_ok()
182
+
183
+ These are not necessary. Use C<use> and C<require> directly. If there is an
184
+ error loading the module the test will catch the error and fail.
185
+
186
+ =item todo_skip()
187
+
188
+ Not necessary.
189
+
190
+ =item eq_array()
191
+
192
+ =item eq_hash()
193
+
194
+ =item eq_set()
195
+
196
+ Discouraged in Test::More.
197
+
198
+ =item explain()
199
+
200
+ This started a fight between Test developers, who may now each write their own
201
+ implementations in L<Test2>. (See explain in L<Test::Most> vs L<Test::More>.
202
+ Hint: Test::Most wrote it first, then Test::More added it, but broke
203
+ compatibility).
204
+
205
+ =item new_ok()
206
+
207
+ Not necessary.
208
+
209
+ =back
210
+
211
+ =head1 SOURCE
212
+
213
+ The source code repository for Test2-Suite can be found at
214
+ F<https://github.com/Test-More/test-more/>.
215
+
216
+ =head1 MAINTAINERS
217
+
218
+ =over 4
219
+
220
+ =item Chad Granum E<lt>exodist@cpan.orgE<gt>
221
+
222
+ =back
223
+
224
+ =head1 AUTHORS
225
+
226
+ =over 4
227
+
228
+ =item Chad Granum E<lt>exodist@cpan.orgE<gt>
229
+
230
+ =back
231
+
232
+ =head1 COPYRIGHT
233
+
234
+ Copyright Chad Granum E<lt>exodist@cpan.orgE<gt>.
235
+
236
+ This program is free software; you can redistribute it and/or
237
+ modify it under the same terms as Perl itself.
238
+
239
+ See F<http://dev.perl.org/licenses/>
240
+
241
+ =cut