line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::Widgets::NavMenu::ToJSON; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
32723
|
use 5.008; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
91
|
|
4
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
10
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
73
|
|
6
|
2
|
|
|
2
|
|
9
|
use warnings FATAL => 'all'; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
80
|
|
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
9
|
use Carp; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
152
|
|
9
|
|
|
|
|
|
|
|
10
|
2
|
|
|
2
|
|
969
|
use parent 'HTML::Widgets::NavMenu::Object'; |
|
2
|
|
|
|
|
640
|
|
|
2
|
|
|
|
|
8
|
|
11
|
|
|
|
|
|
|
|
12
|
2
|
|
|
2
|
|
7796
|
use JSON::MaybeXS 1.002002 (); |
|
2
|
|
|
|
|
12288
|
|
|
2
|
|
|
|
|
596
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our $VERSION = '0.0.7'; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
__PACKAGE__->mk_acc_ref( |
19
|
|
|
|
|
|
|
[ |
20
|
|
|
|
|
|
|
qw( |
21
|
|
|
|
|
|
|
_data_persistence_store |
22
|
|
|
|
|
|
|
_tree_contents |
23
|
|
|
|
|
|
|
), |
24
|
|
|
|
|
|
|
] |
25
|
|
|
|
|
|
|
); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub _init |
28
|
|
|
|
|
|
|
{ |
29
|
1
|
|
|
1
|
|
545
|
my ($self, $args) = @_; |
30
|
|
|
|
|
|
|
|
31
|
1
|
50
|
|
|
|
50
|
$self->_data_persistence_store( |
32
|
|
|
|
|
|
|
$args->{'data_persistence_store'} |
33
|
|
|
|
|
|
|
) or Carp::confess("No data_persistence_store specified."); |
34
|
|
|
|
|
|
|
|
35
|
1
|
50
|
|
|
|
8
|
$self->_tree_contents( |
36
|
|
|
|
|
|
|
$args->{'tree_contents'} |
37
|
|
|
|
|
|
|
) or Carp::confess("No tree_contents specified."); |
38
|
|
|
|
|
|
|
|
39
|
1
|
|
|
|
|
4
|
return; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub _get_id_for_url |
43
|
|
|
|
|
|
|
{ |
44
|
9
|
|
|
9
|
|
9
|
my ($self, $url) = @_; |
45
|
9
|
|
|
|
|
29
|
return $self->_data_persistence_store->get_id_for_url($url); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub output_as_json |
50
|
|
|
|
|
|
|
{ |
51
|
1
|
|
|
1
|
1
|
229
|
my $self = shift; |
52
|
|
|
|
|
|
|
|
53
|
1
|
|
|
|
|
3
|
my $persistence = $self->_data_persistence_store(); |
54
|
|
|
|
|
|
|
|
55
|
1
|
|
|
|
|
7
|
$persistence->load; |
56
|
|
|
|
|
|
|
|
57
|
1
|
|
|
|
|
2
|
my $process_sub_tree; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
$process_sub_tree = sub |
60
|
|
|
|
|
|
|
{ |
61
|
10
|
|
|
10
|
|
40
|
my ($sub_tree) = @_; |
62
|
|
|
|
|
|
|
|
63
|
10
|
|
|
|
|
8
|
my @keys = (grep { $_ ne 'subs' } keys %{$sub_tree}); |
|
31
|
|
|
|
|
44
|
|
|
10
|
|
|
|
|
22
|
|
64
|
|
|
|
|
|
|
|
65
|
10
|
|
|
|
|
14
|
my $has_subs = exists($sub_tree->{subs}); |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
return |
68
|
|
|
|
|
|
|
{ |
69
|
28
|
|
|
|
|
138
|
(exists($sub_tree->{url}) |
70
|
|
|
|
|
|
|
? (id => $self->_get_id_for_url($sub_tree->{url}), ) |
71
|
|
|
|
|
|
|
: () |
72
|
|
|
|
|
|
|
), |
73
|
9
|
|
|
|
|
18
|
(map { $_ => $sub_tree->{$_} } @keys), |
74
|
|
|
|
|
|
|
$has_subs |
75
|
9
|
|
|
|
|
16
|
? (subs => [ map { $process_sub_tree->($_) } |
76
|
3
|
|
|
|
|
7
|
grep { ! exists($_->{separator}) } |
77
|
10
|
100
|
|
|
|
27
|
@{$sub_tree->{subs}} |
|
|
100
|
|
|
|
|
|
78
|
|
|
|
|
|
|
]) |
79
|
|
|
|
|
|
|
: (), |
80
|
|
|
|
|
|
|
}; |
81
|
1
|
|
|
|
|
17
|
}; |
82
|
|
|
|
|
|
|
|
83
|
1
|
|
|
|
|
9
|
my $ret = JSON::MaybeXS->new(utf8 => 1, canonical => 1)->encode( |
84
|
|
|
|
|
|
|
$process_sub_tree->($self->_tree_contents)->{'subs'} |
85
|
|
|
|
|
|
|
); |
86
|
|
|
|
|
|
|
|
87
|
1
|
|
|
|
|
14
|
$persistence->save; |
88
|
|
|
|
|
|
|
|
89
|
1
|
|
|
|
|
3
|
return $ret; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
1; # End of HTML::Widgets::NavMenu::ToJSON |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
__END__ |