blib/lib/Jasonify.pm

filter: Statementstmt 89.1% 180 / 202 Branchbran 63.5% 89 / 140 Conditioncond 83.3% 15 / 18 MC/DCmcdc 66.6% 6 / 9 Subroutinesub 79.6% 47 / 59 Podpod 76.9% 10 / 13 totaltotal 78.6% 347 / 441 CC 77 SCAR 25.5
CC
77
Cov
79%
objectify
50.2
negate
30.0
_scalarify
24.4
CRAP 12.8
↑ Summary
1 2 ▶use v5.14;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 package Jasonify v0.20.060;
5 # ABSTRACT: Just Another Serialized Object Notation library.
6  
7  
8 2 ▶use Carp (); #qw( carp );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Datify v0.20.060 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use LooksLike v0.20.060 (); #qw( number representation );
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use Scalar::Util (); #qw( blessed reftype );
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use String::Tools (); #qw( subst );
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 2 ▶use parent 'Datify';
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16  
17  
18  
19 ### Accessor ###
20  
21  
22  
23  
24 ### Setter ###
25  
26  
27  
28  
29 2 __PACKAGE__->set(
30 # Varify/Encode options
31 #name => '',
32 #assign => undef,
33 #list => undef,
34 list_sep => ', ',
35 beautify => undef,
36 );
37  
38  
39  
40 2 __PACKAGE__->set(
41 # Undefify options
42 null => 'null',
43 );
44  
45  
46  
47 2 __PACKAGE__->set(
48 # Booleanify options
49 false => 'false',
50 true => 'true',
51 );
52  
53  
54  
55 __PACKAGE__->set(
56 # Stringify options
57 quote => '"',
58 #quote1 => undef,
59 quote2 => '"',
60 #q1 => undef,
61 #q2 => undef,
62 #sigils => undef,
63 longstr => -1,
64 #encode1 => undef,
65 encode2 => {
66 134 map( { $_ => sprintf( '\\u%04x', $_ ) }
67 0x00 .. 0x1f, 0x7f, # Control characters (C0)
68 0x80 .. 0x9f, # Control characters (C1)
69 0x2028, 0x2029, # Characters not allowed by Javascript
70 ),
71 # Special cases
72 2 map( { ord( eval qq!"$_"! ) => $_ } qw( \b \t \n \r \" \\\\ ) ),
73 utf => 16,
74 byte => '\\u00%02x',
75 wide => '\\u%04x',
76 },
77 #qpairs => undef,
78 #qquotes => undef,
79 );
80  
81  
82  
83 2 __PACKAGE__->set(
84 # Numify options
85 infinite => '"Infinity"',
86 -infinite => '"-Infinity"',
87 nonnumber => '"NaN"',
88 #num_sep => undef,
89 );
90  
91  
92  
93 2 __PACKAGE__->set(
94 # Lvalueify options
95 lvalue => '$lvalue',
96 );
97  
98  
99  
100 2 __PACKAGE__->set(
101 # Vstringify options
102 vformat => '"\\u%0*v4x"',
103 vsep => '\\u',
104 );
105  
106  
107 #=option Regexpify options
108 #
109 #=over
110 #
111 #=item ...
112 #
113 #=back
114 #
115 #=cut
116 #
117 #__PACKAGE__->set(
118 # # Regexpify options
119 # #quote3 => undef,
120 # #q3 => undef,
121 # #encode3 => undef,
122 #);
123  
124  
125  
126 2 __PACKAGE__->set(
127 # Arrayify options
128 array_ref => '[$_]',
129 );
130  
131  
132  
133 2 __PACKAGE__->set(
134 # Hashify options
135 hash_ref => '{$_}',
136 pair => '$key : $value',
137 keysort => \&Datify::keysort,
138 keyfilter => undef,
139 keyfilterdefault => 1,
140 #keywords => undef,
141 );
142  
143  
144  
145 2 __PACKAGE__->set(
146 # Objectify options
147 json_method => 'TO_JSON',
148 object => '$data',
149 #object => '{$class_str : $data}',
150 overloads => [qw( "" 0+ )],
151 tag => undef,
152 #tag => '($class_str)$data',
153 tag_method => 'FREEZE',
154 );
155  
156  
157  
158 2 __PACKAGE__->set(
159 # Ioify options
160 io => 'null',
161 );
162  
163  
164  
165 2 __PACKAGE__->set(
166 # Codeify options
167 code => 'null',
168 #codename => undef,
169 #body => undef,
170 );
171  
172  
173  
174 2 __PACKAGE__->set(
175 # Refify options
176 reference => '$_',
177 dereference => '$referent$place',
178 #nested => undef,
179 );
180  
181  
182  
183 2 __PACKAGE__->set(
184 # Formatify options
185 format => 'null',
186 );
187  
188  
189  
190 # Override Datify::booleanify() for SCALAR refs
191 sub booleanify {
192 72 ▶ my $self = &Datify::self;
Subroutine booleanify: called CC=5 SCAR=16.1
Pod documented
193 72 ▶ local $_ = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 72 0 72
194 72 ▶ return $self->undefify unless defined;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_ 9 63 72
195 63 ▶ return $self->booleanify($$_) if 'SCALAR' eq ref;
Branch: 1 branch
BranchTrueFalseTotal
if "SCALAR" eq ref $_ 4 59 63
196 59 ▶ return $_ ? $Jasonify::Boolean::true : $Jasonify::Boolean::false;
Branch: 1 branch
BranchTrueFalseTotal
$_ ? : 40 19 59
197 }
198  
199  
200  
201 # Override Datify::keyify() to appropriately stringify all keys
202 sub keyify {
203 138 ▶ my $self = &Datify::self;
Subroutine keyify: called CC=2 SCAR=7.1
Pod documented
204 138 ▶ local $_ = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 138 0 138
205  
206 138 return LooksLike::representation(
207 $_,
208  
209 $_ => $self->stringify($_),
210 "infinity" => $Jasonify::Number::inf,
211 "-infinity" => $Jasonify::Number::ninf,
212 "nan" => $Jasonify::Number::nan,
213 );
214 }
215  
216 sub _objectify_via {
217 4 ▶ my $self = shift;
Subroutine _objectify_via: called CC=2 SCAR=6.9
218 4 my $object = shift;
219  
220 4 ▶ if ( my $method_name = shift ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $method_name = shift()) 2 2 4
221 2 return $object->can($method_name);
222 }
223 2 return;
224 }
225 sub _objectify_via_tag {
226 2 ▶ my $self = shift;
Subroutine _objectify_via_tag: called CC=2 SCAR=7.4
227 2 my $object = shift;
228  
229 2 ▶ my $tag_method = $self->get('tag') && $self->get('tag_method');
Condition33%1/3
$self->get('tag') && $self->get('tag_method')
!ll&&!rl&&r
200
MC/DC0%0/2
$self->get('tag') && $self->get('tag_method')
$self->get('tag') $self->get('tag_method')
Truth table33%1/3
A && B
A= $self->get('tag')B= $self->get('tag_method')
ABresult
0X0
100
111
230 2 return $self->_objectify_via( $object => $tag_method );
231 }
232 sub _objectify_via_json {
233 2 ▶ my $self = shift;
Subroutine _objectify_via_json: called CC=1 SCAR=0.0
234 2 my $object = shift;
235  
236 2 return $self->_objectify_via( $object => $self->get('json_method') );
237 }
238  
239  
240  
241 # Override Datify::objectify() to appropriately stringify objects
242 sub objectify {
243 55 ▶ my $self = &Datify::self;
Subroutine objectify: called CC=16 SCAR=39.2
Pod documented
244 55 my $object = shift;
245  
246 55 ▶ return $self->scalarify($object)
Branch: 1 branch
BranchTrueFalseTotal
unless defined(my $class = builtin::blessed($object)) 0 55 55
247 unless defined( my $class = Scalar::Util::blessed($object) );
248  
249 55 my $object_str = $self->get('object');
250  
251 55 my $data;
252 55 ▶ if (0) {
Branch: 5 branches
BranchTrueFalseTotal
if (do { my $code = $self->_find_handler($class) }) { } 53 2 55
elsif (my $tag = $self->_objectify_via_tag($object)) { } 0 2 2
elsif (my $to_json = $self->_objectify_via_json($object)) { } 0 2 2
elsif (my $method = $self->overloaded($object)) { } 0 2 2
elsif (my $attrkeyvals = $object->can('_attrkeyvals')) { } 0 2 2
253 } elsif ( my $code = $self->_find_handler($class) ) {
254 53 return $self->$code($object);
255 } elsif ( my $tag = $self->_objectify_via_tag($object) ) {
256 0 $object_str = $self->get('tag');
257 0 $data = $self->arrayify( $object->$tag('JSON') );
258 } elsif ( my $to_json = $self->_objectify_via_json($object) ) {
259 0 $data = $self->scalarify( $object->$to_json() );
260 } elsif ( my $method = $self->overloaded($object) ) {
261 0 $data = $self->scalarify( $object->$method() );
262 } elsif ( my $attrkeyvals = $object->can('_attrkeyvals') ) {
263 # TODO: Look this up via meta-objects and such.
264 0 $data = $self->hashify( $object->$attrkeyvals() );
265 } else {
266 2 $data = Scalar::Util::reftype $object;
267  
268 2 ▶ $data
Branch: 9 branches
BranchTrueFalseTotal
$data eq 'ARRAY' ? : 0 2 2
$data eq 'CODE' ? : 0 2 2
$data eq 'FORMAT' ? : 0 2 2
$data eq 'GLOB' ? : 0 2 2
$data eq 'HASH' ? : 2 0 2
$data eq 'IO' ? : 0 0 0
$data eq 'REF' ? : 0 0 0
$data eq 'REGEXP' ? : 0 0 0
$data eq 'SCALAR' ? : 0 0 0
269 = $data eq 'ARRAY' ? $self->arrayify( @$object )
270 : $data eq 'CODE' ? $self->codeify( $object )
271 : $data eq 'FORMAT' ? $self->formatify( $object )
272 : $data eq 'GLOB' ? $self->globify( $object )
273 : $data eq 'HASH' ? $self->hashify( $object )
274 : $data eq 'IO' ? $self->ioify( $object )
275 : $data eq 'REF' ? $self->scalarify( $$object )
276 : $data eq 'REGEXP' ? $self->regexpify( $object )
277 : $data eq 'SCALAR' ? $self->scalarify( $$object )
278 : $self->undefify;
279 }
280  
281 2 return String::Tools::subst(
282 $object_str,
283 class_str => $self->stringify($class),
284 class => $class,
285 data => $data,
286 );
287 }
288  
289  
290  
291 # Override Datify::regexpify() to appropriately stringify regular expressions
292 sub regexpify {
293 2 ▶ my $self = &Datify::self;
Subroutine regexpify: called CC=2 SCAR=7.1
Pod documented
294 2 ▶ local $_ = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 2 0 2
295  
296 2 return $self->stringify($_);
297 }
298  
299 # Override Datify::varify so that it throws an error
300 sub varify;
301  
302  
303  
304 # Override Datify::vstringify so that it encodes a vstring as appropriate
305 sub vstringify {
306 2 ▶ my $self = &Datify::self;
Subroutine vstringify: called CC=3 SCAR=11.7
Pod documented
307 2 ▶ local $_ = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 2 0 2
308  
309 # Encode as a vstring if vformat has been specified
310 # or as a regular string if vformat has not been specified
311 2 ▶ return $self->get('vformat')
Branch: 1 branch
BranchTrueFalseTotal
$self->get('vformat') ? : 2 0 2
312 ? $self->SUPER::vstringify($_)
313 : $self->stringify($_);
314 }
315  
316  
317  
318 # Override Datify::scalarify to properly handle all of the various types
319 sub _scalarify {
320 347 ▶ my $self = &Datify::self;
Subroutine _scalarify: called CC=22 SCAR=31.9
321 347 ▶ local $_ = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 347 0 347
322  
323 347 ▶ return $self->undefify unless defined $_;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_ 11 336 347
324  
325 336 ▶ if ( defined( my $blessed = Scalar::Util::blessed($_) ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $blessed = builtin::blessed($_))) 57 279 336
326 return
327 57 ▶ $blessed eq 'Regexp' ? $self->regexpify($_)
Branch: 1 branch
BranchTrueFalseTotal
$blessed eq 'Regexp' ? : 2 55 57
328 : $self->objectify($_);
329 }
330  
331 279 my $ref = Scalar::Util::reftype $_;
332 279 ▶ if ( not $ref ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ref) 164 115 279
333 # Handle GLOB, LVALUE, and VSTRING
334 164 my $ref2 = ref \$_;
335 return
336 164 ▶ $ref2 eq 'GLOB' ? $self->globify($_)
Branch: 4 branches
BranchTrueFalseTotal
$ref2 eq 'GLOB' ? : 0 164 164
$ref2 eq 'LVALUE' ? : 0 164 164
$ref2 eq 'VSTRING' ? : 2 162 164
$ref2 eq 'SCALAR' && LooksLike::number($_) ? : 55 107 162
Condition66%2/3
$ref2 eq "SCALAR" and LooksLike::number($_)
!ll&&!rl&&r
010755
MC/DC50%1/2
$ref2 eq "SCALAR" and LooksLike::number($_)
$ref2 eq "SCALAR" LooksLike::number($_)
Truth table66%2/3
A and B
A= $ref2 eq "SCALAR"B= LooksLike::number($_)
ABresult
0X0
100
111
337 : $ref2 eq 'LVALUE' ? $self->lvalueify($_)
338 : $ref2 eq 'VSTRING' ? $self->vstringify($_)
339 : $ref2 eq 'SCALAR' && LooksLike::number($_)
340 ? $self->numify($_)
341 : $self->stringify($_)
342 ;
343 }
344  
345 return
346 115 ▶ $ref eq 'ARRAY' ? $self->arrayify(@$_)
Branch: 11 branches
BranchTrueFalseTotal
$ref eq 'ARRAY' ? : 29 86 115
$ref eq 'CODE' ? : 3 83 86
$ref eq 'FORMAT' ? : 0 83 83
$ref eq 'GLOB' ? : 0 83 83
$ref eq 'HASH' ? : 11 72 83
$ref eq 'IO' ? : 0 72 72
$ref eq 'LVALUE' ? : 1 71 72
$ref eq 'REF' ? : 12 59 71
$ref eq 'REGEXP' ? : 0 59 59
$ref eq 'SCALAR' ? : 57 2 59
$ref eq 'VSTRING' ? : 2 0 2
347 : $ref eq 'CODE' ? $self->codeify($_)
348 : $ref eq 'FORMAT' ? $self->formatify($_)
349 : $ref eq 'GLOB' ? $self->globify($$_)
350 : $ref eq 'HASH' ? $self->hashify($_)
351 : $ref eq 'IO' ? $self->ioify($_)
352 : $ref eq 'LVALUE' ? $self->booleanify($$_)
353 : $ref eq 'REF' ? $self->refify($$_)
354 : $ref eq 'REGEXP' ? $self->regexpify($_) # ???
355 : $ref eq 'SCALAR' ? $self->booleanify($$_)
356 : $ref eq 'VSTRING' ? $self->booleanify($$_)
357 : $self->objectify($_) # ???
358 ;
359 }
360  
361  
362  
363 # TODO
364 sub decode;
365  
366  
367  
368 sub encode {
369 53 ▶ my $self = &Datify::self;
Subroutine encode: called CC=3 SCAR=11.2
Pod documented
370 53 ▶ return unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 53 53
371  
372 53 my @return = map { $self->scalarify($_) } @_;
373  
374 51 $self->_cache_reset();
375  
376 51 ▶ return @_ == 1 ? $return[0] : @return;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 ? : 51 0 51
377 }
378  
379  
380  
381 sub boolean {
382 11 ▶ &Datify::class;
Subroutine boolean: called CC=2 SCAR=6.9
Pod documented
383 11 ▶ return @_ ? Jasonify::Boolean::bool( $_[-1] ) : 'Jasonify::Boolean';
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 10 1 11
384 }
385 2 *bool = \&boolean;
386  
387  
388  
389 sub literal {
390 10 ▶ &Datify::class;
Subroutine literal: called CC=2 SCAR=6.9
Pod documented
391 10 ▶ return @_ ? Jasonify::Literal->new( $_[-1] ) : 'Jasonify::Literal';
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 9 1 10
392 }
393  
394  
395  
396 sub number {
397 13 ▶ &Datify::class;
Subroutine number: called CC=3 SCAR=11.0
Pod documented
398 13 my $count = scalar @_;
399 return
400 13 ▶ $count >= 2 ? Jasonify::Number->formatted(@_)
Branch: 2 branches
BranchTrueFalseTotal
$count >= 2 ? : 8 5 13
$count == 1 ? : 4 1 5
401 : $count == 1 ? Jasonify::Number->number(shift)
402 : 'Jasonify::Number'
403 ;
404 }
405  
406  
407  
408 sub string {
409 5 ▶ &Datify::class;
Subroutine string: called CC=2 SCAR=6.9
Pod documented
410 5 ▶ return @_ ? Jasonify::Literal->string( $_[-1] ) : 'Jasonify::Literal';
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 4 1 5
411 }
412  
413 ### Private Methods & Settings ###
414 ### Do not use these methods & settings outside of this package,
415 ### they are subject to change or disappear at any time.
416 3106 ▶sub _settings() { \state %SETTINGS }
Subroutine _settings: called CC=1 SCAR=0.0
417  
418 2 __PACKAGE__->set(
419 _cache_hit => 1, # Sets the caching to use the final representation
420 # or die if that doesn't exist
421 );
422  
423  
424 package
425 Jasonify::Literal;
426  
427 2 ▶use LooksLike (); #qw( zero );
Subroutine BEGIN: called CC=1 SCAR=0.0
428  
429 use overload
430 2 'bool' => 'bool',
431 '""' => 'as_string',
432 2 ▶ ;
Subroutine BEGIN: called CC=1 SCAR=0.0
433  
434 2 our $null = bless \do { my $null = Jasonify->get('null') }, __PACKAGE__;
435 2 our $false = bless \do { my $false = Jasonify->get('false') }, __PACKAGE__;
436 2 our $true = bless \do { my $true = Jasonify->get('true') }, __PACKAGE__;
437  
438 13 ▶sub Jasonify::jasonify_literalify { $_[1]->as_string }
Subroutine jasonify_literalify: called CC=1 SCAR=0.0
Pod undocumented
439 # OR
440 #Jasonify->add_handler( sub { $_[1]->as_string } );
441  
442 0 ▶sub null() { $null }
Subroutine null: not called CC=1 SCAR=6.9
443 0 ▶sub false() { $false }
Subroutine false: not called CC=1 SCAR=6.9
444 0 ▶sub true() { $true }
Subroutine true: not called CC=1 SCAR=6.9
445  
446 sub new {
447 26 ▶ my $class = &Datify::class;
Subroutine new: called CC=3 SCAR=11.3
448 26 my $literal = shift;
449 26 ▶ return $null unless defined($literal);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $literal 0 26 26
450 26 ▶ return $false unless length( $literal);
Branch: 1 branch
BranchTrueFalseTotal
unless length $literal 0 26 26
451 26 return bless \$literal, $class;
452 }
453 sub string {
454 4 ▶ @_ = ( shift, Jasonify->stringify(@_) );
Subroutine string: called CC=1 SCAR=0.0
455 4 goto &new;
456 }
457 #sub comment {
458 # $_[0]->new(
459 # "# " . join( "\n# ", map { split /\n/ } @_[ 1 .. $#_ ] ) . "\n" );
460 #}
461  
462 180 ▶sub as_string { ${ $_[0] } }
Subroutine as_string: called CC=1 SCAR=0.0
463 sub bool {
464 25 ▶ my $literal = ${ $_[0] };
Subroutine bool: called CC=5 SCAR=16.1
465 return
466 25 ▶ $literal ne $$null
Condition100%12/12
$literal ne $$Jasonify::Literal::null && $literal ne $$Jasonify::Literal::false && $literal ne '""' && $literal ne '"0"' && !LooksLike::zero($literal)
!ll&&!rl&&r
6415
$literal ne $$Jasonify::Literal::null and $literal ne $$Jasonify::Literal::false and $literal ne "\"\"" and $literal ne "\"0\""
!ll&&!rl&&r
4219
$literal ne $$Jasonify::Literal::null and $literal ne $$Jasonify::Literal::false and $literal ne "\"\""
!ll&&!rl&&r
2221
$literal ne $$Jasonify::Literal::null and $literal ne $$Jasonify::Literal::false
!ll&&!rl&&r
1123
MC/DC100%5/5
$literal ne $$Jasonify::Literal::null && $literal ne $$Jasonify::Literal::false && $literal ne '""' && $literal ne '"0"' && !LooksLike::zero($literal)
$literal ne $$Jasonify::Literal::null $literal ne $$Jasonify::Literal::false $literal ne "\"\"" $literal ne "\"0\"" !LooksLike::zero($literal)
Truth table100%6/6
A and B and C and D && not(E)
A= $literal ne $$Jasonify::Literal::nullB= $literal ne $$Jasonify::Literal::falseC= $literal ne "\"\""D= $literal ne "\"0\""E= !LooksLike::zero($literal)
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
467 && $literal ne $$false
468 && $literal ne '""'
469 && $literal ne '"0"'
470 && !LooksLike::zero($literal);
471 }
472  
473 package
474 Jasonify::Number;
475  
476 2 ▶use LooksLike (); #qw( number numeric representation );
Subroutine BEGIN: called CC=1 SCAR=0.0
477  
478 use overload
479 2 '0+' => 'as_num',
480 'neg' => 'negate',
481  
482 '<=>' => 'comparen',
483 'cmp' => 'compares',
484 2 ▶ ;
Subroutine BEGIN: called CC=1 SCAR=0.0
485 2 ▶use parent -norequire => 'Jasonify::Literal';
Subroutine BEGIN: called CC=1 SCAR=0.0
486  
487 2 our $nan = bless \do { my $nan = Jasonify->get('nonnumber') }, __PACKAGE__;
488 2 our $inf = bless \do { my $inf = Jasonify->get( 'infinite') }, __PACKAGE__;
489 2 our $ninf = bless \do { my $ninf = Jasonify->get('-infinite') }, __PACKAGE__;
490  
491 20 ▶sub Jasonify::jasonify_numberify { $_[1]->as_string }
Subroutine jasonify_numberify: called CC=1 SCAR=0.0
Pod undocumented
492 # OR
493 #Jasonify->add_handler( sub { $_[1]->as_string } );
494  
495 0 ▶sub nan() { $nan }
Subroutine nan: not called CC=1 SCAR=6.9
496 0 ▶sub inf() { $inf }
Subroutine inf: not called CC=1 SCAR=6.9
497 0 ▶sub ninf() { $ninf }
Subroutine ninf: not called CC=1 SCAR=6.9
498  
499 2 my $number_regex = do {
500 2 my $digit09 = '[0123456789]';
501 2 my $digit19 = '[123456789]';
502 2 my $integer = "(?:0|$digit19+$digit09*)";
503 2 my $decimal = "(?:\.$digit09+)";
504 2 qr/-?$integer$decimal?(?:[Ee][+-]?$integer)?/;
505 };
506  
507 0 ▶sub comparen { ( $_[2] ? -1 : +1 ) * ( $_[0]->as_num <=> $_[1] ) }
Subroutine comparen: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$_[2] ? : 0 0 0
508 0 ▶sub compares { ( $_[2] ? -1 : +1 ) * ( ${ $_[0] } cmp $_[1] ) }
Subroutine compares: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$_[2] ? : 0 0 0
509 0 ▶sub as_num { eval ${ $_[0] } }
Subroutine as_num: not called CC=1 SCAR=6.9
510 sub negate {
511 0 ▶ my $num = ${ $_[0] };
Subroutine negate: not called CC=5 SCAR=34.0
512 return
513 0 ▶ $num eq $$nan ? $nan
Branch: 3 branches
BranchTrueFalseTotal
$num eq $$Jasonify::Number::nan ? : 0 0 0
$num eq $$Jasonify::Number::inf ? : 0 0 0
$num eq $$Jasonify::Number::ninf ? : 0 0 0
514 : $num eq $$inf ? $ninf
515 : $num eq $$ninf ? $inf
516 0 ▶ : $_[0]->number( $num =~ s/\A(-?)/$1 ? '' : '-'/er )
Branch: 1 branch
BranchTrueFalseTotal
$1 ? : 0 0 0
517 ;
518 }
519 sub number {
520 13 ▶ my $class = &Datify::class;
Subroutine number: called CC=4 SCAR=14.9
521 13 my $num = shift;
522 13 ▶ Carp::croak( "Not a number ", $num )
Branch: 1 branch
BranchTrueFalseTotal
unless LooksLike::number($num) 0 13 13
523 unless ( LooksLike::number($num) );
524  
525 return
526 13 ▶ LooksLike::numeric($num)
Branch: 2 branches
BranchTrueFalseTotal
LooksLike::numeric($num) ? : 13 0 13
$num =~ /\A$number_regex\z/u ? : 13 0 13
527 ? $num =~ /\A$number_regex\z/
528 ? $class->new($num)
529 : Carp::croak( "Malformed number ", $num )
530 : LooksLike::representation($num);
531 }
532  
533 9 ▶sub formatted { return shift()->number( sprintf( shift(), @_ ) ) }
Subroutine formatted: called CC=1 SCAR=0.0
534 0 ▶sub integer { return shift()->formatted( '%d', shift() ) }
Subroutine integer: not called CC=1 SCAR=6.9
535 0 ▶sub float { return shift()->formatted( '%f', shift() ) }
Subroutine float: not called CC=1 SCAR=6.9
536  
537 package
538 Jasonify::Boolean;
539  
540 2 ▶use Scalar::Util (); #qw( blessed );
Subroutine BEGIN: called CC=1 SCAR=0.0
541  
542 use overload
543 2 'bool' => 'value',
544 '0+' => 'value',
545 '""' => 'as_string',
546  
547 '<=>' => 'compare',
548 'cmp' => 'compare',
549  
550 '!' => 'negate',
551 2 ▶ ;
Subroutine BEGIN: called CC=1 SCAR=0.0
552  
553 2 our $false = bless \do { my $false = 0 }, __PACKAGE__;
554 2 our $true = bless \do { my $true = 1 }, __PACKAGE__;
555  
556 20 ▶sub Jasonify::jasonify_booleanify { $_[1]->as_string }
Subroutine jasonify_booleanify: called CC=1 SCAR=0.0
Pod undocumented
557 # OR
558 #Jasonify->add_handler( sub { $_[1]->as_string } );
559  
560 2 ▶sub false() { $false }
Subroutine false: called CC=1 SCAR=0.0
561 2 ▶sub true() { $true }
Subroutine true: called CC=1 SCAR=0.0
562  
563 34 ▶sub value { ${ $_[0] } }
Subroutine value: called CC=1 SCAR=0.0
564 sub as_string {
565 93 ▶ ${ $_[0] } ? $Jasonify::Literal::true : $Jasonify::Literal::false;
Subroutine as_string: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
${$_[0];} ? : 56 37 93
566 }
567  
568 44 ▶sub compare { ( $_[2] ? -1 : +1 ) * ( ${ $_[0] } <=> ${ bool( $_[1] ) } ) }
Subroutine compare: called CC=2 SCAR=7.1
Branch: 1 branch
BranchTrueFalseTotal
$_[2] ? : 0 44 44
569  
570 2 ▶sub negate { bool($_[0]) ? $false : $true }
Subroutine negate: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
&bool($_[0]) ? : 1 1 2
571  
572 sub bool($) {
573 is_bool( $_[0] )
574 ? $_[0]
575 : ref( $_[0] ) eq 'SCALAR'
576 56 ▶ ? ${ $_[0] } ? $true : $false
Subroutine bool: called CC=5 SCAR=16.1
Branch: 4 branches
BranchTrueFalseTotal
&is_bool($_[0]) ? : 10 46 56
ref $_[0] eq 'SCALAR' ? : 21 25 46
${$_[0];} ? : 10 11 21
$_[0] ? : 10 15 25
577 : $_[0] ? $true : $false
578 ;
579 }
580 56 ▶sub is_bool($) { Scalar::Util::blessed( $_[0] ) && $_[0]->isa(__PACKAGE__) }
Subroutine is_bool: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($_[0]) and $_[0]->isa(__PACKAGE__) 10 46 56
581  
582 2 1;
583  
584 __END__
↑ Summary