line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
29685
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
32
|
|
2
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
45
|
|
3
|
|
|
|
|
|
|
package HTML::Widget::Plugin::JS; |
4
|
|
|
|
|
|
|
# ABSTRACT: a JavaScript variable declaration emitter |
5
|
|
|
|
|
|
|
$HTML::Widget::Plugin::JS::VERSION = '0.005'; |
6
|
1
|
|
|
1
|
|
836
|
use parent qw(HTML::Widget::Plugin); |
|
1
|
|
|
|
|
319
|
|
|
1
|
|
|
|
|
6
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
7168
|
use Data::JavaScript::Anon; |
|
1
|
|
|
|
|
10019
|
|
|
1
|
|
|
|
|
172
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
1
|
51334
|
sub provided_widgets { qw(js_var js_vars js_anon) } |
11
|
|
|
|
|
|
|
|
12
|
2
|
|
|
2
|
1
|
522
|
sub boolean_args {} |
13
|
2
|
|
|
2
|
1
|
11
|
sub attribute_args {} |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
#pod =head2 js_var |
16
|
|
|
|
|
|
|
#pod |
17
|
|
|
|
|
|
|
#pod =head2 js_vars |
18
|
|
|
|
|
|
|
#pod |
19
|
|
|
|
|
|
|
#pod These are two names for the same widget. Given a hashref, they will produce |
20
|
|
|
|
|
|
|
#pod JavaScript code to assign the data in the hashref. |
21
|
|
|
|
|
|
|
#pod |
22
|
|
|
|
|
|
|
#pod In otherwords, this widget: |
23
|
|
|
|
|
|
|
#pod |
24
|
|
|
|
|
|
|
#pod $fac->js_vars({ |
25
|
|
|
|
|
|
|
#pod foo => { a => 1, b => 2 }, |
26
|
|
|
|
|
|
|
#pod bar => [ 4, 2, 3 ], |
27
|
|
|
|
|
|
|
#pod }); |
28
|
|
|
|
|
|
|
#pod |
29
|
|
|
|
|
|
|
#pod ...will be rendered something like this: |
30
|
|
|
|
|
|
|
#pod |
31
|
|
|
|
|
|
|
#pod var foo = { a: 1, b: 2 }; |
32
|
|
|
|
|
|
|
#pod var bar = [ 1, 2, 3 ]; |
33
|
|
|
|
|
|
|
#pod |
34
|
|
|
|
|
|
|
#pod =cut |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub js_vars { |
37
|
2
|
|
|
2
|
1
|
19
|
my ($self, $factory, $arg) = @_; |
38
|
|
|
|
|
|
|
|
39
|
4
|
|
|
|
|
212
|
my $str = |
40
|
|
|
|
|
|
|
join "\n", |
41
|
2
|
|
|
|
|
7
|
map { Data::JavaScript::Anon->var_dump($_ => $arg->{$_}) } |
42
|
|
|
|
|
|
|
keys %$arg; |
43
|
|
|
|
|
|
|
|
44
|
2
|
|
|
|
|
153
|
return $str; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
1
|
|
|
1
|
|
69
|
BEGIN { *js_var = \&js_vars } |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
#pod =head2 js_anon |
50
|
|
|
|
|
|
|
#pod |
51
|
|
|
|
|
|
|
#pod This widget converts a given data structure to an anonymous JavaScript |
52
|
|
|
|
|
|
|
#pod structure. This basically just provides a widget factory interface to |
53
|
|
|
|
|
|
|
#pod Data::JavaScript::Anon. |
54
|
|
|
|
|
|
|
#pod |
55
|
|
|
|
|
|
|
#pod =cut |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub js_anon { |
58
|
0
|
|
|
0
|
1
|
|
my ($self, $factory, $arg) = @_; |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
Data::JavaScript::Anon->anon_dump($arg); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
1; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
__END__ |