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