LiteObject.pm

filter: Statementstmt 94.2% 66 / 70 Branchbran 88.4% 23 / 26 Conditioncond 71.4% 5 / 7 MC/DCmcdc 50.0% 2 / 4 Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 2 totaltotal 88.7% 102 / 115 CC 19 SCAR 21.5
CC
19
Cov
91%
jsodump
12.5
datum
7.0
import
2.0
CRAP 8.6
↑ Summary example.pl »
1 package Data::JavaScript::LiteObject;
2 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 4 ▶use vars qw($VERSION $JSVER);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 $VERSION = '1.04';
5  
6 4 ▶sub import{
Subroutine import: called CC=2 SCAR=6.9
7 4 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 shift;
9 4 ▶ $JSVER = shift || 1.0;
Condition100%2/2
shift() || 1.0
l!l
22
MC/DC100%1/1
shift() || 1.0
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
10 4 *{"@{[scalar caller()]}::jsodump"} = \&jsodump;
11 }
12  
13 16 ▶sub jsodump {
Subroutine jsodump: called CC=12 SCAR=25.2
Pod undocumented
14 16 my %opts = @_;
15 16 my(@keys, $obj, @objs, $EOL, $EOI, @F);
16  
17 16 ▶ unless( $opts{protoName} && $opts{dataRef} ){
Branch: 1 branch
BranchTrueFalseTotal
unless ($opts{"protoName"} and $opts{"dataRef"}) 0 16 16
Condition33%1/3
$opts{"protoName"} and $opts{"dataRef"}
!ll&&!rl&&r
0016
MC/DC0%0/2
$opts{"protoName"} and $opts{"dataRef"}
$opts{"protoName"} $opts{"dataRef"}
Truth table33%1/3
A and B
A= $opts{"protoName"}B= $opts{"dataRef"}
ABresult
0X0
100
111
18 0 return warn("// Both protoName and dataRef must be supplied");
19 }
20  
21 16 ▶ ($EOI, $EOL) = $opts{explode} ? ("$/\t")x2 : ('', ' ');
Branch: 1 branch
BranchTrueFalseTotal
$opts{'explode'} ? : 4 12 16
22  
23 16 ▶ if( ref($opts{dataRef}) eq "ARRAY" ){
Branch: 1 branch
BranchTrueFalseTotal
if (ref $opts{"dataRef"} eq "ARRAY") 8 8 16
24 8 my $i=0;
25 8 $opts{dataRef} = {map {$opts{protoName}.$i++=>$_} @{$opts{dataRef}} };
26 }
27 #NOT elsif
28 16 ▶ if( ref($opts{dataRef}) eq "HASH" ){
Branch: 1 branch
BranchTrueFalseTotal
if (ref $opts{'dataRef'} eq 'HASH') { } 16 0 16
29 16 ▶ if( ref($opts{attributes}) eq "ARRAY" ){
Branch: 1 branch
BranchTrueFalseTotal
if (ref $opts{'attributes'} eq 'ARRAY') { } 12 4 16
30 12 @keys = @{$opts{attributes}};
31 }
32 else{
33 12 @keys = sort { $a cmp $b } keys
34 4 %{$opts{dataRef}->{(sort keys %{$opts{dataRef}})[0]}};
35 }
36 }
37 else{
38 0 warn("// Unknown reference type, attributes"); return;
39 }
40  
41 16 push @F, "function $opts{protoName} (", join(', ', @keys) ,") {$/\t";
42 16 push @F, map("this.$_ = $_;$EOL", @keys);
43 16 push @F, "}$/";
44  
45 16 foreach $obj ( sort keys %{$opts{dataRef}} ){
46 48 push @F, "$obj = new $opts{protoName}($EOI";
47 push @F, join(",$EOL",
48 48 map(datum($opts{dataRef}->{$obj}->{$_}), @keys) ).$EOL;
49 48 push @F, ");$/";
50 48 push @objs, $obj;
51 }
52  
53 16 ▶ if( defined($opts{listObjects}) ){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opts{"listObjects"}) 0 16 16
54 0 push @F, "$opts{listObjects} = new Array($EOI",
55 join(",$EOL", map("'$_'", @objs)), ");$/";
56 }
57  
58 16 ▶ if( defined($opts{lineIN}) ){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opts{"lineIN"}) 8 8 16
59 8 local $. = $opts{lineIN}+1;
60 8 @F = split($/, join('', @F));
61 8 foreach ( @F ) {
62 164 ▶ $_ .= $/ . '// '. ++$. unless (++$.-$opts{lineIN}) %5;
Branch: 1 branch
BranchTrueFalseTotal
unless (++$. - $opts{"lineIN"}) % 5 40 124 164
63 164 $_ .= $/;
64 }
65 8 ${$opts{lineOUT}} = $.;
66 8 unshift @F, '// '. ($opts{lineIN}+1) .$/;
67 }
68 16 return @F;
69 }
70  
71 288 ▶sub datum {
Subroutine datum: called CC=7 SCAR=19.5
Pod undocumented
72 288 ▶ local $_ = shift() || '';
Condition100%2/2
shift() || ''
l!l
128160
MC/DC100%1/1
shift() || ''
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
73 288 my $val;
74  
75 288 ▶ if ( ref eq "ARRAY" ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $_ eq 'ARRAY') { } 48 240 288
elsif ($val = $_, !($val =~ /^-?(?:\d+(?:\.\d*)?|\.\d+)$/)) { } 160 80 240
76 $val = $JSVER >= 1.2 ?
77 "[" . join(',',
78 map /^-?(?:\d+(?:\.\d*)?|\.\d+)$/ ?
79 24 ▶ $_ : do{ s/'/\\'/g; qq('$_') }, @{$_})
Branch: 1 branch
BranchTrueFalseTotal
/^-?(?:\d+(?:\.\d*)?|\.\d+)$/ ? : 24 24 48
80 . "]"
81 :
82  
83 "new Array(" . join(',',
84 map /^-?(?:\d+(?:\.\d*)?|\.\d+)$/ ?
85 48 ▶ $_ : do{ s/'/\\'/g; qq('$_') }, @{$_})
Branch: 2 branches
BranchTrueFalseTotal
$Data::JavaScript::LiteObject::JSVER >= 1.2 ? : 24 24 48
/^-?(?:\d+(?:\.\d*)?|\.\d+)$/ ? : 24 24 48
86 . ")";
87  
88 }
89 elsif( $val = $_, $val !~ /^-?(?:\d+(?:\.\d*)?|\.\d+)$/ ){
90 160 s/'/\\'/g;
91 160 $val = qq('$_');
92 }
93  
94 288 return $val;
95 }
96  
97 4 1;
98 __END__
↑ Summary example.pl »