Role.pm untested

filter: Statementstmt 0.0% 0 / 58 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 74 CC 4 SCAR 17.0
CC
4
Cov
0%
BUILD
12.0
_build_af
6.0
BEGIN
2.0
CRAP 5.5
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;
21 use utf8;
22
23 use Moose::Role;
24 use namespace::autoclean;
25 use Class::Inspector;
26 use Log::Any qw($log);
27 use AsposeDiagramCloud::ApiFactory;
28
29 has base_url => ( is => 'ro',
30 required => 0,
31 isa => 'Str',
32 documentation => 'Root of the server that requests are sent to',
33 );
34
35 has api_factory => ( is => 'ro',
36 isa => 'AsposeDiagramCloud::ApiFactory',
37 builder => '_build_af',
38 lazy => 1,
39 documentation => 'Builds an instance of the endpoint API class',
40 );
41
42 has tokens => ( is => 'ro',
43 isa => 'HashRef',
44 required => 0,
45 default => sub { {} },
46 documentation => 'The auth tokens required by the application - basic, OAuth and/or API key(s)',
47 );
48
49 has _cfg => ( is => 'ro',
50 isa => 'AsposeDiagramCloud::Configuration',
51 default => sub { AsposeDiagramCloud::Configuration->new() },
52 );
53
54 has version_info => ( is => 'ro',
55 isa => 'HashRef',
56 default => sub { {
57 app_name => 'Aspose.Diagram Cloud API Reference',
58 app_version => '3.0',
59 generator_class => 'io.swagger.codegen.languages.PerlClientCodegen',
60 } },
61 documentation => 'Information about the application version and the codegen codebase version'
62 );
63
64 sub BUILD {
65 my $self = shift;
66
67 $self->_cfg->accept_tokens( $self->tokens ) if keys %{$self->tokens};
68
69 # ignore these symbols imported into API namespaces
70 my %outsiders = map {$_ => 1} qw( croak );
71
72 my %delegates;
73
74 # collect the methods callable on each API
75 foreach my $api_name ($self->api_factory->apis_available) {
76 my $api_class = $self->api_factory->classname_for($api_name);
77 my $methods = Class::Inspector->methods($api_class, 'expanded'); # not Moose, so use CI instead
78 my @local_methods = grep {! /^_/} grep {! $outsiders{$_}} map {$_->[2]} grep {$_->[1] eq $api_class} @$methods;
79 push( @{$delegates{$_}}, {api_name => $api_name, api_class => $api_class} ) for @local_methods;
80 }
81
82 # remove clashes
83 foreach my $method (keys %delegates) {
84 if ( @{$delegates{$method}} > 1 ) {
85 my ($apis) = delete $delegates{$method};
86 }
87 }
88
89 # build the flattened API
90 foreach my $api_name ($self->api_factory->apis_available) {
91 my $att_name = sprintf "%s_api", lc($api_name);
92 my $api_class = $self->api_factory->classname_for($api_name);
93 my @delegated = grep { $delegates{$_}->[0]->{api_name} eq $api_name } keys %delegates;
94 $log->debugf("Adding API: '%s' handles %s", $att_name, join ', ', @delegated);
95 $self->meta->add_attribute( $att_name => (
96 is => 'ro',
97 isa => $api_class,
98 default => sub {$self->api_factory->get_api($api_name)},
99 lazy => 1,
100 handles => \@delegated,
101 ) );
102 }
103 }
104
105 sub _build_af {
106 my $self = shift;
107 my %args;
108 $args{base_url} = $self->base_url if $self->base_url;
109 return AsposeDiagramCloud::ApiFactory->new(%args);
110 }
111
112 =head1 NAME
113
114 AsposeDiagramCloud::Role - a Moose role for the Aspose.Diagram Cloud API Reference
115
116 =head2 Aspose.Diagram Cloud API Reference version: 3.0
117
118 =head1 VERSION
119
120 Automatically generated by the Perl Swagger Codegen project:
121
122 =over 4
123 =item Build package: io.swagger.codegen.languages.PerlClientCodegen
124
125 =item Codegen version:
126
127 =back
128
129 =head2 A note on Moose
130
131 This role is the only component of the library that uses Moose. See
132 AsposeDiagramCloud::ApiFactory for non-Moosey usage.
133
134 =head1 SYNOPSIS
135
136 The Perl Swagger Codegen project builds a library of Perl modules to interact with
137 a web service defined by a OpenAPI Specification. See below for how to build the
138 library.
139
140 This module provides an interface to the generated library. All the classes,
141 objects, and methods (well, not quite *all*, see below) are flattened into this
142 role.
143
144 package MyApp;
145 use Moose;
146 with 'AsposeDiagramCloud::Role';
147
148 package main;
149
150 my $api = MyApp->new({ tokens => $tokens });
151
152 my $pet = $api->get_pet_by_id(pet_id => $pet_id);
153
154 =head2 Structure of the library
155
156 The library consists of a set of API classes, one for each endpoint. These APIs
157 implement the method calls available on each endpoint.
158
159 Additionally, there is a set of "object" classes, which represent the objects
160 returned by and sent to the methods on the endpoints.
161
162 An API factory class is provided, which builds instances of each endpoint API.
163
164 This Moose role flattens all the methods from the endpoint APIs onto the consuming
165 class. It also provides methods to retrieve the endpoint API objects, and the API
166 factory object, should you need it.
167
168 For documentation of all these methods, see AUTOMATIC DOCUMENTATION below.
169
170 =head2 Configuring authentication
171
172 In the normal case, the OpenAPI Spec will describe what parameters are
173 required and where to put them. You just need to supply the tokens.
174
175 my $tokens = {
176 # basic
177 username => $username,
178 password => $password,
179
180 # oauth
181 access_token => $oauth_token,
182
183 # keys
184 $some_key => { token => $token,
185 prefix => $prefix,
186 in => $in, # 'head||query',
187 },
188
189 $another => { token => $token,
190 prefix => $prefix,
191 in => $in, # 'head||query',
192 },
193 ...,
194
195 };
196
197 my $api = MyApp->new({ tokens => $tokens });
198
199 Note these are all optional, as are C<prefix> and C<in>, and depend on the API
200 you are accessing. Usually C<prefix> and C<in> will be determined by the code generator from
201 the spec and you will not need to set them at run time. If not, C<in> will
202 default to 'head' and C<prefix> to the empty string.
203
204 The tokens will be placed in a L<AsposeDiagramCloud::Configuration> instance
205 as follows, but you don't need to know about this.
206
207 =over 4
208
209 =item C<$cfg-\>{username}>
210
211 String. The username for basic auth.
212
213 =item C<$cfg-\>{password}>
214
215 String. The password for basic auth.
216
217 =item C<$cfg-\>{api_key}>
218
219 Hashref. Keyed on the name of each key (there can be multiple tokens).
220
221 $cfg->{api_key} = {
222 secretKey => 'aaaabbbbccccdddd',
223 anotherKey => '1111222233334444',
224 };
225
226 =item C<$cfg->{api_key_prefix}>
227
228 Hashref. Keyed on the name of each key (there can be multiple tokens). Note not
229 all api keys require a prefix.
230
231 $cfg->{api_key_prefix} = {
232 secretKey => 'string',
233 anotherKey => 'same or some other string',
234 };
235
236 =item C<$config-\>{access_token}>
237
238 String. The OAuth access token.
239
240 =back
241
242 =head1 METHODS
243
244 =head2 C<base_url>
245
246 The generated code has the C<base_url> already set as a default value. This method
247 returns the current value of C<base_url>.
248
249 =head2 C<api_factory>
250
251 Returns an API factory object. You probably won't need to call this directly.
252
253 $self->api_factory('Pet'); # returns a AsposeDiagramCloud::PetApi instance
254
255 $self->pet_api; # the same
256
257 =head1 MISSING METHODS
258
259 Most of the methods on the API are delegated to individual endpoint API objects
260 (e.g. Pet API, Store API, User API etc). Where different endpoint APIs use the
261 same method name (e.g. C<new()>), these methods can't be delegated. So you need
262 to call C<$api-E<gt>pet_api-E<gt>new()>.
263
264 In principle, every API is susceptible to the presence of a few, random, undelegatable
265 method names. In practice, because of the way method names are constructed, it's
266 unlikely in general that any methods will be undelegatable, except for:
267
268 new()
269 class_documentation()
270 method_documentation()
271
272 To call these methods, you need to get a handle on the relevant object, either
273 by calling C<$api-E<gt>foo_api> or by retrieving an object, e.g.
274 C<$api-E<gt>get_pet_by_id(pet_id =E<gt> $pet_id)>. They are class methods, so
275 you could also call them on class names.
276
277 =head1 BUILDING YOUR LIBRARY
278
279 See the homepage C<https://github.com/swagger-api/swagger-codegen> for full details.
280 But briefly, clone the git repository, build the codegen codebase, set up your build
281 config file, then run the API build script. You will need git, Java 7 or 8 and Apache
282 maven 3.0.3 or better already installed.
283
284 The config file should specify the project name for the generated library:
285
286 {"moduleName":"WWW::MyProjectName"}
287
288 Your library files will be built under C<WWW::MyProjectName>.
289
290 $ git clone https://github.com/swagger-api/swagger-codegen.git
291 $ cd swagger-codegen
292 $ mvn package
293 $ java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate \
294 -i [URL or file path to JSON swagger API spec] \
295 -l perl \
296 -c /path/to/config/file.json \
297 -o /path/to/output/folder
298
299 Bang, all done. Run the C<autodoc> script in the C<bin> directory to see the API
300 you just built.
301
302 =head1 AUTOMATIC DOCUMENTATION
303
304 You can print out a summary of the generated API by running the included
305 C<autodoc> script in the C<bin> directory of your generated library. A few
306 output formats are supported:
307
308 Usage: autodoc [OPTION]
309
310 -w wide format (default)
311 -n narrow format
312 -p POD format
313 -H HTML format
314 -m Markdown format
315 -h print this help message
316 -c your application class
317
318 The C<-c> option allows you to load and inspect your own application. A dummy
319 namespace is used if you don't supply your own class.
320
321 =head1 DOCUMENTATION FROM THE OpenAPI Spec
322
323 Additional documentation for each class and method may be provided by the Swagger
324 spec. If so, this is available via the C<class_documentation()> and
325 C<method_documentation()> methods on each generated object class, and the
326 C<method_documentation()> method on the endpoint API classes:
327
328 my $cmdoc = $api->pet_api->method_documentation->{$method_name};
329
330 my $odoc = $api->get_pet_by_id->(pet_id => $pet_id)->class_documentation;
331 my $omdoc = $api->get_pet_by_id->(pet_id => $pet_id)->method_documentation->{method_name};
332
333 Each of these calls returns a hashref with various useful pieces of information.
334
335 =cut
336
337 1;