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 18 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 18 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 18 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 18 ▶use OpenStack::MetaAPI::API ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 18 ▶use OpenStack::MetaAPI::Helpers::DataAsYaml;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 18 has 'auth' => (is => 'ro');
13 18 has 'api' => (is => 'ro');
14  
15 18 our $ROUTES;
16  
17 sub init_once {
18 20 ▶ $ROUTES //= OpenStack::MetaAPI::Helpers::DataAsYaml::LoadData();
Subroutine init_once: called CC=2 SCAR=7.2
Pod undocumented
Condition66%2/3
$OpenStack::MetaAPI::Routes::ROUTES //= OpenStack::MetaAPI::Helpers::DataAsYaml::LoadData()
l!l&&r!l&&!r
3170
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 sub list_all {
25 20 ▶ init_once();
Subroutine list_all: called CC=1 SCAR=0.0
Pod undocumented
26 20 return sort keys %$ROUTES;
27 }
28  
29 ▶sub DESTROY {
Subroutine DESTROY: not called CC=1 SCAR=0.0
30 }
31  
32 18 our $AUTOLOAD;
33  
34 sub AUTOLOAD {
35 171 ▶ my (@args) = @_;
Subroutine AUTOLOAD: called CC=4 SCAR=13.9
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 sub service {
59 178 ▶ my ($self, $name) = @_;
Subroutine service: called CC=2 SCAR=6.9
Pod undocumented
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 18 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.004
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__
107 ---
108 keypairs:
109 service: compute
110 flavors:
111 service: compute
112 servers:
113 service: compute
114 delete_server:
115 service: compute
116 server_from_uid:
117 service: compute
118 create_server:
119 service: compute
120 networks:
121 service: network
122 add_floating_ip_to_server:
123 service: network
124 floatingips:
125 service: network
126 ports:
127 service: network
128 delete_floatingip:
129 service: network
130 port_from_uid:
131 service: network
132 security_groups:
133 service: network
134 create_floating_ip:
135 service: network
136 image_from_uid:
137 service: images
138 image_from_name:
139 service: images
140 list_images:
141 service: images
142 limits:
143 service: compute
144 server_action:
145 service: compute
146 create_image:
147 service: compute
148 flavors_detail:
149 service: compute
150 console_output:
151 service: compute
152 server_volumes:
153 service: compute
154 attach_volume:
155 service: compute
156 detach_volume:
157 service: compute
158 volumes:
159 service: volume
160 volume_from_uid:
161 service: volume
162 create_volume:
163 service: volume
164 delete_volume:
165 service: volume
166 volume_limits:
167 service: volume
168  
169  
« MetaAPI/Helpers/DataAsYaml.pm ↑ Summary MetaAPI/API/Specs.pm »