line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package VMware::vCloudDirector::Object; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: Module to contain an object! |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
1523
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
24
|
|
6
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
39
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.007'; # VERSION |
9
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:NIGELM'; # AUTHORITY |
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
65
|
use Moose; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
use Method::Signatures; |
13
|
|
|
|
|
|
|
use Ref::Util qw(is_plain_hashref); |
14
|
|
|
|
|
|
|
use Lingua::EN::Inflexion; |
15
|
|
|
|
|
|
|
use VMware::vCloudDirector::ObjectContent; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
has api => ( |
21
|
|
|
|
|
|
|
is => 'ro', |
22
|
|
|
|
|
|
|
isa => 'VMware::vCloudDirector::API', |
23
|
|
|
|
|
|
|
required => 1, |
24
|
|
|
|
|
|
|
weak_ref => 1, |
25
|
|
|
|
|
|
|
documentation => 'API we use' |
26
|
|
|
|
|
|
|
); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
has content => ( |
29
|
|
|
|
|
|
|
is => 'ro', |
30
|
|
|
|
|
|
|
isa => 'VMware::vCloudDirector::ObjectContent', |
31
|
|
|
|
|
|
|
predicate => 'has_content', |
32
|
|
|
|
|
|
|
writer => '_set_content', |
33
|
|
|
|
|
|
|
documentation => 'The underlying content object', |
34
|
|
|
|
|
|
|
handles => [qw( mime_type href type name )], |
35
|
|
|
|
|
|
|
); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
has _partial_object => ( is => 'rw', isa => 'Bool', default => 0 ); |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# delegates that force a full object to be pulled |
40
|
|
|
|
|
|
|
method hash () { return $self->inflate->content->hash; } |
41
|
|
|
|
|
|
|
method links () { return $self->inflate->content->links; } |
42
|
|
|
|
|
|
|
method id () { return $self->inflate->content->id; } |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
45
|
|
|
|
|
|
|
method BUILD ($args) { |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
$self->_set_content( |
48
|
|
|
|
|
|
|
VMware::vCloudDirector::ObjectContent->new( object => $self, hash => $args->{hash} ) ); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
method inflate () { |
55
|
|
|
|
|
|
|
$self->refetch if ( $self->_partial_object ); |
56
|
|
|
|
|
|
|
return $self; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
60
|
|
|
|
|
|
|
method refetch () { |
61
|
|
|
|
|
|
|
my $hash = $self->api->GET_hash( $self->href ); |
62
|
|
|
|
|
|
|
$self->_set_content( |
63
|
|
|
|
|
|
|
VMware::vCloudDirector::ObjectContent->new( object => $self, hash => $hash ) ); |
64
|
|
|
|
|
|
|
$self->api->_debug( |
65
|
|
|
|
|
|
|
sprintf( |
66
|
|
|
|
|
|
|
'Object: %s a [%s]', |
67
|
|
|
|
|
|
|
( $self->_partial_object ? 'Inflated' : 'Refetched' ), |
68
|
|
|
|
|
|
|
$self->type |
69
|
|
|
|
|
|
|
) |
70
|
|
|
|
|
|
|
) if ( $self->api->debug ); |
71
|
|
|
|
|
|
|
$self->_partial_object(0); |
72
|
|
|
|
|
|
|
return $self; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
method find_links (:$name, :$type, :$rel) { |
79
|
|
|
|
|
|
|
my @matched_links; |
80
|
|
|
|
|
|
|
my $links = $self->links; |
81
|
|
|
|
|
|
|
foreach my $link ( @{$links} ) { |
82
|
|
|
|
|
|
|
if ( not( defined($rel) ) or ( $rel eq ( $link->rel || '' ) ) ) { |
83
|
|
|
|
|
|
|
if ( not( defined($type) ) or ( $type eq ( $link->type || '' ) ) ) { |
84
|
|
|
|
|
|
|
if ( not( defined($name) ) or ( $name eq ( $link->name || '' ) ) ) { |
85
|
|
|
|
|
|
|
push( @matched_links, $link ); |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
return @matched_links; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
method fetch_links (@search_items) { |
97
|
|
|
|
|
|
|
my @matched_objects; |
98
|
|
|
|
|
|
|
foreach my $link ( $self->find_links(@search_items) ) { |
99
|
|
|
|
|
|
|
push( @matched_objects, $link->GET() ); |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
return @matched_objects; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
105
|
|
|
|
|
|
|
method _create_object ($hash, $type='Thing') { |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
# if thing has Link content within it then it is a full object, otherwise it |
108
|
|
|
|
|
|
|
# is just a stub |
109
|
|
|
|
|
|
|
my $object = VMware::vCloudDirector::Object->new( |
110
|
|
|
|
|
|
|
hash => { $type => $hash }, |
111
|
|
|
|
|
|
|
api => $self->api, |
112
|
|
|
|
|
|
|
_partial_object => ( exists( $hash->{Link} ) ) ? 0 : 1, |
113
|
|
|
|
|
|
|
); |
114
|
|
|
|
|
|
|
$self->api->_debug( |
115
|
|
|
|
|
|
|
sprintf( |
116
|
|
|
|
|
|
|
'Object: [%s] instantiated %s for [%s]', |
117
|
|
|
|
|
|
|
$self->type, ( $object->_partial_object ? 'a stub' : 'an object' ), |
118
|
|
|
|
|
|
|
$object->type |
119
|
|
|
|
|
|
|
) |
120
|
|
|
|
|
|
|
) if ( $self->api->debug ); |
121
|
|
|
|
|
|
|
return $object; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
method build_sub_objects ($type) { |
128
|
|
|
|
|
|
|
my @objects; |
129
|
|
|
|
|
|
|
my $container_type = noun($type)->plural; |
130
|
|
|
|
|
|
|
return |
131
|
|
|
|
|
|
|
unless ( exists( $self->hash->{$container_type} ) |
132
|
|
|
|
|
|
|
and is_plain_hashref( $self->hash->{$container_type} ) ); |
133
|
|
|
|
|
|
|
foreach my $thing ( $self->_listify( $self->hash->{$container_type}{$type} ) ) { |
134
|
|
|
|
|
|
|
push( @objects, $self->_create_object( $thing, $type ) ); |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
return @objects; |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
method build_children_objects () { |
140
|
|
|
|
|
|
|
my $hash = $self->hash; |
141
|
|
|
|
|
|
|
return unless ( exists( $hash->{Children} ) and is_plain_hashref( $hash->{Children} ) ); |
142
|
|
|
|
|
|
|
my @objects; |
143
|
|
|
|
|
|
|
foreach my $key ( keys %{ $hash->{Children} } ) { |
144
|
|
|
|
|
|
|
foreach my $thing ( $self->_listify( $self->hash->{Children}{$key} ) ) { |
145
|
|
|
|
|
|
|
push( @objects, $self->_create_object( $thing, $key ) ); |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
return @objects; |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
method DELETE () { return $self->api->GET( $self->href ); } |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
method GET () { return $self->api->GET( $self->href ); } |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
method POST ($xml_hash) { return $self->api->GET( $self->href, $xml_hash ); } |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
method PUT ($xml_hash) { return $self->api->GET( $self->href, $xml_hash ); } |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
166
|
|
|
|
|
|
|
method _listify ($thing) { !defined $thing ? () : ( ( ref $thing eq 'ARRAY' ) ? @{$thing} : $thing ) } |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
1; |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
__END__ |