MetaAPI/Routes.pm

filter: Statementstmt 100% 39 / 39 Branchbran 75.0% 6 / 8 Conditioncond 66.6% 2 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 90.0% 9 / 10 Podpod 0.0% 0 / 3 totaltotal 86.1% 56 / 65 CC 6 SCAR 7.3
CC
6
Cov
94%
AUTOLOAD
4.0
init_once
2.1
service
2.0
CRAP 2.1
« MetaAPI/Helpers/DataAsYaml.pm ↑ Summary MetaAPI/API/Specs.pm »
1 package OpenStack::MetaAPI::Routes;
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;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 19 ▶use OpenStack::MetaAPI::API ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 19 ▶use OpenStack::MetaAPI::Helpers::DataAsYaml;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 19 has 'auth' => (is => 'ro');
13 19 has 'api' => (is => 'ro');
14  
15 19 our $ROUTES;
16  
17 21 ▶sub init_once {
Subroutine init_once: called CC=2 SCAR=7.2
Pod undocumented
18 21 ▶ $ROUTES //= OpenStack::MetaAPI::Helpers::DataAsYaml::LoadData();
Condition66%2/3
$OpenStack::MetaAPI::Routes::ROUTES //= OpenStack::MetaAPI::Helpers::DataAsYaml::LoadData()
l!l&&r!l&&!r
3180
MC/DC0%0/2
$OpenStack::MetaAPI::Routes::ROUTES //= OpenStack::MetaAPI::Helpers::DataAsYaml::LoadData()
$OpenStack::MetaAPI::Routes::ROUTES OpenStack::MetaAPI::Helpers::DataAsYaml::LoadData()
Truth table66%2/3
A //= B
A= $OpenStack::MetaAPI::Routes::ROUTESB= OpenStack::MetaAPI::Helpers::DataAsYaml::LoadData()
ABresult
1X1
011
000
19 }
20  
21 # cannot read from data block at compile time
22 #INIT { init_once() }
23  
24 21 ▶sub list_all {
Subroutine list_all: called CC=1 SCAR=0.0
Pod undocumented
25 21 init_once();
26 21 return sort keys %$ROUTES;
27 }
28  
29 0 ▶sub DESTROY {
Subroutine DESTROY: not called CC=1 SCAR=0.0
30 }
31  
32 19 our $AUTOLOAD;
33  
34 171 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: called CC=4 SCAR=13.9
35 171 my (@args) = @_;
36 171 my $call_for = $AUTOLOAD;
37  
38 171 $call_for =~ s/.*:://;
39  
40 171 ▶ if (my $route = $ROUTES->{$call_for}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $route = $OpenStack::MetaAPI::Routes::ROUTES->{$call_for}) 170 1 171
41 170 ▶ die "$call_for is a method call" unless ref $args[0] eq __PACKAGE__;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $args[0] eq __PACKAGE__ 0 170 170
42 170 my $self = shift @args;
43  
44 170 my $service = $self->service($route->{service});
45  
46 # not easy to overwrite can if Moo/XS::Accessor
47 170 my $controller = $service->can_method($call_for);
48  
49 170 ▶ die "Invalid route '$call_for' for service '" . ref($service) . "'"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $controller 0 170 170
50 unless defined $controller;
51  
52 170 return $controller->($service, @args);
53 }
54  
55 1 die "Unknown function $call_for from AUTOLOAD";
56 }
57  
58 178 ▶sub service {
Subroutine service: called CC=2 SCAR=6.9
Pod undocumented
59 178 my ($self, $name) = @_;
60  
61 # cache the service once
62 178 my $k = '_service_' . $name;
63 178 ▶ if (!$self->{$k}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{$k}) 34 144 178
64 $self->{$k} = OpenStack::MetaAPI::API::get_service(
65 name => $name, auth => $self->auth,
66 34 region => $ENV{'OS_REGION_NAME'},
67  
68 # backreference
69 api => $self->api,
70 );
71 }
72  
73 178 return $self->{$k};
74 }
75  
76 19 1;
77  
78 ## this data block describes the routes
79 # this could be moved to a file...
80  
81 =pod
82  
83 =encoding UTF-8
84  
85 =head1 NAME
86  
87 OpenStack::MetaAPI::Routes
88  
89 =head1 VERSION
90  
91 version 0.005
92  
93 =head1 AUTHOR
94  
95 Nicolas R <atoomic@cpan.org>
96  
97 =head1 COPYRIGHT AND LICENSE
98  
99 This software is copyright (c) 2019 by cPanel, Inc.
100  
101 This is free software; you can redistribute it and/or modify it under
102 the same terms as the Perl 5 programming language system itself.
103  
104 =cut
105  
106 __DATA__
« MetaAPI/Helpers/DataAsYaml.pm ↑ Summary MetaAPI/API/Specs.pm »