|  line  | 
 stmt  | 
 bran  | 
 cond  | 
 sub  | 
 pod  | 
 time  | 
 code  | 
| 
1
 | 
  
 
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 package OpenStack::MetaAPI::Roles::Listable;  | 
| 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
3
 | 
5
 | 
 
 | 
 
 | 
  
5
  
 | 
 
 | 
2581
 | 
 use strict;  | 
| 
 
 | 
5
 | 
 
 | 
 
 | 
 
 | 
 
 | 
12
 | 
    | 
| 
 
 | 
5
 | 
 
 | 
 
 | 
 
 | 
 
 | 
135
 | 
    | 
| 
4
 | 
5
 | 
 
 | 
 
 | 
  
5
  
 | 
 
 | 
23
 | 
 use warnings;  | 
| 
 
 | 
5
 | 
 
 | 
 
 | 
 
 | 
 
 | 
10
 | 
    | 
| 
 
 | 
5
 | 
 
 | 
 
 | 
 
 | 
 
 | 
113
 | 
    | 
| 
5
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
6
 | 
5
 | 
 
 | 
 
 | 
  
5
  
 | 
 
 | 
22
 | 
 use Moo::Role;  | 
| 
 
 | 
5
 | 
 
 | 
 
 | 
 
 | 
 
 | 
8
 | 
    | 
| 
 
 | 
5
 | 
 
 | 
 
 | 
 
 | 
 
 | 
26
 | 
    | 
| 
7
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
8
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub _list {  | 
| 
9
 | 
20
 | 
 
 | 
 
 | 
  
20
  
 | 
 
 | 
38
 | 
     my ($self, $all_args, $caller_args) = @_;  | 
| 
10
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
11
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
   # all_args are arguments from the internal OpenStack::MetaAPI::API  | 
| 
12
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
   # caller_args are coming from the user to filter the results  | 
| 
13
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
   #   if some filters are also arguments to the request  | 
| 
14
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
   #   then appending them to the query will shorten the output and run it faster  | 
| 
15
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
16
 | 
20
 | 
 
 | 
 
 | 
 
 | 
 
 | 
27
 | 
     my @all;  | 
| 
17
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     {  | 
| 
18
 | 
20
 | 
 
 | 
 
 | 
 
 | 
 
 | 
30
 | 
         my ($uri, @extra) = @$all_args;  | 
| 
 
 | 
20
 | 
 
 | 
 
 | 
 
 | 
 
 | 
44
 | 
    | 
| 
19
 | 
20
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
84
 | 
         $uri = $self->root_uri($uri)  | 
| 
20
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
           if $uri !~ m{^/v};    # can be removed once dynmaic methods are used  | 
| 
21
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
22
 | 
20
 | 
 
 | 
 
 | 
 
 | 
 
 | 
311
 | 
         my $extra_filters =  | 
| 
23
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
           $self->api_specs()->query_filters_for('/get', $uri, $caller_args);  | 
| 
24
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
25
 | 
20
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
50
 | 
         if ($extra_filters) {  | 
| 
26
 | 
2
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
5
 | 
             if (scalar @extra == 1) {  | 
| 
 
 | 
 
 | 
  
  0
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
27
 | 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
4
 | 
                 push @extra, {};  | 
| 
28
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
             } elsif (scalar @extra > 1) {  | 
| 
29
 | 
  
0
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
0
 | 
                 die "Too many args when calling _list for all...";  | 
| 
30
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
             }  | 
| 
31
 | 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
3
 | 
             $extra[-1] = {%{$extra[-1]}, %$extra_filters};  | 
| 
 
 | 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
6
 | 
    | 
| 
32
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         }  | 
| 
33
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
34
 | 
20
 | 
 
 | 
 
 | 
 
 | 
 
 | 
325
 | 
         @all = $self->client->all($uri, @extra);  | 
| 
35
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     }  | 
| 
36
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
37
 | 
20
 | 
 
 | 
 
 | 
 
 | 
 
 | 
40681
 | 
     my @args = @$caller_args;  | 
| 
38
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
39
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     # apply our filters to the raw results  | 
| 
40
 | 
20
 | 
 
 | 
 
 | 
 
 | 
 
 | 
35
 | 
     my $nargs = scalar @args;  | 
| 
41
 | 
20
 | 
  
100
  
 | 
  
 66
  
 | 
 
 | 
 
 | 
96
 | 
     if ($nargs && $nargs % 2 == 0) {  | 
| 
42
 | 
17
 | 
 
 | 
 
 | 
 
 | 
 
 | 
46
 | 
         my %opts = @args;  | 
| 
43
 | 
17
 | 
 
 | 
 
 | 
 
 | 
 
 | 
46
 | 
         foreach my $filter (sort keys %opts) {  | 
| 
44
 | 
17
 | 
 
 | 
 
 | 
 
 | 
 
 | 
25
 | 
             my @keep;  | 
| 
45
 | 
17
 | 
 
 | 
  
 50
  
 | 
 
 | 
 
 | 
46
 | 
             my $filter_isa = ref $opts{$filter} // '';  | 
| 
46
 | 
17
 | 
 
 | 
 
 | 
 
 | 
 
 | 
30
 | 
             foreach my $candidate (@all) {  | 
| 
47
 | 
43
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
82
 | 
                 next unless ref $candidate;  | 
| 
48
 | 
43
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
77
 | 
                 if ($filter_isa eq 'Regexp') {  | 
| 
49
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
50
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
                     # can use a regexp as a filter  | 
| 
51
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
                     next  | 
| 
52
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
                       unless $candidate->{$filter}  | 
| 
53
 | 
0
 | 
  
  0
  
 | 
  
  0
  
 | 
 
 | 
 
 | 
0
 | 
                       && $candidate->{$filter} =~ $opts{$filter};  | 
| 
54
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
                 } else {  | 
| 
55
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
56
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
                     # otherwise do one 'eq' check  | 
| 
57
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
                     next  | 
| 
58
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
                       unless $candidate->{$filter}  | 
| 
59
 | 
43
 | 
  
100
  
 | 
  
 66
  
 | 
 
 | 
 
 | 
154
 | 
                       && $candidate->{$filter} eq $opts{$filter};  | 
| 
60
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
                 }  | 
| 
61
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
62
 | 
15
 | 
 
 | 
 
 | 
 
 | 
 
 | 
28
 | 
                 push @keep, $candidate;  | 
| 
63
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
             }  | 
| 
64
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
65
 | 
17
 | 
 
 | 
 
 | 
 
 | 
 
 | 
81
 | 
             @all = @keep;  | 
| 
66
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
67
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         }  | 
| 
68
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     }  | 
| 
69
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
70
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     # avoid to return a list when possible  | 
| 
71
 | 
20
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
177
 | 
     return $all[0] if scalar @all <= 1;  | 
| 
72
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
73
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     # return a list  | 
| 
74
 | 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
37
 | 
     return @all;  | 
| 
75
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
76
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
77
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 1;  | 
| 
78
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
79
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 __END__  |