Fastly/Role/AutoDoc.pm untested

filter: Statementstmt 0.0% 0 / 40 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 4 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 62 CC 6 SCAR 29.1
CC
6
Cov
0%
_printisa
30.0
autodoc
6.0
BEGIN
2.0
CRAP 18.4
1 =begin comment
2  
3 Fastly API
4  
5 Via the Fastly API you can perform any of the operations that are possible within the management console, including creating services, domains, and backends, configuring rules or uploading your own application code, as well as account operations such as user administration and billing reports. The API is organized into collections of endpoints that allow manipulation of objects related to Fastly services and accounts. For the most accurate and up-to-date API reference content, visit our [Developer Hub](https://www.fastly.com/documentation/reference/api/)
6  
7 The version of the API Spec document: 1.0.0
8 Contact: oss@fastly.com
9  
10 =end comment
11  
12 =cut
13  
14 #
15 # NOTE: This class is auto generated.
16 # Do not edit the class manually.
17 #
18 package WebService::Fastly::Role::AutoDoc;
19 use List::MoreUtils qw(uniq);
20  
21 use Moose::Role;
22  
23 sub autodoc {
24 my ($self, $how) = @_;
25  
26 die "Unknown format '$how'" unless $how =~ /^(pod|wide|narrow)$/;
27  
28 $self->_printisa($how);
29 $self->_printmethods($how);
30 $self->_printattrs($how);
31 print "\n";
32 }
33  
34 sub _printisa {
35 my ($self, $how) = @_;
36 my $meta = $self->meta;
37  
38 my $myclass = ref $self;
39  
40 my $super = join ', ', $meta->superclasses;
41 my @roles = $meta->calculate_all_roles;
42 #shift(@roles) if @roles > 1; # if > 1, the first is a composite, the rest are the roles
43  
44 my $isa = join ', ', grep {$_ ne $myclass} $meta->linearized_isa;
45 my $sub = join ', ', $meta->subclasses;
46 my $dsub = join ', ', $meta->direct_subclasses;
47  
48 my $app_name = $self->version_info->{app_name};
49 my $app_version = $self->version_info->{app_version};
50 my $generated_date = $self->version_info->{generated_date};
51 my $generator_class = $self->version_info->{generator_class};
52  
53 $~ = $how eq 'pod' ? 'INHERIT_POD' : 'INHERIT';
54 write;
55  
56 my ($rolepkg, $role_reqs);
57  
58 foreach my $role (@roles) {
59 $rolepkg = $role->{package} || next; # some are anonymous, or something
60 next if $rolepkg eq 'WebService::Fastly::Role::AutoDoc';
61 $role_reqs = join ', ', keys %{$role->{required_methods}};
62 $role_reqs ||= '';
63 $~ = $how eq 'pod' ? 'ROLES_POD' : 'ROLES';
64 write;
65 }
66  
67 if ($how eq 'pod') {
68 $~ = 'ROLES_POD_CLOSE';
69 write;
70 }
71  
72 # ----- format specs -----
73 format INHERIT =
74  
75 @* -
76 $myclass
77 ISA: @*
78 $isa
79 Direct subclasses: @*
80 $dsub
81 All subclasses: @*
82 $sub
83  
84 Target API: @* @*
85 $app_name, $app_version
86 Generated on: @*
87 $generated_date
88 Generator class: @*
89 $generator_class
90  
91 .
92 format ROLES =
93 Composes: ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ~
94 $rolepkg
95 requires: ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ~
96 $role_reqs
97 ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ~~
98 $role_reqs
99 .
100  
101 format INHERIT_POD =
102 =head1 NAME
103  
104 @*
105 $myclass
106  
107 =head1 VERSION
108  
109 =head2 @* version: @*
110 $app_name, $app_version
111  
112 Automatically generated:
113  
114 =over 4
115  
116 =item Build date: @*
117 $generated_date
118  
119 =item Build package: @*
120 $generator_class
121  
122 =item Codegen version:
123  
124  
125 =back
126  
127 =head1 INHERITANCE
128  
129 =head2 Base class(es)
130  
131 @*
132 $isa
133  
134 =head2 Direct subclasses
135  
136 @*
137 $dsub
138  
139 =head2 All subclasses
140  
141 @*
142 $sub
143  
144  
145 =head1 COMPOSITION
146  
147 @* composes the following roles:
148 $myclass
149  
150  
151 .
152 format ROLES_POD =
153 =head2 C<@*>
154 $rolepkg
155  
156 Requires:
157  
158 @*
159 $role_reqs
160  
161 .
162 format ROLES_POD_CLOSE =
163  
164  
165 .
166 # ----- / format specs -----
167 }
168  
169 sub _printmethods {
170 my ($self, $how) = @_;
171  
172 if ($how eq 'narrow') {
173 print <<HEAD;
174 METHODS
175 -------
176 HEAD
177 }
178 elsif ($how eq 'wide') {
179 $~ = 'METHODHEAD';
180 write;
181 }
182 elsif ($how eq 'pod') {
183 $~ = 'METHODHEAD_POD';
184 write;
185 }
186 else {
187 die "Don't know how to print '$how'";
188 }
189  
190 $self->_printmethod($_, $how) for uniq sort $self->meta->get_all_method_names; #$self->meta->get_method_list,
191  
192 if ($how eq 'pod') {
193 $~ = 'METHOD_POD_CLOSE';
194 write;
195 }
196  
197  
198 }
199  
200 sub _printmethod {
201 my ($self, $methodname, $how) = @_;
202 return if $methodname =~ /^_/;
203 return if $self->meta->has_attribute($methodname);
204 my %internal = map {$_ => 1} qw(BUILD BUILDARGS meta can new DEMOLISHALL DESTROY
205 DOES isa BUILDALL does VERSION dump
206 );
207 return if $internal{$methodname};
208 my $method = $self->meta->get_method($methodname) or return; # symbols imported into namespaces i.e. not known by Moose
209  
210 return if $method->original_package_name eq __PACKAGE__;
211  
212 my $delegate_to = '';
213 my $via = '';
214 my $on = '';
215 my $doc = '';
216 my $original_pkg = $method->original_package_name;
217 if ($method->can('associated_attribute')) {
218 $delegate_to = $method->delegate_to_method;
219 my $aa = $method->associated_attribute;
220 $on = $aa->{isa};
221 $via = $aa->{name};
222 $original_pkg = $on;
223 $doc = $original_pkg->method_documentation->{$delegate_to}->{summary};
224 }
225 else {
226 $doc = $method->documentation;
227 }
228  
229 if ($how eq 'narrow') {
230 $~ = 'METHOD_NARROW';
231 write;
232 }
233 elsif ($how eq 'pod' and $delegate_to) {
234 $~ = 'METHOD_POD_DELEGATED';
235 write;
236 }
237 elsif ($how eq 'pod') {
238 $~ = 'METHOD_POD';
239 write;
240 }
241 else {
242 $~ = 'METHOD';
243 write;
244 }
245  
246 # ----- format specs -----
247 format METHODHEAD =
248  
249 METHODS
250 -------
251 Name delegates to on via
252 ===========================================================================================================================================================================
253 .
254 format METHOD =
255 @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<... @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<... @<<<<<<<<<<<<<<<<...
256 $methodname, $delegate_to, $on, $via
257 .
258  
259 format METHOD_NARROW =
260 @*
261 $methodname
262 original pkg: @*
263 $original_pkg
264 delegates to: @*
265 $delegate_to
266 on: @*
267 $on
268 via: @*
269 $via
270  
271 .
272  
273 format METHODHEAD_POD =
274  
275 =head1 METHODS
276  
277 .
278  
279 format METHOD_POD =
280  
281 =head2 C<@*()>
282 $methodname
283  
284 Defined in: @*
285 $original_pkg
286  
287  
288 .
289 format METHOD_POD_DELEGATED =
290  
291 =head2 C<@*()>
292 $methodname
293  
294 Defined in: @*
295 $original_pkg
296 Delegates to: @*()
297 $delegate_to
298 On: @*
299 $on
300 Via: @*()
301 $via
302 Doc: @*
303 $doc
304 Same as: $self->@*->@*()
305 $via, $delegate_to
306  
307 .
308 format METHOD_POD_CLOSE =
309  
310 .
311 # ----- / format specs -----
312 }
313  
314 sub _printattrs {
315 my ($self, $how) = @_;
316  
317 if ($how eq 'narrow') {
318 print <<HEAD;
319 ATTRIBUTES
320 ----------
321 HEAD
322 }
323 elsif ($how eq 'wide') {
324 $~ = 'ATTRHEAD';
325 write;
326 }
327 elsif ($how eq 'pod') {
328 $~ = 'ATTRHEAD_POD';
329 write;
330 }
331 else {
332 die "Don't know how to print attributes '$how'";
333 }
334  
335 $self->_printattr($_, $how) for sort $self->meta->get_attribute_list;
336  
337 if ($how eq 'pod') {
338 $~ = 'ATTR_POD_CLOSE';
339 write;
340 }
341 }
342  
343 sub _printattr {
344 my ($self, $attrname, $how) = @_;
345 return if $attrname =~ /^_/;
346 my $attr = $self->meta->get_attribute($attrname) or die "No attr for $attrname";
347  
348 my $is;
349 $is = 'rw' if $attr->get_read_method && $attr->get_write_method;
350 $is = 'ro' if $attr->get_read_method && ! $attr->get_write_method;
351 $is = 'wo' if $attr->get_write_method && ! $attr->get_read_method;
352 $is = '--' if ! $attr->get_write_method && ! $attr->get_read_method;
353 $is or die "No \$is for $attrname";
354  
355 my $tc = $attr->type_constraint || '';
356 my $from = $attr->associated_class->name || '';
357 my $reqd = $attr->is_required ? 'yes' : 'no';
358 my $lazy = $attr->is_lazy ? 'yes' : 'no';
359 my $has_doc = $attr->has_documentation ? 'yes' : 'no'; # *_api attributes will never have doc, but other attributes might have
360 my $doc = $attr->documentation || '';
361 my $handles = join ', ', sort @{$attr->handles || []};
362 $handles ||= '';
363  
364 if ($how eq 'narrow') {
365 $~ = 'ATTR_NARROW';
366 }
367 elsif ($how eq 'pod') {
368 $~ = 'ATTR_POD';
369 }
370 else {
371 $~ = 'ATTR';
372 }
373  
374 write;
375  
376 # ----- format specs -----
377 format ATTRHEAD =
378  
379 ATTRIBUTES
380 ----------
381 Name is isa reqd lazy doc handles
382 ==============================================================================================================
383 .
384 format ATTR =
385 @<<<<<<<<<<<<<<<<< @< @<<<<<<<<<<<<<<<<<<<<<<<< @<<< @<<< @<< ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
386 $attrname, $is, $tc, $reqd, $lazy, $has_doc, $handles
387 ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ~~
388 $handles
389 .
390  
391 format ATTR_NARROW =
392 @*
393 $attrname
394 is: @*
395 $is
396 isa: @*
397 $tc
398 reqd: @*
399 $reqd
400 lazy: @*
401 $lazy
402 doc: @*
403 $doc
404 handles: ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
405 $handles
406 ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ~~
407 $handles
408  
409 .
410 format ATTRHEAD_POD =
411 =head1 ATTRIBUTES
412  
413 .
414 format ATTR_POD =
415  
416 =head2 C<@*>
417 $attrname
418  
419 is: @*
420 $is
421 isa: @*
422 $tc
423 reqd: @*
424 $reqd
425 lazy: @*
426 $lazy
427 doc: @*
428 $doc
429 handles: ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
430 $handles
431 ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ~~
432 $handles
433  
434 .
435 format ATTR_POD_CLOSE =
436  
437  
438 .
439 # ----- / format specs -----
440 }
441  
442  
443  
444 1;