| 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
MC/DC100%1/1
shift() || 1.0
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 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
Condition33%1/3
$opts{"protoName"} and $opts{"dataRef"}
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"}
| |||||||||||||||||||||||||||||
| 18 | 0 | return warn("// Both protoName and dataRef must be supplied"); | |||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 16 | ▶ | ($EOI, $EOL) = $opts{explode} ? ("$/\t")x2 : ('', ' '); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 16 | ▶ | if( ref($opts{dataRef}) eq "ARRAY" ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 29 | 16 | ▶ | if( ref($opts{attributes}) eq "ARRAY" ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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() || ''
MC/DC100%1/1
shift() || ''
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 73 | 288 | my $val; | |||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 288 | ▶ | if ( ref eq "ARRAY" ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 76 | $val = $JSVER >= 1.2 ? | ||||||||||||||||||||||||||||
| 77 | "[" . join(',', | ||||||||||||||||||||||||||||
| 78 | map /^-?(?:\d+(?:\.\d*)?|\.\d+)$/ ? | ||||||||||||||||||||||||||||
| 79 | 24 | ▶ | $_ : do{ s/'/\\'/g; qq('$_') }, @{$_}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | . "]" | ||||||||||||||||||||||||||||
| 81 | : | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | "new Array(" . join(',', | ||||||||||||||||||||||||||||
| 84 | map /^-?(?:\d+(?:\.\d*)?|\.\d+)$/ ? | ||||||||||||||||||||||||||||
| 85 | 48 | ▶ | $_ : do{ s/'/\\'/g; qq('$_') }, @{$_}) | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||