blib/lib/WWW/GoDaddy/REST/Shell/DocsCommand.pm

filter: Statementstmt 12.9% 19 / 147 Branchbran 0.0% 0 / 42 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 46.1% 6 / 13 Podpod 0.0% 0 / 7 totaltotal 11.6% 25 / 214 CC 25 SCAR 44.5
CC
25
Cov
10%
format_schema_docs
182.0
run_docs
56.0
format_resource_docs
56.0
CRAP 85.5
« blib/lib/WWW/GoDaddy/REST/Shell/QueryCommand.pm ↑ Summary blib/lib/WWW/GoDaddy/REST/Schema.pm »
1 package WWW::GoDaddy::REST::Shell::DocsCommand;
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 => {
7 exports => [qw(run_docs smry_docs help_docs comp_docs alias_docs)],
8 groups => { default => [qw(run_docs smry_docs help_docs comp_docs alias_docs)] }
9 1 ▶};
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Text::FormatTable;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use WWW::GoDaddy::REST::Shell::Util qw(get_resource_by_schema_or_uri);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use WWW::GoDaddy::REST::Util qw(json_encode);
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 sub run_docs {
15 0 ▶ my $self = shift;
Subroutine run_docs: not called CC=7 SCAR=40.3
Pod undocumented
16  
17 0 my $usage = "Usage:\n docs [schema] [id]\n docs /uri/id\n";
18  
19 0 my $resource;
20 0 ▶ if ( @_ == 1 && $self->client->schema( $_[0] ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1 and $self->client->schema($_[0])) { } 0 0 0
Condition0%0/3
@_ == 1 and $self->client->schema($_[0])
!ll&&!rl&&r
000
MC/DC0%0/2
@_ == 1 and $self->client->schema($_[0])
@_ == 1 $self->client->schema($_[0])
Truth table0%0/3
A and B
A= @_ == 1B= $self->client->schema($_[0])
ABresult
0X0
100
111
21 0 $resource = $self->client->schema( $_[0] );
22 }
23 else {
24 0 $resource = eval { return get_resource_by_schema_or_uri( $self, @_ ); };
25 }
26 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
27 0 ▶ if ( UNIVERSAL::isa( $@, 'WWW::GoDaddy::REST::Resource' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($@, 'WWW::GoDaddy::REST::Resource')) { } 0 0 0
28 0 $self->page( $@->to_string(1) . "\n" );
29 }
30 else {
31 0 warn($@);
32 0 warn($usage);
33 }
34 0 return 0;
35 }
36  
37 0 eval {
38 0 ▶ if ( $resource->type() eq 'schema' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($resource->type eq 'schema') { } 0 0 0
39 0 return format_schema_docs( $self, $resource );
40 }
41 else {
42 0 return format_resource_docs( $self, $resource );
43 }
44 };
45 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
46 0 warn($@);
47 }
48  
49 }
50  
51 sub smry_docs {
52 0 ▶ return "summarize a resource or schema";
Subroutine smry_docs: not called CC=1 SCAR=6.9
Pod undocumented
53 }
54  
55 sub help_docs {
56 return <<HELP
57 View a "man page" of a resource.
58  
59 Usage:
60 docs [schema] [id]
61 docs [/uri/to/id]
62 man [schema]
63 HELP
64 0 ▶}
Subroutine help_docs: not called CC=1 SCAR=6.9
Pod undocumented
65  
66 sub comp_docs {
67 0 ▶ my $self = shift;
Subroutine comp_docs: not called CC=1 SCAR=6.9
Pod undocumented
68 0 my $client = $self->client;
69 0 return grep { $client->schema($_)->is_queryable } $self->schema_completion(@_);
70 }
71  
72 sub alias_docs {
73 0 ▶ return ('man');
Subroutine alias_docs: not called CC=1 SCAR=6.9
Pod undocumented
74 }
75  
76 sub format_resource_docs {
77 0 ▶ my $self = shift;
Subroutine format_resource_docs: not called CC=7 SCAR=40.3
Pod undocumented
78 0 my $resource = shift;
79  
80 0 my $link_self = $resource->link('self');
81 0 my $type = $resource->type();
82 0 my $type_fq = $resource->type_fq();
83  
84 0 my $output = '';
85 0 $output .= "RESOURCE\n";
86 0 $output .= " GET $link_self\n\n";
87 0 $output .= "SCHEMA\n";
88 0 $output .= " $type - GET $type_fq\n";
89  
90 0 ▶ my %links = %{ $resource->links() || {} };
Branch: 1 branch
BranchTrueFalseTotal
$resource->links or {} 0 0 0
91 0 ▶ if (%links) {
Branch: 1 branch
BranchTrueFalseTotal
if (%links) 0 0 0
92 0 $output .= "LINKS\n";
93 my ($table) = $self->format_pairs(
94 0 [ map {" $_"} keys %links ],
95 0 [ map {"GET $_"} values %links ],
96 " - ", 1
97 );
98 0 $output .= "$table";
99 0 $output .= "\n";
100 }
101 0 ▶ my %actions = %{ $resource->actions() || {} };
Branch: 1 branch
BranchTrueFalseTotal
$resource->actions or {} 0 0 0
102 0 ▶ if (%actions) {
Branch: 1 branch
BranchTrueFalseTotal
if (%actions) 0 0 0
103 0 $output .= "EXTRA ACTIONS\n";
104 my ($table) = $self->format_pairs(
105 0 [ map {" $_"} keys %actions ],
106 0 [ map {"POST $_"} values %actions ],
107 " - ", 1
108 );
109 0 $output .= "$table";
110 0 $output .= "\n";
111 }
112  
113 0 my %fields = %{ $resource->fields() };
114 0 delete $fields{links};
115 0 delete $fields{actions};
116 0 ▶ if (%fields) {
Branch: 1 branch
BranchTrueFalseTotal
if (%fields) 0 0 0
117 0 $output .= "FIELDS\n";
118 my ($table) = $self->format_pairs(
119 0 [ map {" $_"} keys %fields ],
120 [ map {
121 0 ▶ if ( ref($_) ) { json_encode($_) }
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_) { } 0 0 0
122 0 else {$_}
123 } values %fields
124 ],
125 " - ",
126 1
127 );
128 0 $output .= "$table";
129 }
130  
131 0 $self->page($output);
132  
133 0 return 1;
134 }
135  
136 sub format_schema_docs {
137 0 ▶ my $self = shift;
Subroutine format_schema_docs: not called CC=13 SCAR=52.0
Pod undocumented
138 0 my $resource = shift;
139  
140 0 my $link_self = $resource->link('self');
141 0 my $type = $resource->type();
142 0 my $type_fq = $resource->type_fq();
143  
144 0 my $output = '';
145 0 $output .= "SCHEMA\n";
146 0 $output .= " GET $link_self\n\n";
147  
148 0 ▶ my %links = %{ $resource->links() || {} };
Branch: 1 branch
BranchTrueFalseTotal
$resource->links or {} 0 0 0
149 0 ▶ if (%links) {
Branch: 1 branch
BranchTrueFalseTotal
if (%links) 0 0 0
150 0 $output .= "LINKS\n";
151 my ($table) = $self->format_pairs(
152 0 [ map {" $_"} keys %links ],
153 0 [ map {"GET $_"} values %links ],
154 " - ", 1
155 );
156 0 $output .= "$table";
157 0 $output .= "\n";
158 }
159  
160 0 my $collection_link = $resource->link('collection');
161 0 $output .= "COLLECTION\n";
162 0 $output
163 .= " The collection is the URL that allows you to both search for things, as well as create new things of a particular type.\n\n";
164  
165 0 ▶ if ($collection_link) {
Branch: 1 branch
BranchTrueFalseTotal
if ($collection_link) { } 0 0 0
166 0 my @methods = @{ $resource->f('collectionMethods') };
167 0 my $methods_string = join ',', @methods;
168 0 ▶ $methods_string .= ' ' if @methods;
Branch: 1 branch
BranchTrueFalseTotal
if @methods 0 0 0
169 0 ▶ if (@methods) {
Branch: 1 branch
BranchTrueFalseTotal
if (@methods) { } 0 0 0
170 0 foreach (@methods) {
171 0 $output .= " $_ $collection_link\n";
172 }
173 }
174 else {
175 0 $output .= " $collection_link\n\n";
176 }
177 0 $output .= "\n See the 'FIELDS' section for a list of queryable fields\n\n";
178  
179 }
180 else {
181 0 $output
182 .= " Searching is not available for this schema. There is no\n'collection' link.\n\n";
183 }
184  
185 0 my @fields = sort $resource->resource_field_names();
186 0 my %filters = %{ $resource->f('collectionFilters') };
187  
188 0 my $table = Text::FormatTable->new(' l | l | l | l ');
189 0 $table->rule('-');
190 0 $table->head( 'Name', 'Searchable', 'Flags', 'Type' );
191 0 $table->rule('-');
192  
193 0 my $base_uri = $resource->client->url;
194  
195 0 foreach my $field_name (@fields) {
196 0 my $field = $resource->resource_field($field_name);
197 0 my $filter = $filters{$field_name};
198 0 my $filter_ops = '-';
199 0 ▶ if ($filter) {
Branch: 1 branch
BranchTrueFalseTotal
if ($filter) 0 0 0
200 0 $filter_ops = join ' ', @{ $filter->{modifiers} };
201 }
202  
203 my $flags = sprintf( "%s%s%s%s",
204 $field->{unique} ? 'K' : '-',
205 $field->{required} ? 'R' : '-',
206 $field->{create} ? 'C' : '-',
207 0 ▶ $field->{update} ? 'U' : '-' );
Branch: 4 branches
BranchTrueFalseTotal
$field->{'unique'} ? : 0 0 0
$field->{'required'} ? : 0 0 0
$field->{'create'} ? : 0 0 0
$field->{'update'} ? : 0 0 0
208  
209 0 my @types = map { $_ =~ s|$base_uri||; $_; }
210 0 grep {defined}
211 $resource->resource_field_type( $field_name, { qualify_schema_types => 1 } );
212  
213 0 $table->row( $field_name, $filter_ops, $flags, ( join ' of ', @types ) );
214  
215 }
216 0 $table->rule('-');
217  
218 0 my $table_text = $table->render( $self->termsize->{cols} - 4 );
219 0 $table_text =~ s/\n/\n /gs;
220 0 $table_text =~ s/^/ /g;
221  
222 0 $output .= $table_text;
223  
224 0 $output
225 .= "Flags: K - Unique key, R - Required, C - Allowed on create, U - Allowed on update\n";
226  
227 0 $self->page($output);
228  
229 0 return 1;
230 }
231  
232 1 1;
233  
234 =head1 AUTHOR
235  
236 David Bartle, C<< <davidb@mediatemple.net> >>
237  
238 =head1 COPYRIGHT & LICENSE
239  
240 Copyright (c) 2014 Go Daddy Operating Company, LLC
241  
242 Permission is hereby granted, free of charge, to any person obtaining a
243 copy of this software and associated documentation files (the "Software"),
244 to deal in the Software without restriction, including without limitation
245 the rights to use, copy, modify, merge, publish, distribute, sublicense,
246 and/or sell copies of the Software, and to permit persons to whom the
247 Software is furnished to do so, subject to the following conditions:
248  
249 The above copyright notice and this permission notice shall be included in
250 all copies or substantial portions of the Software.
251  
252 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
253 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
254 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
255 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
256 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
257 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
258 DEALINGS IN THE SOFTWARE.
259  
260 =cut
« blib/lib/WWW/GoDaddy/REST/Shell/QueryCommand.pm ↑ Summary blib/lib/WWW/GoDaddy/REST/Schema.pm »