Client/API.pm

filter: Statementstmt 84.2% 32 / 38 Branchbran 70.0% 7 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod n/a totaltotal 83.3% 45 / 54 CC 6 SCAR 14.6
CC
6
Cov
81%
AUTOLOAD
7.1
BEGIN
1.0
BEGIN
1.0
CRAP 4.3
« Client/Identity/Tagstore.pm ↑ Summary Client/Response.pm »
1 package Net::OpenStack::Client::API;
2 9 $Net::OpenStack::Client::API::VERSION = '0.1.4';
3 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 9 ▶use Net::OpenStack::Client::API::Convert qw(process_args);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 9 ▶use Net::OpenStack::Client::API::Magic qw(retrieve);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 9 our $AUTOLOAD;
10  
11 9 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 9 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 104 ▶{
Subroutine AUTOLOAD: called CC=6 SCAR=19.6
21 104 my $called = $AUTOLOAD;
22  
23 # Don't mess with garbage collection!
24 104 ▶ return if $called =~ m{DESTROY};
Branch: 1 branch
BranchTrueFalseTotal
if $called =~ /DESTROY/ 7 97 104
25  
26 97 my $called_orig = $called;
27 97 $called =~ s{^.*::}{};
28  
29 97 my ($self, @args) = @_;
30  
31 97 my ($cmd, $fail);
32 97 my $api_pattern = "^${API_METHOD_PREFIX}([^_]+)_(.*)\$";
33 97 ▶ if (!defined($self->{versions})) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $self->{'versions'}) { } 0 97 97
elsif ($called =~ /$api_pattern/) { } 97 0 97
34 0 $fail = "no versions specified";
35 } elsif ($called =~ m/$api_pattern/) {
36 97 ($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 my $versions_txt = join(",", map {"$_=$self->{versions}->{$_}"} sort keys %{$self->{versions}});
41 0 $fail = "only $API_METHOD_PREFIX methods supported versions $versions_txt";
42 }
43  
44 97 ▶ if ($fail) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fail) { } 0 97 97
45 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 ▶ if (ref($cmd->{code}) eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $cmd->{'code'} eq 'CODE') { } 64 33 97
53 64 return $cmd->{code}->($self, @args);
54 } else {
55 33 return $self->rest(process_args($cmd, @args));
56 }
57 }
58 }
59  
60  
61 9 1;
« Client/Identity/Tagstore.pm ↑ Summary Client/Response.pm »