line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::OpenStack::Client::API; |
2
|
|
|
|
|
|
|
$Net::OpenStack::Client::API::VERSION = '0.1.4'; |
3
|
9
|
|
|
9
|
|
190531
|
use strict; |
|
9
|
|
|
|
|
26
|
|
|
9
|
|
|
|
|
244
|
|
4
|
9
|
|
|
9
|
|
45
|
use warnings; |
|
9
|
|
|
|
|
15
|
|
|
9
|
|
|
|
|
238
|
|
5
|
|
|
|
|
|
|
|
6
|
9
|
|
|
9
|
|
3293
|
use Net::OpenStack::Client::API::Convert qw(process_args); |
|
9
|
|
|
|
|
26
|
|
|
9
|
|
|
|
|
492
|
|
7
|
9
|
|
|
9
|
|
3484
|
use Net::OpenStack::Client::API::Magic qw(retrieve); |
|
9
|
|
|
|
|
22
|
|
|
9
|
|
|
|
|
540
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $AUTOLOAD; |
10
|
|
|
|
|
|
|
|
11
|
9
|
|
|
9
|
|
58
|
use Readonly; |
|
9
|
|
|
|
|
16
|
|
|
9
|
|
|
|
|
2860
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
Readonly our $API_METHOD_PREFIX => 'api_'; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# This will add all AUTOLOADable functions as methods calls |
16
|
|
|
|
|
|
|
# So only AUTOLOAD method with command name prefixed |
17
|
|
|
|
|
|
|
# with api_, returns a C<$api_method> call |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub AUTOLOAD |
20
|
|
|
|
|
|
|
{ |
21
|
104
|
|
|
104
|
|
38190
|
my $called = $AUTOLOAD; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# Don't mess with garbage collection! |
24
|
104
|
100
|
|
|
|
766
|
return if $called =~ m{DESTROY}; |
25
|
|
|
|
|
|
|
|
26
|
97
|
|
|
|
|
138
|
my $called_orig = $called; |
27
|
97
|
|
|
|
|
481
|
$called =~ s{^.*::}{}; |
28
|
|
|
|
|
|
|
|
29
|
97
|
|
|
|
|
267
|
my ($self, @args) = @_; |
30
|
|
|
|
|
|
|
|
31
|
97
|
|
|
|
|
148
|
my ($cmd, $fail); |
32
|
97
|
|
|
|
|
310
|
my $api_pattern = "^${API_METHOD_PREFIX}([^_]+)_(.*)\$"; |
33
|
97
|
50
|
|
|
|
1038
|
if (!defined($self->{versions})) { |
|
|
50
|
|
|
|
|
|
34
|
0
|
|
|
|
|
0
|
$fail = "no versions specified"; |
35
|
|
|
|
|
|
|
} elsif ($called =~ m/$api_pattern/) { |
36
|
97
|
|
|
|
|
364
|
($cmd, $fail) = retrieve($1, $2, $self->{versions}->{$1}); |
37
|
|
|
|
|
|
|
} else { |
38
|
|
|
|
|
|
|
# TODO: |
39
|
|
|
|
|
|
|
# Add support for guessing the service based on service + API version attribute |
40
|
0
|
|
|
|
|
0
|
my $versions_txt = join(",", map {"$_=$self->{versions}->{$_}"} sort keys %{$self->{versions}}); |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
41
|
0
|
|
|
|
|
0
|
$fail = "only $API_METHOD_PREFIX methods supported versions $versions_txt"; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
97
|
50
|
|
|
|
201
|
if ($fail) { |
45
|
0
|
|
|
|
|
0
|
die "Unknown Net::OpenStack::Client::API method: '$called' failed $fail (from original $called_orig)"; |
46
|
|
|
|
|
|
|
} else { |
47
|
|
|
|
|
|
|
# Run the expected method. |
48
|
|
|
|
|
|
|
# AUTOLOAD with glob assignment and goto defines the autoloaded method |
49
|
|
|
|
|
|
|
# (so they are only autoloaded once when they are first called), |
50
|
|
|
|
|
|
|
# but that breaks inheritance. |
51
|
|
|
|
|
|
|
|
52
|
97
|
100
|
|
|
|
223
|
if (ref($cmd->{code}) eq 'CODE') { |
53
|
64
|
|
|
|
|
200
|
return $cmd->{code}->($self, @args); |
54
|
|
|
|
|
|
|
} else { |
55
|
33
|
|
|
|
|
122
|
return $self->rest(process_args($cmd, @args)); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
1; |