blib/lib/WWW/GoDaddy/REST/Resource.pm

filter: Statementstmt 91.7% 144 / 157 Branchbran 75.0% 30 / 40 Conditioncond 45.1% 14 / 31 MC/DCmcdc 10.0% 2 / 20 Subroutinesub 96.7% 30 / 31 Podpod 100% 23 / 23 totaltotal 80.4% 243 / 302 CC 35 SCAR 16.4
CC
35
Cov
82%
f_as_resources
17.3
new_subclassed
5.0
data
4.2
CRAP 5.1
« blib/lib/WWW/GoDaddy/REST/Shell/GetCommand.pm ↑ Summary blib/lib/WWW/GoDaddy/REST/Util.pm »
1 package WWW::GoDaddy::REST::Resource;
2  
3 4 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use List::MoreUtils qw( natatime );
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use WWW::GoDaddy::REST::Util qw( abs_url json_instance json_encode json_decode is_json );
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 4 ▶use constant DEFAULT_IMPL_CLASS => 'WWW::GoDaddy::REST::Resource';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use overload '""' => \&to_string;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 4 has 'client' => (
12 is => 'rw',
13 isa => 'WWW::GoDaddy::REST',
14 required => 1
15 );
16  
17 4 has 'fields' => (
18 is => 'ro',
19 isa => 'HashRef',
20 required => 1,
21 );
22  
23 4 has 'http_response' => (
24 is => 'ro',
25 isa => 'Maybe[HTTP::Response]',
26 required => 0
27 );
28  
29 sub save {
30 1 ▶ my $self = shift;
Subroutine save: called CC=2 SCAR=7.6
Pod documented
31 1 ▶ my $url = $self->link('self') || $self->client->schema( $self->type )->query_url( $self->id );
Condition33%1/3
$self->link('self') || $self->client->schema($self->type)->query_url($self->id)
l!l&&r!l&&!r
100
MC/DC0%0/2
$self->link('self') || $self->client->schema($self->type)->query_url($self->id)
$self->link('self') $self->client->schema($self->type)->query_url($self->id)
Truth table33%1/3
A || B
A= $self->link('self')B= $self->client->schema($self->type)->query_url($self->id)
ABresult
1X1
011
000
32 1 return $self->client->http_request_as_resource( 'PUT', $url, $self );
33 }
34  
35 sub delete {
36 1 ▶ my $self = shift;
Subroutine delete: called CC=2 SCAR=7.6
Pod documented
37 1 ▶ my $url = $self->link('self') || $self->client->schema( $self->type )->query_url( $self->id );
Condition33%1/3
$self->link('self') || $self->client->schema($self->type)->query_url($self->id)
l!l&&r!l&&!r
100
MC/DC0%0/2
$self->link('self') || $self->client->schema($self->type)->query_url($self->id)
$self->link('self') $self->client->schema($self->type)->query_url($self->id)
Truth table33%1/3
A || B
A= $self->link('self')B= $self->client->schema($self->type)->query_url($self->id)
ABresult
1X1
011
000
38 1 return $self->client->http_request_as_resource( 'DELETE', $url, $self );
39 }
40  
41 sub follow_link {
42 2 ▶ my $self = shift;
Subroutine follow_link: called CC=2 SCAR=6.9
Pod documented
43 2 my $link_name = shift;
44  
45 2 my $link_url = $self->link($link_name);
46 2 ▶ if ( !$link_url ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($link_url) 1 1 2
47 1 my @valid_links = keys %{ $self->links() };
48 1 croak("$link_name is not a valid link name. Did you mean one of these? @valid_links");
49 }
50  
51 1 return $self->client->http_request_as_resource( 'GET', $link_url );
52 }
53  
54 sub do_action {
55 3 ▶ my $self = shift;
Subroutine do_action: called CC=2 SCAR=7.8
Pod documented
56 3 my $action = shift;
57 3 my $params = shift;
58  
59 3 my $action_url = $self->action($action);
60 3 ▶ if ( !$action_url ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($action_url) 0 3 3
61 0 my @valid_actions = keys %{ $self->actions() };
62 0 croak("$action is not a valid action name. Did you mean one of these? @valid_actions");
63 }
64  
65 3 return $self->client->http_request_as_resource( 'POST', $action_url, $params );
66  
67 }
68  
69 sub items {
70 0 ▶ my $self = shift;
Subroutine items: not called CC=1 SCAR=6.9
Pod documented
71 0 return ($self);
72 }
73  
74 sub id {
75 119 ▶ return shift->f('id');
Subroutine id: called CC=1 SCAR=0.0
Pod documented
76 }
77  
78 sub type {
79 9 ▶ return shift->f('type');
Subroutine type: called CC=1 SCAR=0.0
Pod documented
80 }
81  
82 sub type_fq {
83 5 ▶ my $self = shift;
Subroutine type_fq: called CC=1 SCAR=0.0
Pod documented
84  
85 5 my $base_url = $self->schemas_url;
86  
87 5 return abs_url( $base_url, $self->type );
88 }
89  
90 sub schema {
91 5 ▶ my $self = shift;
Subroutine schema: called CC=2 SCAR=7.6
Pod documented
92 5 ▶ my $schema = $self->client->schema( $self->type_fq ) || $self->client->schema( $self->type );
Condition33%1/3
$self->client->schema($self->type_fq) || $self->client->schema($self->type)
l!l&&r!l&&!r
500
MC/DC0%0/2
$self->client->schema($self->type_fq) || $self->client->schema($self->type)
$self->client->schema($self->type_fq) $self->client->schema($self->type)
Truth table33%1/3
A || B
A= $self->client->schema($self->type_fq)B= $self->client->schema($self->type)
ABresult
1X1
011
000
93 5 return $schema;
94 }
95  
96 sub link {
97 55 ▶ my $self = shift;
Subroutine link: called CC=2 SCAR=6.9
Pod documented
98 55 my $name = shift;
99  
100 55 my $links = $self->links();
101 55 ▶ if ( exists $links->{$name} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $links->{$name}) 53 2 55
102 53 return $links->{$name};
103 }
104 2 return undef;
105 }
106  
107 sub links {
108 56 ▶ return shift->f('links');
Subroutine links: called CC=1 SCAR=0.0
Pod documented
109 }
110  
111 sub action {
112 3 ▶ my $self = shift;
Subroutine action: called CC=2 SCAR=7.2
Pod documented
113 3 my $name = shift;
114  
115 3 my $actions = $self->actions();
116 3 ▶ if ( exists $actions->{$name} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $actions->{$name}) 3 0 3
117 3 return $actions->{$name};
118 }
119 0 return undef;
120 }
121  
122 sub actions {
123 3 ▶ return shift->f('actions');
Subroutine actions: called CC=1 SCAR=0.0
Pod documented
124 }
125  
126 sub f {
127 230 ▶ return shift->field(@_);
Subroutine f: called CC=1 SCAR=0.0
Pod documented
128 }
129  
130 sub f_as_resources {
131 5 ▶ my $self = shift;
Subroutine f_as_resources: called CC=12 SCAR=28.5
Pod documented
132 5 my $field = shift;
133 5 my $raw_data = $self->f($field);
134  
135 5 my ( $container, $type ) = $self->schema->resource_field_type($field);
136 5 my %defaults = (
137 client => $self->client,
138 http_response => $self->http_response
139 );
140  
141 5 my $type_schema = $self->client->schema($type);
142 5 ▶ if ($type_schema) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type_schema) 4 1 5
143 4 ▶ if ( $container && $container eq 'map' ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($container and $container eq 'map') { } 1 3 4
elsif ($container and $container eq 'array') { } 3 0 3
elsif (ref $raw_data eq 'HASH') { } 0 0 0
Condition66%2/3
$container and $container eq "map"
!ll&&!rl&&r
031
MC/DC50%1/2
$container and $container eq "map"
$container $container eq "map"
Truth table66%2/3
A and B
A= $containerB= $container eq "map"
ABresult
0X0
100
111
144 1 my %ret;
145 1 foreach ( my ( $k, $v ) = each %{$raw_data} ) {
146 2 ▶ $v->{type} ||= $type_schema->id;
Condition66%2/3
$v->{"type"} ||= $type_schema->id
l!l&&r!l&&!r
110
MC/DC0%0/2
$v->{"type"} ||= $type_schema->id
$v->{"type"} $type_schema->id
Truth table66%2/3
A ||= B
A= $v->{"type"}B= $type_schema->id
ABresult
1X1
011
000
147 2 $ret{$k} = $self->new_subclassed( { %defaults, fields => $v } );
148 }
149 1 return \%ret;
150 }
151 ▶ elsif ( $container && $container eq 'array' ) {
Condition33%1/3
$container and $container eq "array"
!ll&&!rl&&r
003
MC/DC0%0/2
$container and $container eq "array"
$container $container eq "array"
Truth table33%1/3
A and B
A= $containerB= $container eq "array"
ABresult
0X0
100
111
152 3 my @ret;
153 3 foreach my $v ( @{$raw_data} ) {
154 17 ▶ $v->{type} ||= $type_schema->id;
Condition33%1/3
$v->{"type"} ||= $type_schema->id
l!l&&r!l&&!r
1700
MC/DC0%0/2
$v->{"type"} ||= $type_schema->id
$v->{"type"} $type_schema->id
Truth table33%1/3
A ||= B
A= $v->{"type"}B= $type_schema->id
ABresult
1X1
011
000
155 17 push @ret, $self->new_subclassed( { %defaults, fields => $v } );
156 }
157 3 return \@ret;
158 }
159 elsif ( ref($raw_data) eq 'HASH' ) {
160 0 my %ret = %{$raw_data};
161 0 ▶ $ret{type} ||= $type_schema->id;
Condition0%0/3
$ret{"type"} ||= $type_schema->id
l!l&&r!l&&!r
000
MC/DC0%0/2
$ret{"type"} ||= $type_schema->id
$ret{"type"} $type_schema->id
Truth table0%0/3
A ||= B
A= $ret{"type"}B= $type_schema->id
ABresult
1X1
011
000
162 0 return $self->new_subclassed( { %defaults, fields => \%ret } );
163 }
164 }
165  
166 # just return the raw data if not returned otherwise
167 1 return $raw_data;
168  
169 }
170  
171 sub field {
172 233 ▶ my $self = shift;
Subroutine field: called CC=2 SCAR=6.9
Pod documented
173 233 ▶ if ( @_ <= 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ <= 1) { } 228 5 233
174 228 return $self->_get_field(@_);
175 }
176 else {
177 5 return $self->_set_field(@_);
178 }
179 }
180  
181 sub schemas_url {
182 5 ▶ my $self = shift;
Subroutine schemas_url: called CC=3 SCAR=11.4
Pod documented
183  
184 5 my $found;
185  
186 5 my $http_resp = $self->http_response;
187 5 my $link = $self->link('schemas');
188  
189 5 ▶ if ( $http_resp && $http_resp->header('X-API-Schemas') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($http_resp and $http_resp->header("X-API-Schemas")) 0 5 5
Condition66%2/3
$http_resp and $http_resp->header("X-API-Schemas")
!ll&&!rl&&r
320
MC/DC0%0/2
$http_resp and $http_resp->header("X-API-Schemas")
$http_resp $http_resp->header("X-API-Schemas")
Truth table66%2/3
A and B
A= $http_respB= $http_resp->header("X-API-Schemas")
ABresult
0X0
100
111
190 0 return $http_resp->header('X-API-Schemas');
191 }
192  
193 5 return $self->client->schemas_url;
194 }
195  
196 sub _get_field {
197 228 ▶ my $self = shift;
Subroutine _get_field: called CC=2 SCAR=6.9
198 228 my $name = shift;
199  
200 228 ▶ if ( !exists $self->fields->{$name} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->fields->{$name}) 1 227 228
201 1 return undef;
202 }
203 227 return $self->fields->{$name};
204  
205 }
206  
207 sub _set_field {
208 5 ▶ my $self = shift;
Subroutine _set_field: called CC=1 SCAR=0.0
209 5 my $name = shift;
210 5 my $value = shift;
211 5 $self->fields->{$name} = $value;
212 5 return $self->fields->{$name};
213 }
214  
215 sub new_subclassed {
216 71 ▶ my $class = shift;
Subroutine new_subclassed: called CC=5 SCAR=16.2
Pod documented
217 71 my $params = shift;
218  
219 71 my $data = $params->{fields};
220  
221 71 my $impl = DEFAULT_IMPL_CLASS;
222 71 ▶ if ( ref($data) eq "HASH" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $data eq 'HASH') { } 67 4 71
223 67 ▶ my $type_short = $params->{fields}->{type} || '';
Condition50%1/2
$params->{'fields'}{'type'} || ''
l!l
670
MC/DC0%0/1
$params->{'fields'}{'type'} || ''
$params->{'fields'}{'type'}
Truth table50%1/2
A
A= $params->{'fields'}{'type'}
Aresult
11
00
224 67 ▶ my $type_long = $type_short ? $params->{client}->schemas_url($type_short) : '';
Branch: 1 branch
BranchTrueFalseTotal
$type_short ? : 67 0 67
225  
226 67 ▶ $impl = $class->find_implementation( ( $type_long, $type_short ) ) || DEFAULT_IMPL_CLASS;
Condition100%2/2
$class->find_implementation($type_long, $type_short) || 'WWW::GoDaddy::REST::Resource'
l!l
4720
MC/DC100%1/1
$class->find_implementation($type_long, $type_short) || 'WWW::GoDaddy::REST::Resource'
$class->find_implementation($type_long, $type_short)
Truth table100%2/2
A
A= $class->find_implementation($type_long, $type_short)
Aresult
11
00
227 67 eval "require $impl;";
228 }
229 else {
230  
231 # hmm, the json response didn't seem to be a hashref...
232 # well in this case, there are not really any fields
233 # so the caller will have to check the http_response
234 # content
235 4 $params->{fields} = {};
236 }
237  
238 71 return $impl->new($params);
239  
240 }
241  
242 sub TO_JSON {
243 20 ▶ my $self = shift;
Subroutine TO_JSON: called CC=1 SCAR=0.0
Pod documented
244 20 return $self->data;
245 }
246  
247 sub data {
248 23 ▶ my $self = shift;
Subroutine data: called CC=4 SCAR=14.2
Pod documented
249  
250 23 my %fields = %{ $self->fields };
251 23 ▶ if (%fields) {
Branch: 2 branches
BranchTrueFalseTotal
if (%fields) { } 20 3 23
elsif ($self->http_response) { } 3 0 3
252 20 return \%fields;
253 }
254 elsif ( $self->http_response ) {
255 3 my $content = $self->http_response->decoded_content;
256 3 ▶ return is_json($content) ? json_decode($content) : $content;
Branch: 1 branch
BranchTrueFalseTotal
is_json($content) ? : 3 0 3
257 }
258 0 return {};
259 }
260  
261 sub to_string {
262 18 ▶ my $self = shift;
Subroutine to_string: called CC=2 SCAR=7.2
Pod documented
263 18 my $pretty = shift;
264  
265 18 my $JSON = json_instance();
266 18 ▶ if ($pretty) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pretty) 0 18 18
267 0 $JSON->pretty(1);
268 }
269 18 return json_encode( $self, $JSON );
270 }
271  
272 4 my %SCHEMA_TO_IMPL = (
273 'collection' => 'WWW::GoDaddy::REST::Collection',
274 'schema' => 'WWW::GoDaddy::REST::Schema',
275 );
276  
277 sub find_implementation {
278 73 ▶ my $class = shift;
Subroutine find_implementation: called CC=3 SCAR=11.0
Pod documented
279 73 my @look_for = @_;
280  
281 73 foreach (@look_for) {
282 140 ▶ if ( exists $SCHEMA_TO_IMPL{$_} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $SCHEMA_TO_IMPL{$_}) 52 88 140
283 52 return $SCHEMA_TO_IMPL{$_};
284 }
285 }
286 21 return;
287 }
288  
289 sub register_implementation {
290 3 ▶ my $class = shift;
Subroutine register_implementation: called CC=3 SCAR=11.0
Pod documented
291  
292 3 ▶ if ( @_ % 2 != 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ % 2 != 0) 1 2 3
293 1 croak("Expecting even number of parameters");
294 }
295  
296 2 my $iterator = natatime 2, @_;
297 2 ▶ while ( my ( $schema, $subclass ) = $iterator->() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = &$iterator()) 3 2 5
298 3 $SCHEMA_TO_IMPL{$schema} = $subclass;
299 }
300 2 return;
301 }
302  
303 4 1;
304  
305 =head1 NAME
306  
307 WWW::GoDaddy::REST::Resource - Represent a REST resource
308  
309 =head1 SYNOPSIS
310  
311 $client = WWW::GoDaddy::REST->new(...);
312  
313 $resource = WWW::GoDaddy::REST::Resource->new({
314 client => $client,
315 fields => {
316 'type' => 'automobile',
317 'id' => '1001',
318 'make' => 'Tesla',
319 'model' => 'S'
320 'links' => {
321 'self' => 'https://example.com/v1/automobiles/1001',
322 'schemas' => 'https://example.com/v1/schemas'
323 },
324 'actions' => {
325 'charge' => 'https://example.com/v1/automobiles/1001?charge'
326 }
327 # ...
328 # see: https://github.com/godaddy/gdapi/blob/master/specification.md
329 },
330 });
331  
332 $resource->f('id'); # get 1001
333 $resource->f('id','2000'); # set to 2000 and return 2000
334  
335 # follow a link in links section
336 $schemas_resource = $resource->follow_link('schemas');
337  
338 # perform an action in the actions section
339 $result_resource = $resource->do_action('charge',{ 'with' => 'quick_charger' });
340  
341 =head1 DESCRIPTION
342  
343 Base class used to represent a REST resource.
344  
345 =head1 CLASS METHODS
346  
347 =over 4
348  
349 =item new
350  
351 Given a hash reference of L<"ATTRIBUTES"> and values, return a new instance
352 of this object.
353  
354 It is likely more important that you use the C<new_subclassed> class method.
355  
356 Example:
357  
358 my $resource = WWW::GoDaddy::REST::Resource->new({
359 client => WWW::GoDaddy::REST->new(...),
360 fields => {
361 id => '...',
362 ...
363 },
364 });
365  
366 =item new_subclassed
367  
368 This takes the same paramegers as C<new> and is the preferred construction
369 method. This tries to find the appropriate subclass of
370 C<WWW::GoDaddy::REST::Resource> and passes along the paramegers to the C<new>
371 method of that subclass instead.
372  
373 See also: C<new>
374  
375 =item find_implementation
376  
377 Given a list of schema type names, find the best implementation sub class.
378  
379 Returns the string of the class name. If no good subclass candidate is found,
380 returns undef.
381  
382 Example:
383  
384 find_implementation( 'schema' );
385 # WWW::GoDaddy::REST::Schema
386  
387 =item register_implementation
388  
389 Register a subclass handler for a schema type given a schema name and the
390 name of a L<WWW::GoDaddy::REST::Resource> subclass.
391  
392 This can take as many schema => resource class pairs as you want.
393  
394 Example:
395  
396 WWW::GoDaddy::REST::Resource->register_subclass( 'account' => 'My::AccountRes' );
397 WWW::GoDaddy::REST::Resource->register_subclass( 'foo' => 'Bar', 'baz' => 'Buzz' );
398  
399 =back
400  
401 =head1 ATTRIBUTES
402  
403 =over 4
404  
405 =item client
406  
407 Instance of L<WWW::GoDaddy::REST> associated with the resource.
408  
409 =item fields
410  
411 Hash reference containing the raw data for the underlying resource.
412  
413 Several methods delegate to this underlying structure such as C<f>,
414 and C<field>.
415  
416 =item http_response
417  
418 Optionally present instance of an L<HTTP::Response> object so that
419 you can inspect the HTTP information related to the resource.
420  
421 =back
422  
423 =head1 METHODS
424  
425 =over 4
426  
427 =item f
428  
429 Get or set a field by name. You may also use the longer name C<field>.
430  
431 When performing a set, it also returns the new value that was set.
432  
433 Example:
434  
435 $res->f('field_name'); # get
436 $res->f('field_name','new'); # set
437  
438 =item f_as_resources
439  
440 Get a field by name. If it is a resource, this will turn it into an
441 object instead of giving you the raw hash reference as the return value.
442  
443 Note, if the field is a 'map' or 'array' of resources, every item in
444 those lists will be 'resourcified'.
445  
446 If this is not a resource, then it does return the raw value.
447  
448 Example:
449  
450 # return value is a WWW::GoDaddy::REST::Resource, not a hash ref
451 $driver = $car->f('driver');
452  
453 See C<f> if you want the raw value. This will return the raw value, if
454 the value does not look like a resource.
455  
456 =item field
457  
458 Get or set a field by name. You may also use the shorter name C<f>.
459  
460 When performing a set, it also returns the new value that was set.
461  
462 Example:
463  
464 $res->field('field_name'); # get
465 $res->fieldf('field_name','new'); # set
466  
467 =item save
468  
469 Does a PUT at this resources URI. Returns a new resource object.
470  
471 Example:
472  
473 $r2 = $r1->save();
474  
475 =item delete
476  
477 Does a DELETE on this resource. Returns a new resource object. This
478 return value likely is only useful to get at the C<http_response> attribute.
479  
480 =item do_action
481  
482 Does a POST with the supplied data on the action URL with the given name.
483  
484 If the action with the provided name does not exist, this method will
485 die. See also: C<action> and C<actions>
486  
487 Example:
488  
489 $r2 = $r1->do_action('some_action',{ a => 'a_v' });
490  
491 =item follow_link
492  
493 Gets the resource by following the link URL with the provided name.
494  
495 If the link with the provided name does not exist, this method will
496 die. See also: C<link> and C<link>
497  
498 Example:
499  
500 $r2 = $r1->follow_link('some_link');
501  
502 =item id
503  
504 Return the id of this instance
505  
506 =item type
507  
508 Return the name of the schema type that this object belongs to.
509  
510 =item type_fq
511  
512 Return the full URI to the schema type that this object belongs to.
513  
514 =item schemas_url
515  
516 Returns the URL for the schema collection. This differs from the
517 client C<schemas_url> method since it has more places to look for hints
518 of the schemas collection url (headers, json response etc).
519  
520 Example:
521  
522 $r->schemas_url();
523  
524 =item schema
525  
526 Find and return the L<WWW::GoDaddy::REST::Schema> object that this is.
527  
528 =item link
529  
530 Return the link URL for the given name or undef if it does not exist.
531  
532 Example:
533  
534 # https://example.com/v1/thing/...
535 $r->link('self');
536 # 'https://example.com/v1/me/1'
537  
538 =item links
539  
540 Return the hashref that contains the link => url information
541  
542 Example:
543  
544 $r->links();
545 # {
546 # 'self' => 'https://example.com/v1/me/1',
547 # 'some_link' => 'https://example.com/v1/me/1/some_link'
548 # }
549  
550 =item action
551  
552 Return the action URL for the given name.
553  
554 Example:
555  
556 $r->action('custom_action');
557 # https://example.com/v1/thing/1001?some_action
558  
559 =item actions
560  
561 Return the hashref that contains the action => url information
562  
563 Example:
564  
565 $r->actions();
566 # {
567 # 'custom_action' => 'https://example.com/v1/thing/1001?some_action'
568 # }
569  
570 =item items
571  
572 Returns a list of resources that this resource contains. This implementation
573 simply returns a list of 'self'. It is here to be consistent with the
574 implementation found in L<WWW::GoDaddy::REST::Collection>.
575  
576 Example:
577  
578 @items = $resource->items();
579  
580 =item TO_JSON
581  
582 Returns a hashref that represents this object. This exists to make using the
583 L<JSON> module more convenient. This does NOT return a JSON STRING, just a
584 perl data structure.
585  
586 See C<to_string>.
587  
588 =item to_string
589  
590 Returns a JSON string that represents this object. This takes an optional
591 parameter, "pretty". If true, the json output will be prettified. This defaults
592 to false.
593  
594 =item data
595  
596 The resource is returned as a perl data structure. Note, if there are no
597 C<fields>, then the http_respons is consulted, if json data is found in
598 the content, that is returned (for instance, a plane old string or integer).
599  
600 =back
601  
602 =head1 AUTHOR
603  
604 David Bartle, C<< <davidb@mediatemple.net> >>
605  
606 =head1 COPYRIGHT & LICENSE
607  
608 Copyright (c) 2014 Go Daddy Operating Company, LLC
609  
610 Permission is hereby granted, free of charge, to any person obtaining a
611 copy of this software and associated documentation files (the "Software"),
612 to deal in the Software without restriction, including without limitation
613 the rights to use, copy, modify, merge, publish, distribute, sublicense,
614 and/or sell copies of the Software, and to permit persons to whom the
615 Software is furnished to do so, subject to the following conditions:
616  
617 The above copyright notice and this permission notice shall be included in
618 all copies or substantial portions of the Software.
619  
620 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
621 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
622 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
623 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
624 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
625 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
626 DEALINGS IN THE SOFTWARE.
627  
628  
629 =cut
« blib/lib/WWW/GoDaddy/REST/Shell/GetCommand.pm ↑ Summary blib/lib/WWW/GoDaddy/REST/Util.pm »