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

filter: Statementstmt 71.2% 72 / 101 Branchbran 50.0% 25 / 50 Conditioncond 44.4% 8 / 18 MC/DCmcdc 20.0% 2 / 10 Subroutinesub 85.7% 12 / 14 Podpod 25.0% 3 / 12 totaltotal 59.5% 122 / 205 CC 34 SCAR 36.5
CC
34
Cov
62%
resource_field_type
93.1
is_queryable
12.0
registry_lookup
7.1
CRAP 38.4
« blib/lib/WWW/GoDaddy/REST/Shell/DocsCommand.pm ↑ Summary blib/lib/WWW/GoDaddy/REST/Shell/Util.pm »
1 package WWW::GoDaddy::REST::Schema;
2  
3 4 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use WWW::GoDaddy::REST::Util qw( abs_url build_complex_query_url );
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 4 extends 'WWW::GoDaddy::REST::Resource';
7  
8 sub resource_field_names {
9 0 ▶ my $self = shift;
Subroutine resource_field_names: not called CC=1 SCAR=6.9
Pod undocumented
10 0 my %res_fields = %{ $self->f('resourceFields') };
11 0 return keys %res_fields;
12 }
13  
14 sub resource_field {
15 3 ▶ my $self = shift;
Subroutine resource_field: called CC=2 SCAR=7.2
Pod undocumented
16 3 my $name = shift;
17 3 my $res_fields = $self->f('resourceFields');
18 3 ▶ if ( !exists $res_fields->{$name} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $res_fields->{$name}) 0 3 3
19 0 return undef;
20 }
21 3 return $res_fields->{$name};
22 }
23  
24 sub resource_field_type {
25 3 ▶ my $self = shift;
Subroutine resource_field_type: called CC=18 SCAR=45.3
Pod undocumented
26 3 my $name = shift;
27 3 ▶ my $opts = shift || {};
Condition50%1/2
shift() || {}
l!l
03
MC/DC0%0/1
shift() || {}
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
28  
29 3 ▶ my $type = $self->resource_field($name)->{'type'} || 'string';
Condition50%1/2
$self->resource_field($name)->{'type'} || 'string'
l!l
30
MC/DC0%0/1
$self->resource_field($name)->{'type'} || 'string'
$self->resource_field($name)->{'type'}
Truth table50%1/2
A
A= $self->resource_field($name)->{'type'}
Aresult
11
00
30 3 my $want_array = wantarray;
31 3 my $auto_upconvert_reference = $opts->{auto_upconvert_reference};
32 3 my $qualify_schema_types = $opts->{qualify_schema_types};
33  
34 3 ▶ if ( $want_array or $auto_upconvert_reference or $qualify_schema_types ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($want_array or $auto_upconvert_reference or $qualify_schema_types) 0 0 0
Condition33%2/6
$want_array or $auto_upconvert_reference or $qualify_schema_types
l!l&&r!l&&!r
300
$want_array or $auto_upconvert_reference
l!l&&r!l&&!r
300
MC/DC0%0/3
$want_array or $auto_upconvert_reference or $qualify_schema_types
$want_array $auto_upconvert_reference $qualify_schema_types
Truth table25%1/4
A or B or C
A= $want_arrayB= $auto_upconvert_referenceC= $qualify_schema_types
ABCresult
1XX1
01X1
0011
0000
35 3 my ( $a_type, $b_type ) = split( /[\[\]]/, $type );
36  
37 3 ▶ my $compound_type = $b_type ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$b_type ? : 1 2 3
38  
39 3 ▶ if ($auto_upconvert_reference) {
Branch: 1 branch
BranchTrueFalseTotal
if ($auto_upconvert_reference) 0 3 3
40  
41 # some schemas don't properly use the 'reference' type to indicate
42 # the complex relationship. Convention seems to favor two sorts
43 # of field names that link to complex types:
44 # mySchemaId
45 # my_schema_id
46 0 ▶ if ( !$compound_type && $name =~ /^(.*)(_id|Id)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $compound_type and $name =~ /^(.*)(_id|Id)$/) 0 0 0
Condition0%0/3
not $compound_type and $name =~ /^(.*)(_id|Id)$/
!ll&&!rl&&r
000
MC/DC0%0/2
not $compound_type and $name =~ /^(.*)(_id|Id)$/
not $compound_type $name =~ /^(.*)(_id|Id)$/
Truth table0%0/3
not(A) and B
A= not $compound_typeB= $name =~ /^(.*)(_id|Id)$/
ABresult
0X0
100
111
47 0 my $possible_schema = $self->client->schema($1);
48 0 ▶ if ($possible_schema) {
Branch: 1 branch
BranchTrueFalseTotal
if ($possible_schema) 0 0 0
49 0 $compound_type = 1;
50 0 $a_type = 'reference';
51 0 $b_type = $possible_schema->id;
52 }
53 }
54 }
55  
56 3 ▶ if ($qualify_schema_types) {
Branch: 1 branch
BranchTrueFalseTotal
if ($qualify_schema_types) 0 3 3
57 0 ▶ if ($compound_type) {
Branch: 1 branch
BranchTrueFalseTotal
if ($compound_type) { } 0 0 0
58 0 my $possible_schema = $self->client->schema($b_type);
59 0 ▶ if ($possible_schema) {
Branch: 1 branch
BranchTrueFalseTotal
if ($possible_schema) 0 0 0
60 0 $b_type = $possible_schema->link('self');
61 }
62 }
63 else {
64 0 my $possible_schema = $self->client->schema($a_type);
65 0 ▶ if ($possible_schema) {
Branch: 1 branch
BranchTrueFalseTotal
if ($possible_schema) 0 0 0
66 0 $a_type = $possible_schema->link('self');
67 }
68 }
69 }
70  
71 3 ▶ if ($want_array) {
Branch: 1 branch
BranchTrueFalseTotal
if ($want_array) { } 3 0 3
72 3 ▶ if ($compound_type) {
Branch: 1 branch
BranchTrueFalseTotal
if ($compound_type) { } 1 2 3
73 1 return ( $a_type, $b_type );
74 }
75 else {
76 2 return ( undef, $a_type );
77 }
78 }
79 else {
80 0 ▶ if ($compound_type) {
Branch: 1 branch
BranchTrueFalseTotal
if ($compound_type) { } 0 0 0
81 0 $type = sprintf( '%s[%s]', $a_type, $b_type );
82 }
83 else {
84 0 $type = $a_type;
85 }
86 }
87 }
88 0 return $type;
89 }
90  
91 sub query {
92 5 ▶ my $self = shift;
Subroutine query: called CC=2 SCAR=6.9
Pod documented
93  
94 5 ▶ if ( !ref( $_[0] ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $_[0]) { } 2 3 5
95 2 return $self->query_by_id(@_);
96 }
97 else {
98 3 return $self->query_complex(@_);
99 }
100  
101 }
102  
103 sub query_complex {
104 3 ▶ my $self = shift;
Subroutine query_complex: called CC=2 SCAR=6.9
Pod documented
105  
106 3 my $url = build_complex_query_url( $self->query_url, @_ );
107  
108 3 my $resource = $self->client->http_request_as_resource( 'GET', $url );
109  
110 3 ▶ return wantarray ? $resource->items() : $resource;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 2 1 3
111 }
112  
113 sub query_by_id {
114 8 ▶ my $self = shift;
Subroutine query_by_id: called CC=2 SCAR=6.9
Pod documented
115 8 my $id = shift;
116 8 ▶ my $opts = shift || {};
Condition100%2/2
shift() || {}
l!l
26
MC/DC100%1/1
shift() || {}
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
117  
118 8 my $client = $self->client;
119 8 my $url = build_complex_query_url( $self->query_url($id), $opts );
120  
121 8 return $client->http_request_as_resource( 'GET', $url );
122 }
123  
124 sub create {
125 3 ▶ my $self = shift;
Subroutine create: called CC=1 SCAR=0.0
Pod undocumented
126  
127 3 my $client = $self->client;
128 3 my $url = $self->query_url;
129  
130 3 return $client->http_request_as_resource( 'POST', $url, @_ );
131 }
132  
133 sub is_queryable {
134 0 ▶ my $self = shift;
Subroutine is_queryable: not called CC=3 SCAR=24.8
Pod undocumented
135 0 ▶ if ( $self->id eq 'schema' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->id eq "schema") 0 0 0
136 0 return 1;
137 }
138 0 ▶ if ( $self->link('collection') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->link("collection")) 0 0 0
139 0 return 1;
140 }
141 }
142  
143 sub query_url {
144 15 ▶ my $self = shift;
Subroutine query_url: called CC=4 SCAR=14.2
Pod undocumented
145 15 my ($id) = @_;
146  
147 15 ▶ my $base_url = $self->id eq 'schema' ? $self->link('schemas') : $self->link('collection');
Branch: 1 branch
BranchTrueFalseTotal
$self->id eq 'schema' ? : 0 15 15
148 15 ▶ if ( !defined $base_url ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $base_url) 0 15 15
149 0 die( "Unable to build a query url: schema '" . $self->id . "' has no 'collection' link" );
150 }
151 15 ▶ if ( defined $id ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $id) 9 6 15
152 9 return abs_url( $base_url, $id );
153 }
154 6 return $base_url;
155 }
156  
157 4 our %REGISTRY;
158  
159 sub registry_add {
160 80 ▶ my $class = shift;
Subroutine registry_add: called CC=2 SCAR=6.9
Pod undocumented
161 80 my %schemas = @_;
162 80 ▶ while ( my ( $key, $object ) = each(%schemas) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %schemas) 80 80 160
163 80 $REGISTRY{$key} = $object;
164 }
165 }
166  
167 sub registry_lookup {
168 30 ▶ my $class = shift;
Subroutine registry_lookup: called CC=7 SCAR=19.7
Pod undocumented
169 30 my @possibles = @_;
170 30 foreach my $find (@possibles) {
171 30 ▶ next unless defined $find;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $find 4 26 30
172 26 ▶ if ( exists $REGISTRY{$find} and defined $REGISTRY{$find} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $WWW::GoDaddy::REST::Schema::REGISTRY{$find} and defined $WWW::GoDaddy::REST::Schema::REGISTRY{$find}) 25 1 26
Condition66%2/3
exists $WWW::GoDaddy::REST::Schema::REGISTRY{$find} and defined $WWW::GoDaddy::REST::Schema::REGISTRY{$find}
!ll&&!rl&&r
1025
MC/DC50%1/2
exists $WWW::GoDaddy::REST::Schema::REGISTRY{$find} and defined $WWW::GoDaddy::REST::Schema::REGISTRY{$find}
exists $WWW::GoDaddy::REST::Schema::REGISTRY{$find} defined $WWW::GoDaddy::REST::Schema::REGISTRY{$find}
Truth table66%2/3
A and B
A= exists $WWW::GoDaddy::REST::Schema::REGISTRY{$find}B= defined $WWW::GoDaddy::REST::Schema::REGISTRY{$find}
ABresult
0X0
100
111
173 25 return $REGISTRY{$find};
174 }
175 1 ▶ while ( my ( $key, $schema ) = each %REGISTRY ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %WWW::GoDaddy::REST::Schema::REGISTRY) 20 1 21
176 20 ▶ if ( lc($find) eq lc($key) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (lc $find eq lc $key) 0 20 20
177 0 return $schema;
178 }
179 }
180 }
181 5 return;
182  
183 }
184  
185 sub registry_list {
186 4 ▶ my $class = shift;
Subroutine registry_list: called CC=1 SCAR=0.0
Pod undocumented
187 4 my %seen;
188 4 return grep { not $seen{ $_->id }++ } values %REGISTRY;
189 }
190  
191 4 1;
192  
193 =head1 NAME
194  
195 WWW::GoDaddy::REST::Schema - schema specific resource class
196  
197 =head1 SYNOPSIS
198  
199 $schema = $client->schema('the_name');
200 $scehama = $resource->schema();
201  
202 =head1 DESCRIPTION
203  
204 This is used to represent a 'schema' which is a very common resource in the
205 Go Daddy(r) API specification.
206  
207 It is a sub class of L<WWW::GoDaddy::REST::Resource>.
208  
209 =head1 METHODS
210  
211 =over 4
212  
213 =item query
214  
215 This is a helper method that, based on the parameters
216 will choose to call C<query_by_id> or C<query_complex>.
217  
218 You probably should not be calling this directly.
219  
220 See the C<query> method on L<WWW::GoDaddy::REST|WWW::GoDaddy::REST>.
221  
222 Example:
223  
224 $schema->query('1234'); # query_by_id('1234')
225 $schema->query('1234', { opt => '1' } ); # query_by_id('1234', { opt => '1' } )
226  
227 =item query_by_id
228  
229 Returns a L<Resource|WWW::GoDaddy::REST::Resource> given
230 an C<id> parameter and an optional hash reference with additional key value pairs.
231  
232 You probably should not be calling this directly.
233  
234 See the C<query> method on the L<client instance|WWW::GoDaddy::REST>.
235  
236 Example:
237  
238 $resource = $schema->query_by_id('1234');
239 $resource = $schema->query_by_id('1234', { opt => '1' } );
240  
241 =item query_complex
242  
243 Search against the collection defined by this resource.
244  
245 Returns a L<Collection|WWW::GoDaddy::REST::Collection> given a hash ref with
246 key value pairs.
247  
248 Example:
249  
250 $resource = $schema->query_complex( { opt => '1' } );
251  
252 =back
253  
254 =head1 AUTHOR
255  
256 David Bartle, C<< <davidb@mediatemple.net> >>
257  
258 =head1 COPYRIGHT & LICENSE
259  
260 Copyright (c) 2014 Go Daddy Operating Company, LLC
261  
262 Permission is hereby granted, free of charge, to any person obtaining a
263 copy of this software and associated documentation files (the "Software"),
264 to deal in the Software without restriction, including without limitation
265 the rights to use, copy, modify, merge, publish, distribute, sublicense,
266 and/or sell copies of the Software, and to permit persons to whom the
267 Software is furnished to do so, subject to the following conditions:
268  
269 The above copyright notice and this permission notice shall be included in
270 all copies or substantial portions of the Software.
271  
272 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
273 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
274 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
275 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
276 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
277 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
278 DEALINGS IN THE SOFTWARE.
279  
280 =cut
« blib/lib/WWW/GoDaddy/REST/Shell/DocsCommand.pm ↑ Summary blib/lib/WWW/GoDaddy/REST/Shell/Util.pm »