| 1 | package OpenStack::MetaAPI::Routes; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 6 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 6 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | 6 | ▶ | use Moo; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | 6 | ▶ | use OpenStack::MetaAPI::API (); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | 6 | ▶ | use YAML::XS; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | 6 | ▶ | use OpenStack::MetaAPI::Helpers::DataAsYaml; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | 6 | has 'auth' => (is => 'ro'); | |||||||||||||||||||
| 14 | 6 | has 'api' => (is => 'ro'); | |||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | 6 | our $ROUTES; | |||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | sub init_once { | ||||||||||||||||||||
| 19 | 6 | ▶ | $ROUTES //= OpenStack::MetaAPI::Helpers::DataAsYaml::LoadData(); | ||||||||||||||||||
|
Subroutine
init_once: called CC=2 SCAR=9.2
Pod
undocumented
Condition33%1/3
$OpenStack::MetaAPI::Routes::ROUTES //= OpenStack::MetaAPI::Helpers::DataAsYaml::LoadData()
MC/DC0%0/2
$OpenStack::MetaAPI::Routes::ROUTES //= OpenStack::MetaAPI::Helpers::DataAsYaml::LoadData()
$OpenStack::MetaAPI::Routes::ROUTES
OpenStack::MetaAPI::Helpers::DataAsYaml::LoadData()
Truth table33%1/3
A //= B
A= $OpenStack::MetaAPI::Routes::ROUTESB= OpenStack::MetaAPI::Helpers::DataAsYaml::LoadData()
| |||||||||||||||||||||
| 20 | } | ||||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | # cannot read from data block at compile time | ||||||||||||||||||||
| 23 | #INIT { init_once() } | ||||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | sub list_all { | ||||||||||||||||||||
| 26 | 6 | ▶ | init_once(); | ||||||||||||||||||
|
Subroutine
list_all: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 27 | 6 | return sort keys %$ROUTES; | |||||||||||||||||||
| 28 | } | ||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | ▶ | sub DESTROY { | |||||||||||||||||||
|
Subroutine
DESTROY: not called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 31 | } | ||||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | 6 | our $AUTOLOAD; | |||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | sub AUTOLOAD { | ||||||||||||||||||||
| 36 | 39 | ▶ | my (@args) = @_; | ||||||||||||||||||
|
Subroutine
AUTOLOAD: called CC=4 SCAR=14.4
| |||||||||||||||||||||
| 37 | 39 | my $call_for = $AUTOLOAD; | |||||||||||||||||||
| 38 | |||||||||||||||||||||
| 39 | 39 | $call_for =~ s/.*:://; | |||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | 39 | ▶ | if (my $route = $ROUTES->{$call_for}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 42 | 39 | ▶ | die "$call_for is a method call" unless ref $args[0] eq __PACKAGE__; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 43 | 39 | my $self = shift @args; | |||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | 39 | my $service = $self->service($route->{service}); | |||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | # not easy to overwrite can if Moo/XS::Accessor | ||||||||||||||||||||
| 48 | 39 | my $controller = $service->can_method($call_for); | |||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | 39 | ▶ | die "Invalid route '$call_for' for service '" . ref($service) . "'" | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 51 | unless defined $controller; | ||||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | 39 | return $controller->($service, @args); | |||||||||||||||||||
| 54 | } | ||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | 0 | die "Unknown function $call_for from AUTOLOAD"; | |||||||||||||||||||
| 57 | } | ||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | sub service { | ||||||||||||||||||||
| 60 | 39 | ▶ | my ($self, $name) = @_; | ||||||||||||||||||
|
Subroutine
service: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | # cache the service once | ||||||||||||||||||||
| 63 | 39 | my $k = '_service_' . $name; | |||||||||||||||||||
| 64 | 39 | ▶ | if (!$self->{$k}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 65 | $self->{$k} = OpenStack::MetaAPI::API::get_service( | ||||||||||||||||||||
| 66 | name => $name, auth => $self->auth, | ||||||||||||||||||||
| 67 | 8 | region => $ENV{'OS_REGION_NAME'}, | |||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | # backreference | ||||||||||||||||||||
| 70 | api => $self->api, | ||||||||||||||||||||
| 71 | ); | ||||||||||||||||||||
| 72 | } | ||||||||||||||||||||
| 73 | |||||||||||||||||||||
| 74 | 39 | return $self->{$k}; | |||||||||||||||||||
| 75 | } | ||||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | 6 | 1; | |||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | ## this data block describes the routes | ||||||||||||||||||||
| 80 | # this could be moved to a file... | ||||||||||||||||||||
| 81 | |||||||||||||||||||||
| 82 | =pod | ||||||||||||||||||||
| 83 | |||||||||||||||||||||
| 84 | =encoding UTF-8 | ||||||||||||||||||||
| 85 | |||||||||||||||||||||
| 86 | =head1 NAME | ||||||||||||||||||||
| 87 | |||||||||||||||||||||
| 88 | OpenStack::MetaAPI::Routes | ||||||||||||||||||||
| 89 | |||||||||||||||||||||
| 90 | =head1 VERSION | ||||||||||||||||||||
| 91 | |||||||||||||||||||||
| 92 | version 0.002 | ||||||||||||||||||||
| 93 | |||||||||||||||||||||
| 94 | =head1 AUTHOR | ||||||||||||||||||||
| 95 | |||||||||||||||||||||
| 96 | Nicolas R <atoomic@cpan.org> | ||||||||||||||||||||
| 97 | |||||||||||||||||||||
| 98 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||
| 99 | |||||||||||||||||||||
| 100 | This software is copyright (c) 2019 by cPanel, Inc. | ||||||||||||||||||||
| 101 | |||||||||||||||||||||
| 102 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||
| 103 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||
| 104 | |||||||||||||||||||||
| 105 | =cut | ||||||||||||||||||||
| 106 | |||||||||||||||||||||
| 107 | __DATA__ | ||||||||||||||||||||
| 108 | --- | ||||||||||||||||||||
| 109 | keypairs: | ||||||||||||||||||||
| 110 | service: compute | ||||||||||||||||||||
| 111 | flavors: | ||||||||||||||||||||
| 112 | service: compute | ||||||||||||||||||||
| 113 | servers: | ||||||||||||||||||||
| 114 | service: compute | ||||||||||||||||||||
| 115 | delete_server: | ||||||||||||||||||||
| 116 | service: compute | ||||||||||||||||||||
| 117 | server_from_uid: | ||||||||||||||||||||
| 118 | service: compute | ||||||||||||||||||||
| 119 | create_server: | ||||||||||||||||||||
| 120 | service: compute | ||||||||||||||||||||
| 121 | networks: | ||||||||||||||||||||
| 122 | service: network | ||||||||||||||||||||
| 123 | add_floating_ip_to_server: | ||||||||||||||||||||
| 124 | service: network | ||||||||||||||||||||
| 125 | floatingips: | ||||||||||||||||||||
| 126 | service: network | ||||||||||||||||||||
| 127 | ports: | ||||||||||||||||||||
| 128 | service: network | ||||||||||||||||||||
| 129 | delete_floatingip: | ||||||||||||||||||||
| 130 | service: network | ||||||||||||||||||||
| 131 | port_from_uid: | ||||||||||||||||||||
| 132 | service: network | ||||||||||||||||||||
| 133 | security_groups: | ||||||||||||||||||||
| 134 | service: network | ||||||||||||||||||||
| 135 | create_floating_ip: | ||||||||||||||||||||
| 136 | service: network | ||||||||||||||||||||
| 137 | image_from_uid: | ||||||||||||||||||||
| 138 | service: images | ||||||||||||||||||||
| 139 | image_from_name: | ||||||||||||||||||||
| 140 | service: images | ||||||||||||||||||||
| 141 | |||||||||||||||||||||
| 142 | |||||||||||||||||||||