MetaAPI/Roles/Listable.pm

filter: Statementstmt 97.4% 38 / 39 Branchbran 80.0% 16 / 20 Conditioncond 81.8% 9 / 11 MC/DCmcdc 71.4% 5 / 7 Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 88.8% 72 / 81 CC 17 SCAR 27.1
CC
17
Cov
90%
_list
17.5
BEGIN
1.0
BEGIN
1.0
CRAP 15.0
« MetaAPI.pm ↑ Summary MetaAPI/API/Specs/Roles/Service.pm »
1 package OpenStack::MetaAPI::Roles::Listable;
2  
3 16 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 16 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 16 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 85 ▶sub _list {
Subroutine _list: called CC=17 SCAR=28.6
9 85 my ($self, $all_args, $caller_args) = @_;
10  
11 # all_args are arguments from the internal OpenStack::MetaAPI::API
12 # caller_args are coming from the user to filter the results
13 # if some filters are also arguments to the request
14 # then appending them to the query will shorten the output and run it faster
15  
16 85 my @all;
17 {
18 85 my ($uri, @extra) = @$all_args;
19 85 ▶ $uri = $self->root_uri($uri)
Branch: 1 branch
BranchTrueFalseTotal
unless $uri =~ m[^/v] 43 42 85
20 if $uri !~ m{^/v}; # can be removed once dynmaic methods are used
21  
22 85 my $extra_filters =
23 $self->api_specs()->query_filters_for('/get', $uri, $caller_args);
24  
25 85 ▶ if ($extra_filters) {
Branch: 1 branch
BranchTrueFalseTotal
if ($extra_filters) 4 81 85
26 4 ▶ if (scalar @extra == 1) {
Branch: 2 branches
BranchTrueFalseTotal
if (scalar @extra == 1) { } 4 0 4
elsif (scalar @extra > 1) { } 0 0 0
27 4 push @extra, {};
28 } elsif (scalar @extra > 1) {
29 0 die "Too many args when calling _list for all...";
30 }
31 4 $extra[-1] = {%{$extra[-1]}, %$extra_filters};
32 }
33  
34 85 @all = $self->client->all($uri, @extra);
35 }
36  
37 85 my @args = @$caller_args;
38  
39 # apply our filters to the raw results
40 85 my $nargs = scalar @args;
41 85 ▶ if ($nargs && $nargs % 2 == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nargs and $nargs % 2 == 0) 75 10 85
Condition66%2/3
$nargs and $nargs % 2 == 0
!ll&&!rl&&r
10075
MC/DC50%1/2
$nargs and $nargs % 2 == 0
$nargs $nargs % 2 == 0
Truth table66%2/3
A and B
A= $nargsB= $nargs % 2 == 0
ABresult
0X0
100
111
42 75 my %opts = @args;
43 75 foreach my $filter (sort keys %opts) {
44 77 my @keep;
45 77 ▶ my $filter_isa = ref $opts{$filter} // '';
Condition50%1/2
ref $opts{$filter} // ""
l!l
770
MC/DC0%0/1
ref $opts{$filter} // ""
ref $opts{$filter}
Truth table50%1/2
A
A= ref $opts{$filter}
Aresult
11
00
46 77 foreach my $candidate (@all) {
47 193 ▶ next unless ref $candidate;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $candidate 0 193 193
48 193 ▶ if ($filter_isa eq 'Regexp') {
Branch: 1 branch
BranchTrueFalseTotal
if ($filter_isa eq 'Regexp') { } 31 162 193
49  
50 # can use a regexp as a filter
51 next
52 unless defined $candidate->{$filter}
53 31 ▶ && $candidate->{$filter} =~ $opts{$filter};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $candidate->{$filter} and $candidate->{$filter} =~ /$opts{$filter}/ 20 11 31
Condition100%3/3
defined $candidate->{$filter} and $candidate->{$filter} =~ /$opts{$filter}/
!ll&&!rl&&r
31711
MC/DC100%2/2
defined $candidate->{$filter} and $candidate->{$filter} =~ /$opts{$filter}/
defined $candidate->{$filter} $candidate->{$filter} =~ /$opts{$filter}/
Truth table100%3/3
A and B
A= defined $candidate->{$filter}B= $candidate->{$filter} =~ /$opts{$filter}/
ABresult
0X0
100
111
54 } else {
55  
56 # otherwise do one 'eq' check
57 next
58 unless defined $candidate->{$filter}
59 162 ▶ && $candidate->{$filter} eq $opts{$filter};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $candidate->{$filter} and $candidate->{$filter} eq $opts{$filter} 101 61 162
Condition100%3/3
defined $candidate->{$filter} and $candidate->{$filter} eq $opts{$filter}
!ll&&!rl&&r
69561
MC/DC100%2/2
defined $candidate->{$filter} and $candidate->{$filter} eq $opts{$filter}
defined $candidate->{$filter} $candidate->{$filter} eq $opts{$filter}
Truth table100%3/3
A and B
A= defined $candidate->{$filter}B= $candidate->{$filter} eq $opts{$filter}
ABresult
0X0
100
111
60 }
61  
62 72 push @keep, $candidate;
63 }
64  
65 77 @all = @keep;
66  
67 }
68 }
69  
70 # avoid to return a list when possible
71 85 ▶ return $all[0] if scalar @all <= 1;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @all <= 1 75 10 85
72  
73 # return a list
74 10 return @all;
75 }
76  
77 16 1;
78  
79 __END__
« MetaAPI.pm ↑ Summary MetaAPI/API/Specs/Roles/Service.pm »