line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::JavaScript::LiteObject; |
2
|
4
|
|
|
4
|
|
3323
|
use strict; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
150
|
|
3
|
4
|
|
|
4
|
|
20
|
use vars qw($VERSION $JSVER); |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
281
|
|
4
|
|
|
|
|
|
|
$VERSION = '1.04'; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
sub import{ |
7
|
4
|
|
|
4
|
|
17
|
no strict 'refs'; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
4728
|
|
8
|
4
|
|
|
4
|
|
32
|
shift; |
9
|
4
|
|
100
|
|
|
26
|
$JSVER = shift || 1.0; |
10
|
4
|
|
|
|
|
9
|
*{"@{[scalar caller()]}::jsodump"} = \&jsodump; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
9256
|
|
11
|
|
|
|
|
|
|
} |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub jsodump { |
14
|
16
|
|
|
16
|
0
|
2039
|
my %opts = @_; |
15
|
16
|
|
|
|
|
23
|
my(@keys, $obj, @objs, $EOL, $EOI, @F); |
16
|
|
|
|
|
|
|
|
17
|
16
|
50
|
33
|
|
|
116
|
unless( $opts{protoName} && $opts{dataRef} ){ |
18
|
0
|
|
|
|
|
0
|
return warn("// Both protoName and dataRef must be supplied"); |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
16
|
100
|
|
|
|
66
|
($EOI, $EOL) = $opts{explode} ? ("$/\t")x2 : ('', ' '); |
22
|
|
|
|
|
|
|
|
23
|
16
|
100
|
|
|
|
55
|
if( ref($opts{dataRef}) eq "ARRAY" ){ |
24
|
8
|
|
|
|
|
10
|
my $i=0; |
25
|
8
|
|
|
|
|
8
|
$opts{dataRef} = {map {$opts{protoName}.$i++=>$_} @{$opts{dataRef}} }; |
|
24
|
|
|
|
|
81
|
|
|
8
|
|
|
|
|
17
|
|
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
#NOT elsif |
28
|
16
|
50
|
|
|
|
48
|
if( ref($opts{dataRef}) eq "HASH" ){ |
29
|
16
|
100
|
|
|
|
41
|
if( ref($opts{attributes}) eq "ARRAY" ){ |
30
|
12
|
|
|
|
|
16
|
@keys = @{$opts{attributes}}; |
|
12
|
|
|
|
|
43
|
|
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
else{ |
33
|
9
|
|
|
|
|
36
|
@keys = sort { $a cmp $b } keys |
|
4
|
|
|
|
|
33
|
|
34
|
4
|
|
|
|
|
9
|
%{$opts{dataRef}->{(sort keys %{$opts{dataRef}})[0]}}; |
|
4
|
|
|
|
|
10
|
|
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
else{ |
38
|
0
|
|
|
|
|
0
|
warn("// Unknown reference type, attributes"); return; |
|
0
|
|
|
|
|
0
|
|
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
16
|
|
|
|
|
82
|
push @F, "function $opts{protoName} (", join(', ', @keys) ,") {$/\t"; |
42
|
16
|
|
|
|
|
127
|
push @F, map("this.$_ = $_;$EOL", @keys); |
43
|
16
|
|
|
|
|
38
|
push @F, "}$/"; |
44
|
|
|
|
|
|
|
|
45
|
16
|
|
|
|
|
21
|
foreach $obj ( sort keys %{$opts{dataRef}} ){ |
|
16
|
|
|
|
|
64
|
|
46
|
48
|
|
|
|
|
109
|
push @F, "$obj = new $opts{protoName}($EOI"; |
47
|
48
|
|
|
|
|
179
|
push @F, join(",$EOL", |
48
|
|
|
|
|
|
|
map(datum($opts{dataRef}->{$obj}->{$_}), @keys) ).$EOL; |
49
|
48
|
|
|
|
|
127
|
push @F, ");$/"; |
50
|
48
|
|
|
|
|
91
|
push @objs, $obj; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
16
|
50
|
|
|
|
63
|
if( defined($opts{listObjects}) ){ |
54
|
0
|
|
|
|
|
0
|
push @F, "$opts{listObjects} = new Array($EOI", |
55
|
|
|
|
|
|
|
join(",$EOL", map("'$_'", @objs)), ");$/"; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
16
|
100
|
|
|
|
52
|
if( defined($opts{lineIN}) ){ |
59
|
8
|
|
|
|
|
52
|
local $. = $opts{lineIN}+1; |
60
|
8
|
|
|
|
|
225
|
@F = split($/, join('', @F)); |
61
|
8
|
|
|
|
|
35
|
foreach ( @F ) { |
62
|
164
|
100
|
|
|
|
486
|
$_ .= $/ . '// '. ++$. unless (++$.-$opts{lineIN}) %5; |
63
|
164
|
|
|
|
|
213
|
$_ .= $/; |
64
|
|
|
|
|
|
|
} |
65
|
8
|
|
|
|
|
15
|
${$opts{lineOUT}} = $.; |
|
8
|
|
|
|
|
27
|
|
66
|
8
|
|
|
|
|
58
|
unshift @F, '// '. ($opts{lineIN}+1) .$/; |
67
|
|
|
|
|
|
|
} |
68
|
16
|
|
|
|
|
204
|
return @F; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub datum { |
72
|
288
|
|
100
|
288
|
0
|
961
|
local $_ = shift() || ''; |
73
|
288
|
|
|
|
|
296
|
my $val; |
74
|
|
|
|
|
|
|
|
75
|
288
|
100
|
|
|
|
1090
|
if ( ref eq "ARRAY" ) { |
|
|
100
|
|
|
|
|
|
76
|
|
|
|
|
|
|
$val = $JSVER >= 1.2 ? |
77
|
|
|
|
|
|
|
"[" . join(',', |
78
|
|
|
|
|
|
|
map /^-?(?:\d+(?:\.\d*)?|\.\d+)$/ ? |
79
|
24
|
|
|
|
|
29
|
$_ : do{ s/'/\\'/g; qq('$_') }, @{$_}) |
|
24
|
|
|
|
|
191
|
|
|
24
|
|
|
|
|
98
|
|
80
|
|
|
|
|
|
|
. "]" |
81
|
|
|
|
|
|
|
: |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
"new Array(" . join(',', |
84
|
|
|
|
|
|
|
map /^-?(?:\d+(?:\.\d*)?|\.\d+)$/ ? |
85
|
48
|
100
|
|
|
|
93
|
$_ : do{ s/'/\\'/g; qq('$_') }, @{$_}) |
|
24
|
100
|
|
|
|
68
|
|
|
24
|
100
|
|
|
|
227
|
|
|
24
|
|
|
|
|
95
|
|
86
|
|
|
|
|
|
|
. ")"; |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
elsif( $val = $_, $val !~ /^-?(?:\d+(?:\.\d*)?|\.\d+)$/ ){ |
90
|
160
|
|
|
|
|
165
|
s/'/\\'/g; |
91
|
160
|
|
|
|
|
225
|
$val = qq('$_'); |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
288
|
|
|
|
|
1254
|
return $val; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
1; |
98
|
|
|
|
|
|
|
__END__ |