line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
66845
|
use strict; |
|
1
|
|
|
|
|
10
|
|
|
1
|
|
|
|
|
27
|
|
2
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
41
|
|
3
|
|
|
|
|
|
|
package HTML::Widget::Plugin::JS; |
4
|
|
|
|
|
|
|
$HTML::Widget::Plugin::JS::VERSION = '0.007'; |
5
|
|
|
|
|
|
|
# ABSTRACT: a JavaScript variable declaration emitter |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
448
|
use parent qw(HTML::Widget::Plugin); |
|
1
|
|
|
|
|
290
|
|
|
1
|
|
|
|
|
5
|
|
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
17511
|
use Data::JavaScript::Anon; |
|
1
|
|
|
|
|
7548
|
|
|
1
|
|
|
|
|
133
|
|
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
1
|
33773
|
sub provided_widgets { qw(js_var js_vars js_anon) } |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
0
|
1
|
|
sub boolean_args {} |
14
|
|
|
|
0
|
1
|
|
sub attribute_args {} |
15
|
|
|
|
|
|
|
|
16
|
4
|
|
|
4
|
1
|
2204
|
sub rewrite_arg { return $_[1] } |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
#pod =head2 js_var |
19
|
|
|
|
|
|
|
#pod |
20
|
|
|
|
|
|
|
#pod =head2 js_vars |
21
|
|
|
|
|
|
|
#pod |
22
|
|
|
|
|
|
|
#pod These are two names for the same widget. Given a hashref, they will produce |
23
|
|
|
|
|
|
|
#pod JavaScript code to assign the data in the hashref. |
24
|
|
|
|
|
|
|
#pod |
25
|
|
|
|
|
|
|
#pod In otherwords, this widget: |
26
|
|
|
|
|
|
|
#pod |
27
|
|
|
|
|
|
|
#pod $fac->js_vars({ |
28
|
|
|
|
|
|
|
#pod foo => { a => 1, b => 2 }, |
29
|
|
|
|
|
|
|
#pod bar => [ 4, 2, 3 ], |
30
|
|
|
|
|
|
|
#pod }); |
31
|
|
|
|
|
|
|
#pod |
32
|
|
|
|
|
|
|
#pod ...will be rendered something like this: |
33
|
|
|
|
|
|
|
#pod |
34
|
|
|
|
|
|
|
#pod var foo = { a: 1, b: 2 }; |
35
|
|
|
|
|
|
|
#pod var bar = [ 1, 2, 3 ]; |
36
|
|
|
|
|
|
|
#pod |
37
|
|
|
|
|
|
|
#pod =cut |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub js_vars { |
40
|
3
|
|
|
3
|
1
|
13
|
my ($self, $factory, $arg) = @_; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
my $str = |
43
|
|
|
|
|
|
|
join "\n", |
44
|
3
|
|
|
|
|
18
|
map { HTML::Widget::Plugin::JS::Encoder->var_dump($_ => $arg->{$_}) } |
|
5
|
|
|
|
|
165
|
|
45
|
|
|
|
|
|
|
keys %$arg; |
46
|
|
|
|
|
|
|
|
47
|
3
|
|
|
|
|
194
|
return $str; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
1
|
|
|
1
|
|
54
|
BEGIN { *js_var = \&js_vars } |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
#pod =head2 js_anon |
53
|
|
|
|
|
|
|
#pod |
54
|
|
|
|
|
|
|
#pod This widget converts a given data structure to an anonymous JavaScript |
55
|
|
|
|
|
|
|
#pod structure. This basically just provides a widget factory interface to |
56
|
|
|
|
|
|
|
#pod Data::JavaScript::Anon. |
57
|
|
|
|
|
|
|
#pod |
58
|
|
|
|
|
|
|
#pod It also escapes end-tag-like content in strings, using a JavaScript C<\u003c> |
59
|
|
|
|
|
|
|
#pod form to avoid being interpreted as a real end tag in JavaScript embedded in |
60
|
|
|
|
|
|
|
#pod HTML. |
61
|
|
|
|
|
|
|
#pod |
62
|
|
|
|
|
|
|
#pod Software is terrible. |
63
|
|
|
|
|
|
|
#pod |
64
|
|
|
|
|
|
|
#pod =cut |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub js_anon { |
67
|
1
|
|
|
1
|
1
|
6
|
my ($self, $factory, $arg) = @_; |
68
|
|
|
|
|
|
|
|
69
|
1
|
|
|
|
|
5
|
HTML::Widget::Plugin::JS::Encoder->anon_dump($arg); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
{ |
73
|
|
|
|
|
|
|
package |
74
|
|
|
|
|
|
|
HTML::Widget::Plugin::JS::Encoder; |
75
|
1
|
|
|
1
|
|
6
|
use parent 'Data::JavaScript::Anon'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub _escape { |
78
|
2
|
|
|
2
|
|
93
|
my ($self, $text) = @_; |
79
|
2
|
|
|
|
|
20
|
$text = $self->SUPER::_escape($text); |
80
|
2
|
|
|
|
|
71
|
$text =~ s/\\u003c/g; |
81
|
2
|
|
|
|
|
10
|
return $text; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
1; |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
__END__ |