line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HAL::Tiny; |
2
|
2
|
|
|
2
|
|
24375
|
use 5.008001; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
81
|
|
3
|
2
|
|
|
2
|
|
11
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
73
|
|
4
|
2
|
|
|
2
|
|
9
|
use warnings; |
|
2
|
|
|
|
|
11
|
|
|
2
|
|
|
|
|
76
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
908
|
use JSON qw/encode_json/; |
|
2
|
|
|
|
|
18128
|
|
|
2
|
|
|
|
|
12
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = "0.03"; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new { |
11
|
3
|
|
|
3
|
1
|
44
|
my ($class, %args) = @_; |
12
|
|
|
|
|
|
|
|
13
|
3
|
|
|
|
|
6
|
my ($state, $links, $embedded) |
14
|
|
|
|
|
|
|
= @args{qw/state links embedded/}; |
15
|
|
|
|
|
|
|
|
16
|
3
|
|
|
|
|
22
|
return bless +{ |
17
|
|
|
|
|
|
|
state => $state, |
18
|
|
|
|
|
|
|
links => $links, |
19
|
|
|
|
|
|
|
embedded => $embedded, |
20
|
|
|
|
|
|
|
}, $class; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub as_hash { |
24
|
6
|
|
|
6
|
0
|
10
|
my ($self) = @_; |
25
|
|
|
|
|
|
|
|
26
|
6
|
|
|
|
|
6
|
my %hash; |
27
|
|
|
|
|
|
|
|
28
|
6
|
50
|
|
|
|
23
|
if (my $state = $self->{state}) { |
29
|
6
|
|
|
|
|
6
|
%hash = %{ $self->{state} }; |
|
6
|
|
|
|
|
23
|
|
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
6
|
50
|
|
|
|
18
|
if (my $links = $self->{links}) { |
33
|
6
|
|
|
|
|
7
|
my $v = +{}; |
34
|
6
|
|
|
|
|
15
|
for my $rel (keys %$links) { |
35
|
12
|
|
|
|
|
16
|
my $value = $links->{$rel}; |
36
|
12
|
100
|
|
|
|
23
|
if (ref $value) { |
37
|
4
|
|
|
|
|
10
|
$v->{$rel} = $value; |
38
|
|
|
|
|
|
|
} else { |
39
|
8
|
|
|
|
|
32
|
$v->{$rel} = +{ |
40
|
|
|
|
|
|
|
href => $links->{$rel}, |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
} |
44
|
6
|
|
|
|
|
13
|
$hash{_links} = $v; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
6
|
100
|
|
|
|
31
|
if (my $embedded = $self->{embedded}) { |
48
|
2
|
|
|
|
|
4
|
my $v = +{}; |
49
|
2
|
|
|
|
|
7
|
for my $rel (keys %$embedded) { |
50
|
2
|
50
|
|
|
|
7
|
if (ref $embedded->{$rel} eq 'ARRAY') { |
51
|
2
|
|
|
|
|
3
|
my @hashed = map { $_->as_hashref } @{$embedded->{$rel}}; |
|
4
|
|
|
|
|
12
|
|
|
2
|
|
|
|
|
10
|
|
52
|
2
|
|
|
|
|
8
|
$v->{$rel} = \@hashed; |
53
|
|
|
|
|
|
|
} else { |
54
|
0
|
|
|
|
|
0
|
$v->{$rel} = $embedded->{$rel}->as_hashref; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
} |
57
|
2
|
|
|
|
|
6
|
$hash{_embedded} = $v; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
6
|
|
|
|
|
129
|
return %hash; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub as_hashref { |
64
|
6
|
|
|
6
|
0
|
16
|
+{ $_[0]->as_hash }; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub as_json { |
68
|
2
|
|
|
2
|
1
|
206
|
encode_json($_[0]->as_hashref); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
1; |
73
|
|
|
|
|
|
|
__END__ |