File Coverage

blib/lib/WWW/GoDaddy/REST/Shell/Util.pm
Criterion Covered Total %
statement 9 25 36.0
branch 0 10 0.0
condition n/a
subroutine 3 4 75.0
pod 0 1 0.0
total 12 40 30.0


line stmt bran cond sub pod time code
1             package WWW::GoDaddy::REST::Shell::Util;
2              
3 1     1   102 use strict;
  1         2  
  1         60  
4 1     1   6 use warnings;
  1         1  
  1         30  
5              
6 1     1   4 use Sub::Exporter -setup => { exports => [qw(get_resource_by_schema_or_uri)] };
  1         1  
  1         7  
7              
8             sub get_resource_by_schema_or_uri {
9 0     0 0   my ( $self, $schema_or_uri, $id ) = @_;
10              
11 0           my $client = $self->client;
12              
13 0 0         if ( !defined $schema_or_uri ) {
14 0           die("schema or uri is required");
15             }
16              
17 0           my $resource;
18 0 0         if ( $schema_or_uri =~ /\// ) {
19 0           return $client->http_request_as_resource( 'GET', $schema_or_uri );
20             }
21             else {
22 0           my $schema = $client->schema($schema_or_uri);
23 0 0         if ( !$schema ) {
24 0           die("'$schema_or_uri' is not a recognized schema");
25             }
26              
27 0 0         if ( !$schema->is_queryable ) {
28 0           die("This schema has no 'collection' link. It does not look like it can be queried. You can always try using a direct URL as a way around this if you know a URL exists to query this."
29             );
30             }
31              
32 0 0         if ( !defined $id ) {
33 0           die("'id' is required");
34             }
35              
36 0           return $resource = eval { $client->query_by_id( $schema_or_uri, $id ); };
  0            
37             }
38              
39             }
40              
41             1;
42              
43             =head1 AUTHOR
44              
45             David Bartle, C<< <davidb@mediatemple.net> >>
46              
47             =head1 COPYRIGHT & LICENSE
48              
49             Copyright (c) 2014 Go Daddy Operating Company, LLC
50              
51             Permission is hereby granted, free of charge, to any person obtaining a
52             copy of this software and associated documentation files (the "Software"),
53             to deal in the Software without restriction, including without limitation
54             the rights to use, copy, modify, merge, publish, distribute, sublicense,
55             and/or sell copies of the Software, and to permit persons to whom the
56             Software is furnished to do so, subject to the following conditions:
57              
58             The above copyright notice and this permission notice shall be included in
59             all copies or substantial portions of the Software.
60              
61             THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
62             IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
63             FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
64             THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
65             LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
66             FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
67             DEALINGS IN THE SOFTWARE.
68              
69             =cut