blib/lib/HAL/Tiny.pm

filter: Statementstmt 97.6% 42 / 43 Branchbran 70.0% 7 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 66.6% 2 / 3 totaltotal 92.0% 58 / 63 SCAR 20.8
CC
8
Cov
92%
as_hash
8.1
BEGIN
1.0
BEGIN
1.0
CRAP 8.0
↑ Summary Build »
1 package HAL::Tiny;
2 2 ▶use 5.008001;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use JSON qw/encode_json/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 our $VERSION = "0.02";
9  
10 sub new {
11 3 ▶ my ($class, %args) = @_;
Subroutine new: called CC=1 SCAR=0.0
Pod documented
12  
13 my ($state, $links, $embedded)
14 3 = @args{qw/state links embedded/};
15  
16 3 return bless +{
17 state => $state,
18 links => $links,
19 embedded => $embedded,
20 }, $class;
21 }
22  
23 sub as_hash {
24 6 ▶ my ($self) = @_;
Subroutine as_hash: called CC=8 SCAR=20.9
Pod undocumented
25  
26 6 my %hash;
27  
28 6 ▶ if (my $state = $self->{state}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $state = $self->{"state"}) 6 0 6
29 6 %hash = %{ $self->{state} };
30 }
31  
32 6 ▶ if (my $links = $self->{links}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $links = $self->{"links"}) 6 0 6
33 6 my $v = +{};
34 6 for my $rel (keys %$links) {
35 12 my $value = $links->{$rel};
36 12 ▶ if (ref $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value) { } 4 8 12
37 4 $v->{$rel} = $value;
38 } else {
39 $v->{$rel} = +{
40 8 href => $links->{$rel},
41 }
42 }
43 }
44 6 $hash{_links} = $v;
45 }
46  
47 6 ▶ if (my $embedded = $self->{embedded}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $embedded = $self->{"embedded"}) 2 4 6
48 2 my $v = +{};
49 2 for my $rel (keys %$embedded) {
50 2 ▶ if (ref $embedded->{$rel} eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $embedded->{$rel} eq 'ARRAY') { } 2 0 2
51 2 my @hashed = map { $_->as_hash } @{$embedded->{$rel}};
52 2 $v->{$rel} = \@hashed;
53 } else {
54 0 $v->{$rel} = $embedded->{$rel}->as_hash;
55 }
56 }
57 2 $hash{_embedded} = $v;
58 }
59  
60 6 return \%hash;
61 }
62  
63 sub as_json {
64 2 ▶ my ($self) = @_;
Subroutine as_json: called CC=1 SCAR=0.0
Pod documented
65 2 my $hash = $self->as_hash;
66 2 return encode_json($hash);
67 }
68  
69  
70 2 1;
71 __END__
↑ Summary Build »