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