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