Megaport/Internal/_Result.pm

filter: Statementstmt 40.3% 21 / 52 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 63.6% 7 / 11 Podpod 66.6% 2 / 3 totaltotal 32.9% 30 / 91 CC 16 SCAR 34.0
CC
16
Cov
28%
list
72.0
BUILD
20.0
__ANON__
20.0
CRAP 30.0
« Megaport/Client.pm ↑ Summary Megaport/Internal/_Obj.pm »
1 package Megaport::Internal::_Result;
2  
3 3 ▶use 5.10.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 3 ▶use Carp qw(croak cluck);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use List::Util qw(first);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use Megaport::Internal::_Obj;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 3 ▶use Class::Tiny qw(client errstr), {
Subroutine BEGIN: called CC=1 SCAR=0.0
12 _data => {}
13 3 };
14  
15 0 ▶sub BUILD {
Subroutine BUILD: not called CC=4 SCAR=30.0
Pod undocumented
16 0 my ($self, $args) = @_;
17  
18 0 ▶ croak __PACKAGE__ . '->new: client not passed to constructor' unless $self->client;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->client 0 0 0
19  
20 0 my $data = $self->client->request($self->_request->{method} => $self->_request->{path});
21  
22 0 ▶ if ($data) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data) 0 0 0
23 0 my %list;
24 0 foreach (@{$data}) {
25 0 $list{$_->{ $self->_request->{pkey} }} = Megaport::Internal::_Obj->new(%{$_});
26 }
27  
28 0 $self->_data(\%list);
29 }
30 }
31  
32 0 ▶sub get {
Subroutine get: not called CC=3 SCAR=24.8
Pod documented
33 0 my ($self, %search) = @_;
34  
35 0 ▶ if ($search{id} && exists $self->_data->{$search{id}}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($search{"id"} and exists $self->_data->{$search{"id"}}) 0 0 0
Condition0%0/3
$search{"id"} and exists $self->_data->{$search{"id"}}
!ll&&!rl&&r
000
MC/DC0%0/2
$search{"id"} and exists $self->_data->{$search{"id"}}
$search{"id"} exists $self->_data->{$search{"id"}}
Truth table0%0/3
A and B
A= $search{"id"}B= exists $self->_data->{$search{"id"}}
ABresult
0X0
100
111
36 0 return $self->_data->{$search{id}};
37 }
38  
39 0 ▶ my $needle = first {
Subroutine __ANON__: not called CC=4 SCAR=30.0
40 0 foreach my $k (keys %search) {
41 0 ▶ last unless exists $_->{$k};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $_->{$k} 0 0 0
42 0 ▶ return $_ if $_->{$k} eq $search{$k};
Branch: 1 branch
BranchTrueFalseTotal
if $_->{$k} eq $search{$k} 0 0 0
43 }
44 0 } values %{$self->_data};
45  
46 0 return $needle;
47 }
48  
49 0 ▶sub list {
Subroutine list: not called CC=8 SCAR=42.8
Pod documented
50 0 my ($self, %search) = @_;
51 0 my @result;
52  
53 0 ▶ if (!%search) {
Branch: 1 branch
BranchTrueFalseTotal
if (not %search) { } 0 0 0
54 0 @result = values %{$self->_data};
55 }
56 else {
57 0 foreach my $item (values %{$self->_data}) {
58 0 foreach my $k (keys %search) {
59 0 ▶ if (ref $search{$k} eq 'Regexp') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $search{$k} eq 'Regexp') { } 0 0 0
60 0 ▶ push @result, $item if $item->{$k} =~ $search{$k};
Branch: 1 branch
BranchTrueFalseTotal
if $item->{$k} =~ /$search{$k}/ 0 0 0
61 }
62 else {
63 0 ▶ push @result, $item if $item->{$k} eq $search{$k};
Branch: 1 branch
BranchTrueFalseTotal
if $item->{$k} eq $search{$k} 0 0 0
64 }
65 }
66 }
67 }
68  
69 0 ▶ return wantarray ? @result : \@result;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
70 }
71  
72 3 1;
73 __END__
« Megaport/Client.pm ↑ Summary Megaport/Internal/_Obj.pm »