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

filter: Statementstmt 69.7% 69 / 99 Branchbran 45.8% 22 / 48 Conditioncond 36.8% 7 / 19 MC/DCmcdc 9.0% 1 / 11 Subroutinesub 85.7% 12 / 14 Podpod 0.0% 0 / 12 totaltotal 54.6% 111 / 203 CC 33 SCAR 36.6
CC
33
Cov
59%
resource_field_type
93.1
is_queryable
12.0
registry_lookup
6.2
CRAP 39.0
« 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 5 ▶ my $self = shift;
Subroutine resource_field: called CC=2 SCAR=7.2
Pod undocumented
16 5 my $name = shift;
17 5 my $res_fields = $self->f('resourceFields');
18 5 ▶ if ( !exists $res_fields->{$name} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $res_fields->{$name}) 0 5 5
19 0 return undef;
20 }
21 5 return $res_fields->{$name};
22 }
23  
24 sub resource_field_type {
25 5 ▶ my $self = shift;
Subroutine resource_field_type: called CC=18 SCAR=45.3
Pod undocumented
26 5 my $name = shift;
27 5 ▶ my $opts = shift || {};
Condition50%1/2
shift() || {}
l!l
05
MC/DC0%0/1
shift() || {}
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
28  
29 5 ▶ my $type = $self->resource_field($name)->{'type'} || 'string';
Condition50%1/2
$self->resource_field($name)->{'type'} || 'string'
l!l
50
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 5 my $want_array = wantarray;
31 5 my $auto_upconvert_reference = $opts->{auto_upconvert_reference};
32 5 my $qualify_schema_types = $opts->{qualify_schema_types};
33  
34 5 ▶ 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
500
$want_array or $auto_upconvert_reference
l!l&&r!l&&!r
500
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 5 my ( $a_type, $b_type ) = split( /[\[\]]/, $type );
36  
37 5 ▶ my $compound_type = $b_type ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$b_type ? : 4 1 5
38  
39 5 ▶ if ($auto_upconvert_reference) {
Branch: 1 branch
BranchTrueFalseTotal
if ($auto_upconvert_reference) 0 5 5
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 5 ▶ if ($qualify_schema_types) {
Branch: 1 branch
BranchTrueFalseTotal
if ($qualify_schema_types) 0 5 5
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 5 ▶ if ($want_array) {
Branch: 1 branch
BranchTrueFalseTotal
if ($want_array) { } 5 0 5
72 5 ▶ if ($compound_type) {
Branch: 1 branch
BranchTrueFalseTotal
if ($compound_type) { } 4 1 5
73 4 return ( $a_type, $b_type );
74 }
75 else {
76 1 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 2 ▶ my $self = shift;
Subroutine query: called CC=3 SCAR=13.3
Pod undocumented
93  
94 2 ▶ if ( @_ == 1 && !ref( $_[0] ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1 and not ref $_[0]) { } 0 2 2
Condition33%1/3
@_ == 1 and not ref $_[0]
!ll&&!rl&&r
020
MC/DC0%0/2
@_ == 1 and not ref $_[0]
@_ == 1 not ref $_[0]
Truth table33%1/3
A and not(B)
A= @_ == 1B= not ref $_[0]
ABresult
0X0
100
111
95 0 return $self->query_by_id(@_);
96 }
97 else {
98 2 return $self->query_complex(@_);
99 }
100  
101 }
102  
103 sub query_complex {
104 2 ▶ my $self = shift;
Subroutine query_complex: called CC=2 SCAR=6.9
Pod undocumented
105  
106 2 my $url = build_complex_query_url( $self->query_url, @_ );
107  
108 2 my $resource = $self->client->http_request_as_resource( 'GET', $url );
109  
110 2 ▶ return wantarray ? $resource->items() : $resource;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1 1 2
111 }
112  
113 sub query_by_id {
114 5 ▶ my $self = shift;
Subroutine query_by_id: called CC=1 SCAR=0.0
Pod undocumented
115 5 my $id = shift;
116  
117 5 my $client = $self->client;
118 5 my $url = $self->query_url($id);
119  
120 5 return $client->http_request_as_resource( 'GET', $url );
121 }
122  
123 sub create {
124 3 ▶ my $self = shift;
Subroutine create: called CC=1 SCAR=0.0
Pod undocumented
125  
126 3 my $client = $self->client;
127 3 my $url = $self->query_url;
128  
129 3 return $client->http_request_as_resource( 'POST', $url, @_ );
130 }
131  
132 sub is_queryable {
133 0 ▶ my $self = shift;
Subroutine is_queryable: not called CC=3 SCAR=24.8
Pod undocumented
134 0 ▶ if ( $self->id eq 'schema' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->id eq "schema") 0 0 0
135 0 return 1;
136 }
137 0 ▶ if ( $self->link('collection') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->link("collection")) 0 0 0
138 0 return 1;
139 }
140 }
141  
142 sub query_url {
143 10 ▶ my $self = shift;
Subroutine query_url: called CC=4 SCAR=14.2
Pod undocumented
144 10 my ($id) = @_;
145  
146 10 ▶ my $base_url = $self->id eq 'schema' ? $self->link('schemas') : $self->link('collection');
Branch: 1 branch
BranchTrueFalseTotal
$self->id eq 'schema' ? : 0 10 10
147 10 ▶ if ( !defined $base_url ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $base_url) 0 10 10
148 0 die( "Unable to build a query url: schema '" . $self->id . "' has no 'collection' link" );
149 }
150 10 ▶ if ( defined $id ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $id) 5 5 10
151 5 return abs_url( $base_url, $id );
152 }
153 5 return $base_url;
154 }
155  
156 4 our %REGISTRY;
157  
158 sub registry_add {
159 72 ▶ my $class = shift;
Subroutine registry_add: called CC=2 SCAR=6.9
Pod undocumented
160 72 my %schemas = @_;
161 72 ▶ while ( my ( $key, $object ) = each(%schemas) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %schemas) 72 72 144
162 72 $REGISTRY{$key} = $object;
163 }
164 }
165  
166 sub registry_lookup {
167 20 ▶ my $class = shift;
Subroutine registry_lookup: called CC=6 SCAR=18.2
Pod undocumented
168 20 my @possibles = @_;
169 20 foreach my $find (@possibles) {
170 20 ▶ 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}) 19 1 20
Condition66%2/3
exists $WWW::GoDaddy::REST::Schema::REGISTRY{$find} and defined $WWW::GoDaddy::REST::Schema::REGISTRY{$find}
!ll&&!rl&&r
1019
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
171 19 return $REGISTRY{$find};
172 }
173 1 ▶ while ( my ( $key, $schema ) = each %REGISTRY ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %WWW::GoDaddy::REST::Schema::REGISTRY) 18 1 19
174 18 ▶ if ( lc($find) eq lc($key) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (lc $find eq lc $key) 0 18 18
175 0 return $schema;
176 }
177 }
178 }
179 1 return;
180  
181 }
182  
183 sub registry_list {
184 4 ▶ my $class = shift;
Subroutine registry_list: called CC=1 SCAR=0.0
Pod undocumented
185 4 my %seen;
186 4 return grep { not $seen{ $_->id }++ } values %REGISTRY;
187 }
188  
189 4 1;
190  
191 =head1 NAME
192  
193 WWW::GoDaddy::REST::Schema - schema specific resource class
194  
195 =head1 SYNOPSIS
196  
197 $schema = $client->schema('the_name');
198 $scehama = $resource->schema();
199  
200 =head1 DESCRIPTION
201  
202 This is used to represent a 'schema' which is a very common resource in the
203 Go Daddy(r) API specification.
204  
205 It is a sub class of L<WWW::GoDaddy::REST::Resource>.
206  
207 =head1 METHODS
208  
209 TODO: You'll have to read code to understand the methods listed here for
210 now. See L<WWW::GoDaddy::REST::Resource> for at least some of this.
211  
212 =head1 AUTHOR
213  
214 David Bartle, C<< <davidb@mediatemple.net> >>
215  
216 =head1 COPYRIGHT & LICENSE
217  
218 Copyright (c) 2014 Go Daddy Operating Company, LLC
219  
220 Permission is hereby granted, free of charge, to any person obtaining a
221 copy of this software and associated documentation files (the "Software"),
222 to deal in the Software without restriction, including without limitation
223 the rights to use, copy, modify, merge, publish, distribute, sublicense,
224 and/or sell copies of the Software, and to permit persons to whom the
225 Software is furnished to do so, subject to the following conditions:
226  
227 The above copyright notice and this permission notice shall be included in
228 all copies or substantial portions of the Software.
229  
230 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
231 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
232 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
233 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
234 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
235 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
236 DEALINGS IN THE SOFTWARE.
237  
238 =cut
« blib/lib/WWW/GoDaddy/REST/Shell/DocsCommand.pm ↑ Summary blib/lib/WWW/GoDaddy/REST/Shell/Util.pm »