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