| 1 | package OpenStack::MetaAPI::API::Specs::Roles::Service; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 19 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 19 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 19 | ▶ | use Moo::Role; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 19 | ▶ | use OpenStack::MetaAPI::Helpers::DataAsYaml; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | has 'specs' => ( | ||||||||||||||||||||||||||||||||||||||||||
| 11 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 12 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 13 | 45 | ▶ | default => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 45 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 15 | 45 | ▶ | my $specs = | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
OpenStack::MetaAPI::Helpers::DataAsYaml::LoadDataFrom(ref $self) // {}
MC/DC100%1/1
OpenStack::MetaAPI::Helpers::DataAsYaml::LoadDataFrom(ref $self) // {}
OpenStack::MetaAPI::Helpers::DataAsYaml::LoadDataFrom(ref $self)
Truth table100%2/2
A
A= OpenStack::MetaAPI::Helpers::DataAsYaml::LoadDataFrom(ref $self)
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | OpenStack::MetaAPI::Helpers::DataAsYaml::LoadDataFrom(ref $self) | ||||||||||||||||||||||||||||||||||||||||||
| 17 | // {}; | ||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | # populate missing keys | ||||||||||||||||||||||||||||||||||||||||||
| 20 | 45 | ▶ | $specs->{$_} //= {} for qw/get post put delete/; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$specs->{$_} //= {}
MC/DC100%1/1
$specs->{$_} //= {}
$specs->{$_}
Truth table100%2/2
A
A= $specs->{$_}
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | 45 | return $specs; | |||||||||||||||||||||||||||||||||||||||||
| 23 | 19 | }); | |||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | 96 | ▶ | sub get { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | 96 | my ($self, $route) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | 96 | ▶ | $route = '/' . $route unless $route =~ m{^/}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | 96 | return $self->specs()->{get}->{$route}; | |||||||||||||||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | ▶ | sub put { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
put: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | die "must be implemented"; | |||||||||||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | ▶ | sub post { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
post: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | die "must be implemented"; | |||||||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | 101 | ▶ | sub query_filters_for { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
query_filters_for: called CC=11 SCAR=24.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 101 | my ($self, $method, $route, $args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | 101 | ▶ | die "query_filters_for: method is required" unless defined $method; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | 99 | ▶ | die "query_filters_for: route is required" unless defined $route; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 98 | ▶ | die "query_filters_for: args must be an ARRAY ref" unless ref $args eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | 96 | ▶ | return unless @$args % 2 == 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | 94 | my %filters = @$args; | |||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | 94 | $method =~ s{^/+}{}; | |||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | 94 | my $spec = $self->can($method)->($self, $route); | |||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | return | ||||||||||||||||||||||||||||||||||||||||||
| 57 | unless ref $spec eq 'HASH' | ||||||||||||||||||||||||||||||||||||||||||
| 58 | && ref $spec->{request} | ||||||||||||||||||||||||||||||||||||||||||
| 59 | 94 | ▶ | && ref $spec->{request}->{query}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
ref $spec eq "HASH" and ref $spec->{"request"} and ref $spec->{"request"}{"query"}
ref $spec eq "HASH" and ref $spec->{"request"}
MC/DC33%1/3
ref $spec eq "HASH" and ref $spec->{"request"} and ref $spec->{"request"}{"query"}
ref $spec eq "HASH"
ref $spec->{"request"}
ref $spec->{"request"}{"query"}
Truth table50%2/4
A and B and C
A= ref $spec eq "HASH"B= ref $spec->{"request"}C= ref $spec->{"request"}{"query"}
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | 92 | my %valid_filters = map { $_ => 1 } sort keys %{$spec->{request}->{query}}; | |||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | 92 | my $use_filters = {}; | |||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | 92 | foreach my $filter (sort keys %filters) { | |||||||||||||||||||||||||||||||||||||||||
| 66 | 87 | ▶ | next unless defined $valid_filters{$filter}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 67 | ### ... can use type & co ... | ||||||||||||||||||||||||||||||||||||||||||
| 68 | 10 | $use_filters->{$filter} = $filters{$filter}; | |||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | 92 | ▶ | return unless scalar keys %$use_filters; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | 8 | return $use_filters; | |||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | ## hook all methods to our object | ||||||||||||||||||||||||||||||||||||||||||
| 76 | 34 | ▶ | sub setup_api_methods_for_service { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
setup_api_methods_for_service: called CC=11 SCAR=24.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | 34 | my ($self, $service) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | 34 | my $specs = $self->specs; | |||||||||||||||||||||||||||||||||||||||||
| 80 | 34 | foreach my $method (sort keys %$specs) { | |||||||||||||||||||||||||||||||||||||||||
| 81 | 136 | foreach my $route (sort keys %{$specs->{$method}}) { | |||||||||||||||||||||||||||||||||||||||||
| 82 | 120 | my $rule = $specs->{$method}->{$route}; | |||||||||||||||||||||||||||||||||||||||||
| 83 | 120 | ▶ | next unless ref $rule && ref $rule->{perl_api}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $rule and ref $rule->{"perl_api"}
MC/DC0%0/2
ref $rule and ref $rule->{"perl_api"}
ref $rule
ref $rule->{"perl_api"}
Truth table33%1/3
A and B
A= ref $ruleB= ref $rule->{"perl_api"}
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | 120 | my $perl_api = $rule->{perl_api}; | |||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | 120 | ▶ | my $code = sub { }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | 120 | my $from_txt = | |||||||||||||||||||||||||||||||||||||||||
| 89 | "from spec " . (ref $self->specs) . " for route $route"; | ||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | my $method_name = $perl_api->{method} | ||||||||||||||||||||||||||||||||||||||||||
| 92 | 120 | ▶ | or die "method is missing $from_txt"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 93 | 120 | ▶ | my $type = $perl_api->{type} or die "type is missing $from_txt"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | 120 | ▶ | if ($type eq 'getfromid') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 95 | 28 | ▶ | my $token = $perl_api->{uid} or die "uid is missing $from_txt"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | 24 | ▶ | $code = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 98 | 24 | my ($self, $uid) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | 24 | my $r = $route; | |||||||||||||||||||||||||||||||||||||||||
| 101 | 24 | $r =~ s[\Q$token\E][$uid]g; | |||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | 24 | return $self->_get_from_id_spec($r, $uid); | |||||||||||||||||||||||||||||||||||||||||
| 104 | 28 | }; | |||||||||||||||||||||||||||||||||||||||||
| 105 | } elsif ($type eq 'listable') { | ||||||||||||||||||||||||||||||||||||||||||
| 106 | my $listable_key = $perl_api->{listable_key} | ||||||||||||||||||||||||||||||||||||||||||
| 107 | 92 | ▶ | or die "listable_key is missing $from_txt"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 108 | 84 | ▶ | $code = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 109 | 84 | my ($self, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 110 | 84 | return $self->_list([$route, $listable_key], \@args); | |||||||||||||||||||||||||||||||||||||||||
| 111 | 92 | }; | |||||||||||||||||||||||||||||||||||||||||
| 112 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | die "Unknown type '$type' $from_txt"; | |||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | 120 | $service->setup_method($method_name, $code); | |||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||
| 120 | 34 | return; | |||||||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||
| 123 | 19 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | __END__ | ||||||||||||||||||||||||||||||||||||||||||