| 1 | package OpenStack::MetaAPI::Roles::GetFromId; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 4 | ▶ | use Moo::Role; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | ### FIXME to delete once unused, should prefer the other flavor | ||||||||||||||||||||||||||||
| 9 | sub _get_from_id { | ||||||||||||||||||||||||||||
| 10 | 0 | ▶ | my ($self, $route, $id) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_get_from_id: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 0 | ▶ | die "route must be defined when using get_from_id" unless defined $route; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 13 | 0 | ▶ | die "invalid route '$route' - must starts with /" unless $route =~ m{^/}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 14 | 0 | ▶ | die "Undefined 'id' for route '$route'" unless defined $id; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 0 | ▶ | $route .= '/' unless $route =~ m{/$}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 0 | my $uri = $self->root_uri($route . $id); | |||||||||||||||||||||||||||
| 19 | 0 | my $answer = $self->get($uri); | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 0 | ▶ | if (ref $answer eq 'HASH' && scalar keys %$answer == 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $answer eq "HASH" and scalar keys %$answer == 1
MC/DC0%0/2
ref $answer eq "HASH" and scalar keys %$answer == 1
ref $answer eq "HASH"
scalar keys %$answer == 1
Truth table0%0/3
A and B
A= ref $answer eq "HASH"B= scalar keys %$answer == 1
| |||||||||||||||||||||||||||||
| 22 | 0 | my ($mainkey) = keys %$answer; | |||||||||||||||||||||||||||
| 23 | 0 | return $answer->{$mainkey}; | |||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 0 | return $answer; | |||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | sub _get_from_id_spec { | ||||||||||||||||||||||||||||
| 30 | 8 | ▶ | my ($self, $route, $id) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_get_from_id_spec: called CC=7 SCAR=22.0
| |||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 8 | ▶ | die "route must be defined when using get_from_id" unless defined $route; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 33 | 8 | ▶ | die "invalid route '$route' - must starts with /" unless $route =~ m{^/}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | 8 | ▶ | die "Undefined 'id' for route '$route'" unless defined $id; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 8 | ▶ | $route .= '/' unless $route =~ m{/$}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | #my $uri = $self->root_uri( $route ); | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 8 | my $answer = $self->get($route); | |||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 8 | ▶ | if (ref $answer eq 'HASH' && scalar keys %$answer == 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $answer eq "HASH" and scalar keys %$answer == 1
MC/DC0%0/2
ref $answer eq "HASH" and scalar keys %$answer == 1
ref $answer eq "HASH"
scalar keys %$answer == 1
Truth table33%1/3
A and B
A= ref $answer eq "HASH"B= scalar keys %$answer == 1
| |||||||||||||||||||||||||||||
| 43 | 8 | my ($mainkey) = keys %$answer; | |||||||||||||||||||||||||||
| 44 | 8 | return $answer->{$mainkey}; | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 0 | return $answer; | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 4 | 1; | |||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | __END__ | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | =pod | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | =encoding UTF-8 | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | =head1 NAME | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | OpenStack::MetaAPI::Roles::GetFromId | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | =head1 VERSION | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | version 0.002 | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | Nicolas R <atoomic@cpan.org> | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | This software is copyright (c) 2019 by cPanel, Inc. | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||
| 75 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | =cut | ||||||||||||||||||||||||||||