| 1 | package WWW::GoDaddy::REST::Shell::Util; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 1 | ▶ | use Sub::Exporter -setup => { exports => [qw(get_resource_by_schema_or_uri)] }; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 0 | ▶ | sub get_resource_by_schema_or_uri { | ||||||||
|
Subroutine
get_resource_by_schema_or_uri: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||
| 9 | 0 | my ( $self, $schema_or_uri, $id ) = @_; | |||||||||
| 10 | |||||||||||
| 11 | 0 | my $client = $self->client; | |||||||||
| 12 | |||||||||||
| 13 | 0 | ▶ | if ( !defined $schema_or_uri ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 14 | 0 | die("schema or uri is required"); | |||||||||
| 15 | } | ||||||||||
| 16 | |||||||||||
| 17 | 0 | my $resource; | |||||||||
| 18 | 0 | ▶ | if ( $schema_or_uri =~ /\// ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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 | ▶ | if ( !$schema ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 24 | 0 | die("'$schema_or_uri' is not a recognized schema"); | |||||||||
| 25 | } | ||||||||||
| 26 | |||||||||||
| 27 | 0 | ▶ | if ( !$schema->is_queryable ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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 | ▶ | if ( !defined $id ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 33 | 0 | die("'id' is required"); | |||||||||
| 34 | } | ||||||||||
| 35 | |||||||||||
| 36 | 0 | return $resource = eval { $client->query_by_id( $schema_or_uri, $id ); }; | |||||||||
| 37 | } | ||||||||||
| 38 | |||||||||||
| 39 | } | ||||||||||
| 40 | |||||||||||
| 41 | 1 | 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 | ||||||||||