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