blib/lib/HAL/Tiny.pm

filter: Statementstmt 97.6% 41 / 42 Branchbran 70.0% 7 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod 50.0% 2 / 4 totaltotal 90.6% 58 / 64 CC 8 SCAR 15.7
CC
8
Cov
92%
as_hash
8.1
BEGIN
1.0
BEGIN
1.0
CRAP 4.8
↑ Summary
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.03";
9  
10 3 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
11 3 my ($class, %args) = @_;
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 6 ▶sub as_hash {
Subroutine as_hash: called CC=8 SCAR=20.9
Pod undocumented
24 6 my ($self) = @_;
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_hashref } @{$embedded->{$rel}};
52 2 $v->{$rel} = \@hashed;
53 } else {
54 0 $v->{$rel} = $embedded->{$rel}->as_hashref;
55 }
56 }
57 2 $hash{_embedded} = $v;
58 }
59  
60 6 return %hash;
61 }
62  
63 6 ▶sub as_hashref {
Subroutine as_hashref: called CC=1 SCAR=0.0
Pod undocumented
64 6 +{ $_[0]->as_hash };
65 }
66  
67 2 ▶sub as_json {
Subroutine as_json: called CC=1 SCAR=0.0
Pod documented
68 2 encode_json($_[0]->as_hashref);
69 }
70  
71  
72 2 1;
73 __END__
↑ Summary