lib/Net/API/CPAN/Distribution.pm

filter: Statementstmt 81.8% 45 / 55 Branchbran 50.0% 11 / 22 Conditioncond 13.0% 3 / 23 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 76.4% 13 / 17 Podpod 100% 9 / 9 totaltotal 59.5% 81 / 136 CC 20 SCAR 31.6
CC
20
Cov
59%
__ANON__
54.4
init
9.7
metacpan_url
6.0
CRAP 23.6
« lib/Net/API/CPAN/Release.pm ↑ Summary blib/lib/Net/API/CPAN/Activity.pm »
1 ##----------------------------------------------------------------------------
2 ## Meta CPAN API - ~/lib/Net/API/CPAN/Distribution.pm
3 ## Version v0.1.0
4 ## Copyright(c) 2023 DEGUEST Pte. Ltd.
5 ## Author: Jacques Deguest <jack@deguest.jp>
6 ## Created 2023/07/25
7 ## Modified 2023/09/26
8 ## All rights reserved
9 ##
10 ##
11 ## This program is free software; you can redistribute it and/or modify it
12 ## under the same terms as Perl itself.
13 ##----------------------------------------------------------------------------
14 # This module file has been automatically generated. Any change made here will be lost.
15 # Edit the script in ./build/build_modules.pl instead
16 package Net::API::CPAN::Distribution;
17 BEGIN
18 {
19 2 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 2 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 2 ▶ use parent qw( Net::API::CPAN::Generic );
Subroutine BEGIN: called CC=1 SCAR=0.0
22 2 ▶ use vars qw( $VERSION );
Subroutine BEGIN: called CC=1 SCAR=0.0
23 2 ▶ our $VERSION = 'v0.1.0';
Subroutine BEGIN: called CC=1 SCAR=0.0
24 };
25  
26 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29 sub init
30 {
31 1 ▶ my $self = shift( @_ );
Subroutine init: called CC=6 SCAR=22.8
Pod documented
32 1 ▶ $self->{bugs} = undef unless( CORE::exists( $self->{bugs} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"bugs"} 1 0 1
33 1 ▶ $self->{external_package} = undef unless( CORE::exists( $self->{external_package} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"external_package"} 1 0 1
34 1 ▶ $self->{name} = undef unless( CORE::exists( $self->{name} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"name"} 1 0 1
35 1 $self->{object} = 'distribution';
36 1 ▶ $self->{river} = undef unless( CORE::exists( $self->{river} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"river"} 1 0 1
37 $self->{_init_preprocess} = sub
38 {
39 1 ▶ my $this = shift( @_ );
Subroutine __ANON__: called CC=14 SCAR=40.0
40 1 ▶ if( $self->_is_array( $this ) )
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_is_array($this)) { } 1 0 1
elsif ($self->_is_hash($this)) { } 0 0 0
41 {
42 1 ▶ for( my $i = 0; $i < scalar( @$this ); $i += 2 )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @$this) 5 1 6
43 {
44 5 ▶ if( $this->[$i] eq 'bugs' )
Branch: 1 branch
BranchTrueFalseTotal
if ($this->[$i] eq "bugs") 1 4 5
45 {
46 1 my $ref = $this->[$i + 1];
47 1 ▶ if( ref( $ref ) eq 'HASH' &&
Branch: 1 branch
BranchTrueFalseTotal
if (ref $ref eq "HASH" and exists $ref->{"rt"} and ref $ref->{"rt"} eq "HASH" and exists $ref->{"rt"}{"new"}) 1 0 1
Condition33%3/9
ref $ref eq "HASH" and exists $ref->{"rt"} and ref $ref->{"rt"} eq "HASH" and exists $ref->{"rt"}{"new"}
!ll&&!rl&&r
001
ref $ref eq "HASH" and exists $ref->{"rt"} and ref $ref->{"rt"} eq "HASH"
!ll&&!rl&&r
001
ref $ref eq "HASH" and exists $ref->{"rt"}
!ll&&!rl&&r
001
MC/DC0%0/4
ref $ref eq "HASH" and exists $ref->{"rt"} and ref $ref->{"rt"} eq "HASH" and exists $ref->{"rt"}{"new"}
ref $ref eq "HASH" exists $ref->{"rt"} ref $ref->{"rt"} eq "HASH" exists $ref->{"rt"}{"new"}
Truth table20%1/5
A and B and C and D
A= ref $ref eq "HASH"B= exists $ref->{"rt"}C= ref $ref->{"rt"} eq "HASH"D= exists $ref->{"rt"}{"new"}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
48 exists( $ref->{rt} ) &&
49 ref( $ref->{rt} ) eq 'HASH' &&
50 exists( $ref->{rt}->{new} ) )
51 {
52 1 $ref->{rt}->{recent} = CORE::delete( $ref->{rt}->{new} );
53 1 $this->[$i + 1] = $ref;
54 }
55 }
56 }
57 }
58 elsif( $self->_is_hash( $this ) )
59 {
60 0 ▶ if( exists( $this->{bugs} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $this->{"bugs"} and ref $this->{"bugs"} eq "HASH" and exists $this->{"bugs"}{"rt"} and ref $this->{"bugs"}{"rt"} eq "HASH" and exists $this->{"bugs"}{"rt"}{"new"}) 0 0 0
Condition0%0/12
exists $this->{"bugs"} and ref $this->{"bugs"} eq "HASH" and exists $this->{"bugs"}{"rt"} and ref $this->{"bugs"}{"rt"} eq "HASH" and exists $this->{"bugs"}{"rt"}{"new"}
!ll&&!rl&&r
000
exists $this->{"bugs"} and ref $this->{"bugs"} eq "HASH" and exists $this->{"bugs"}{"rt"} and ref $this->{"bugs"}{"rt"} eq "HASH"
!ll&&!rl&&r
000
exists $this->{"bugs"} and ref $this->{"bugs"} eq "HASH" and exists $this->{"bugs"}{"rt"}
!ll&&!rl&&r
000
exists $this->{"bugs"} and ref $this->{"bugs"} eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/5
exists $this->{"bugs"} and ref $this->{"bugs"} eq "HASH" and exists $this->{"bugs"}{"rt"} and ref $this->{"bugs"}{"rt"} eq "HASH" and exists $this->{"bugs"}{"rt"}{"new"}
exists $this->{"bugs"} ref $this->{"bugs"} eq "HASH" exists $this->{"bugs"}{"rt"} ref $this->{"bugs"}{"rt"} eq "HASH" exists $this->{"bugs"}{"rt"}{"new"}
Truth table0%0/6
A and B and C and D and E
A= exists $this->{"bugs"}B= ref $this->{"bugs"} eq "HASH"C= exists $this->{"bugs"}{"rt"}D= ref $this->{"bugs"}{"rt"} eq "HASH"E= exists $this->{"bugs"}{"rt"}{"new"}
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
61 ref( $this->{bugs} ) eq 'HASH' &&
62 exists( $this->{bugs}->{rt} ) &&
63 ref( $this->{bugs}->{rt} ) eq 'HASH' &&
64 exists( $this->{bugs}->{rt}->{new} ) )
65 {
66 0 $this->{bugs}->{rt}->{recent} = CORE::delete( $this->{bugs}->{rt}->{new} );
67 }
68 }
69 1 return( $this );
70 1 };
71 1 $self->{_init_strict_use_sub} = 1;
72 1 $self->{_exception_class} = 'Net::API::CPAN::Exception';
73 1 ▶ $self->SUPER::init( @_ ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->SUPER::init(@_) or return $self->pass_error 0 1 1
74 1 $self->{fields} = [qw( bugs external_package name river )];
75 1 return( $self );
76 }
77  
78 2 ▶sub bugs { return( shift->_set_get_class( 'bugs', {
Subroutine bugs: called CC=1 SCAR=0.0
Pod documented
79 github => {
80 def => {
81 active => "integer",
82 closed => "integer",
83 open => "integer",
84 source => "uri",
85 },
86 type => "class",
87 },
88 rt => {
89 def => {
90 active => "integer",
91 closed => "integer",
92 open => "integer",
93 patched => "integer",
94 recent => "integer",
95 rejected => "integer",
96 resolved => "integer",
97 source => "uri",
98 stalled => "integer",
99 },
100 type => "class",
101 },
102 }, @_ ) ); }
103  
104 2 ▶sub external_package { return( shift->_set_get_class( 'external_package', {
Subroutine external_package: called CC=1 SCAR=0.0
Pod documented
105 cygwin => "scalar_as_object",
106 debian => "scalar_as_object",
107 fedora => "scalar_as_object",
108 }, @_ ) ); }
109  
110 0 ▶sub github { return( shift->bugs->github ); }
Subroutine github: not called CC=1 SCAR=6.9
Pod documented
111  
112 sub metacpan_url
113 {
114 0 ▶ my $self = shift( @_ );
Subroutine metacpan_url: not called CC=2 SCAR=17.9
Pod documented
115 0 ▶ my $name = $self->name ||
Condition0%0/2
$self->name || (return $self->error('No distribution name is set to return a Meta CPAN URL for this distribution.'))
l!l
00
MC/DC0%0/1
$self->name || (return $self->error('No distribution name is set to return a Meta CPAN URL for this distribution.'))
$self->name
Truth table0%0/2
A
A= $self->name
Aresult
11
00
116 return( $self->error( "No distribution name is set to return a Meta CPAN URL for this distribution." ) );
117 0 my $api_uri = $self->api->api_uri->clone;
118 0 $api_uri->path( "/release/$name" );
119 0 return( $api_uri );
120 }
121  
122 2 ▶sub name { return( shift->_set_get_scalar_as_object( 'name', @_ ) ); }
Subroutine name: called CC=1 SCAR=0.0
Pod documented
123  
124 0 ▶sub object { return( shift->_set_get_scalar_as_object( 'object', @_ ) ); }
Subroutine object: not called CC=1 SCAR=6.9
Pod documented
125  
126 2 ▶sub river { return( shift->_set_get_class( 'river', {
Subroutine river: called CC=1 SCAR=0.0
Pod documented
127 bucket => "integer",
128 bus_factor => "integer",
129 immediate => "integer",
130 total => "integer",
131 }, @_ ) ); }
132  
133 0 ▶sub rt { return( shift->bugs->rt ); }
Subroutine rt: not called CC=1 SCAR=6.9
Pod documented
134  
135 2 1;
136 # NOTE: POD
137 __END__
138  
139 =encoding utf-8
140  
141 =head1 NAME
142  
143 Net::API::CPAN::Distribution - Meta CPAN API Distribution Class
144  
145 =head1 SYNOPSIS
146  
147 use Net::API::CPAN::Distribution;
148 my $obj = Net::API::CPAN::Distribution->new( {
149 bugs => {
150 github => {
151 active => 5,
152 closed => 10,
153 open => 3,
154 source => "https://github.com/momotaro/Folkore-Japan",
155 },
156 rt => {
157 active => 2,
158 closed => 18,
159 new => 0,
160 open => 2,
161 patched => 0,
162 rejected => 0,
163 resolved => 18,
164 source => "https://rt.cpan.org/Public/Dist/Display.html?Name=Folkore-Japan",
165 stalled => 0,
166 },
167 },
168 external_package => {
169 cygwin => "perl-Folkore-Japan",
170 debian => "folklore-japan-perl",
171 fedora => "perl-Folkore-Japan",
172 },
173 name => "Folklore-Japan",
174 river => {
175 bucket => 2,
176 bus_factor => 1,
177 immediate => 15,
178 total => 19,
179 },
180 } ) || die( Net::API::CPAN::Distribution->error );
181
182 my $this = $obj->bugs;
183 my $github_obj = $obj->bugs->github;
184 my $rt_obj = $obj->bugs->rt;
185 my $this = $obj->external_package;
186 my $scalar = $obj->external_package->cygwin;
187 my $scalar = $obj->external_package->debian;
188 my $scalar = $obj->external_package->fedora;
189 my $this = $obj->github;
190 my $uri = $obj->metacpan_url;
191 my $string = $obj->name;
192 my $str = $obj->object;
193 my $this = $obj->river;
194 my $integer = $obj->river->bucket;
195 my $integer = $obj->river->bus_factor;
196 my $integer = $obj->river->immediate;
197 my $integer = $obj->river->total;
198 my $this = $obj->rt;
199  
200 =head1 VERSION
201  
202 v0.1.0
203  
204 =head1 DESCRIPTION
205  
206 This class serves to retrieve and manipulate distributions.
207  
208 It inherits from L<Net::API::CPAN::Generic>
209  
210 =head1 CONSTRUCTOR
211  
212 =head2 new
213  
214 Provided with an hash or hash reference of parameters, and this instantiates a new C<Net::API::CPAN::Distribution> object.
215  
216 The parameters that can be provided bear the same name and supports the same values as the methods below.
217  
218 =head1 METHODS
219  
220 =head2 bugs
221  
222 $obj->bugs( {
223 github => {
224 active => 5,
225 closed => 10,
226 open => 3,
227 source => "https://github.com/momotaro/Folkore-Japan",
228 },
229 rt => {
230 active => 2,
231 closed => 18,
232 new => 0,
233 open => 2,
234 patched => 0,
235 rejected => 0,
236 resolved => 18,
237 source => "https://rt.cpan.org/Public/Dist/Display.html?Name=Folkore-Japan",
238 stalled => 0,
239 },
240 } );
241 my $this = $obj->bugs;
242 $obj->bugs->github( {
243 active => 5,
244 closed => 10,
245 open => 3,
246 source => "https://github.com/momotaro/Folkore-Japan",
247 } );
248 my $github_obj = $obj->bugs->github;
249 $obj->bugs->rt( {
250 active => 2,
251 closed => 18,
252 new => 0,
253 open => 2,
254 patched => 0,
255 rejected => 0,
256 resolved => 18,
257 source => "https://rt.cpan.org/Public/Dist/Display.html?Name=Folkore-Japan",
258 stalled => 0,
259 } );
260 my $rt_obj = $obj->bugs->rt;
261  
262 Sets or gets a dynamic class object with class name C<Net::API::CPAN::Distribution::Bugs> and having the folowing properties also accessible as methods, and returns an object from such class, or C<undef> if no value was provided.
263  
264 =over 4
265  
266 =item * C<github> dynamic subclass (hash reference)
267  
268 =over 8
269  
270 =item * C<active> integer (L<number object|Module::Generic::Number>)
271  
272 =item * C<closed> integer (L<number object|Module::Generic::Number>)
273  
274 =item * C<open> integer (L<number object|Module::Generic::Number>)
275  
276 =item * C<source> URI (L<uri object|URI>)
277  
278 =back
279  
280 =item * C<rt> dynamic subclass (hash reference)
281  
282 =over 8
283  
284 =item * C<active> integer (L<number object|Module::Generic::Number>)
285  
286 =item * C<closed> integer (L<number object|Module::Generic::Number>)
287  
288 =item * C<open> integer (L<number object|Module::Generic::Number>)
289  
290 =item * C<patched> integer (L<number object|Module::Generic::Number>)
291  
292 =item * C<recent> integer (L<number object|Module::Generic::Number>)
293  
294 =item * C<rejected> integer (L<number object|Module::Generic::Number>)
295  
296 =item * C<resolved> integer (L<number object|Module::Generic::Number>)
297  
298 =item * C<source> URI (L<uri object|URI>)
299  
300 =item * C<stalled> integer (L<number object|Module::Generic::Number>)
301  
302 =back
303  
304 =back
305  
306 =head2 external_package
307  
308 $obj->external_package( {
309 cygwin => "perl-Folkore-Japan",
310 debian => "folklore-japan-perl",
311 fedora => "perl-Folkore-Japan",
312 } );
313 my $this = $obj->external_package;
314 $obj->external_package->cygwin( "perl-Folkore-Japan" );
315 my $scalar = $obj->external_package->cygwin;
316 $obj->external_package->debian( "folklore-japan-perl" );
317 my $scalar = $obj->external_package->debian;
318 $obj->external_package->fedora( "perl-Folkore-Japan" );
319 my $scalar = $obj->external_package->fedora;
320  
321 Sets or gets a dynamic class object with class name C<Net::API::CPAN::Distribution::ExternalPackage> and having the folowing properties also accessible as methods, and returns an object from such class, or C<undef> if no value was provided.
322  
323 =over 4
324  
325 =item * C<cygwin> scalar_as_object
326  
327 =item * C<debian> scalar_as_object
328  
329 =item * C<fedora> scalar_as_object
330  
331 =back
332  
333 =head2 github
334  
335 Returns the object for the dynamic class C<Net::API::CPAN::Bugs::Github>, which provides access to a few methods.
336  
337 See L</bugs> for more information.
338  
339 It returns C<undef> if no value is set.
340  
341 =head2 metacpan_url
342  
343 Returns a link, as an L<URI> object, to the distribution's page on MetaCPAN, or C<undef> if no distribution C<name> is currently set.
344  
345 =head2 name
346  
347 $obj->name( "Folklore-Japan" );
348 my $string = $obj->name;
349  
350 Sets or gets a string and returns a L<scalar object|Module::Generic::Scalar>, even if there is no value.
351  
352 =head2 object
353  
354 Returns the object type for this class, which is C<distribution>
355  
356 =head2 river
357  
358 $obj->river( {
359 bucket => 2,
360 bus_factor => 1,
361 immediate => 15,
362 total => 19,
363 } );
364 my $this = $obj->river;
365 $obj->river->bucket( 2 );
366 my $integer = $obj->river->bucket;
367 $obj->river->bus_factor( 1 );
368 my $integer = $obj->river->bus_factor;
369 $obj->river->immediate( 15 );
370 my $integer = $obj->river->immediate;
371 $obj->river->total( 19 );
372 my $integer = $obj->river->total;
373  
374 Sets or gets a dynamic class object with class name C<Net::API::CPAN::Distribution::River> and having the folowing properties also accessible as methods, and returns an object from such class, or C<undef> if no value was provided.
375  
376 =over 4
377  
378 =item * C<bucket> integer (L<number object|Module::Generic::Number>)
379  
380 =item * C<bus_factor> integer (L<number object|Module::Generic::Number>)
381  
382 =item * C<immediate> integer (L<number object|Module::Generic::Number>)
383  
384 =item * C<total> integer (L<number object|Module::Generic::Number>)
385  
386 =back
387  
388 =head2 rt
389  
390 Returns the object for the dynamic class C<Net::API::CPAN::Bugs::Rt>, which provides access to a few methods.
391  
392 See L</bugs> for more information.
393  
394 It returns C<undef> if no value is set.
395  
396 =head1 API SAMPLE
397  
398 {
399 "bugs" : {
400 "github" : {
401 "active" : 5,
402 "closed" : 10,
403 "open" : 3,
404 "source" : "https://github.com/momotaro/Folkore-Japan"
405 },
406 "rt" : {
407 "active" : "2",
408 "closed" : "18",
409 "new" : 0,
410 "open" : 2,
411 "patched" : 0,
412 "rejected" : 0,
413 "resolved" : 18,
414 "source" : "https://rt.cpan.org/Public/Dist/Display.html?Name=Folkore-Japan",
415 "stalled" : 0
416 }
417 },
418 "external_package" : {
419 "cygwin" : "perl-Folkore-Japan",
420 "debian" : "folklore-japan-perl",
421 "fedora" : "perl-Folkore-Japan"
422 },
423 "name" : "Folklore-Japan",
424 "river" : {
425 "bucket" : 2,
426 "bus_factor" : 1,
427 "immediate" : 15,
428 "total" : 19
429 }
430 }
431  
432 =head1 AUTHOR
433  
434 Jacques Deguest E<lt>F<jack@deguest.jp>E<gt>
435  
436 =head1 SEE ALSO
437  
438 L<Net::API::CPAN>, L<Net::API::CPAN::Activity>, L<Net::API::CPAN::Author>, L<Net::API::CPAN::Changes>, L<Net::API::CPAN::Changes::Release>, L<Net::API::CPAN::Contributor>, L<Net::API::CPAN::Cover>, L<Net::API::CPAN::Diff>, L<Net::API::CPAN::Distribution>, L<Net::API::CPAN::DownloadUrl>, L<Net::API::CPAN::Favorite>, L<Net::API::CPAN::File>, L<Net::API::CPAN::Module>, L<Net::API::CPAN::Package>, L<Net::API::CPAN::Permission>, L<Net::API::CPAN::Rating>, L<Net::API::CPAN::Release>
439  
440 L<MetaCPAN::API>, L<MetaCPAN::Client>
441  
442 L<https://github.com/metacpan/metacpan-api/blob/master/docs/API-docs.md>
443  
444 =head1 COPYRIGHT & LICENSE
445  
446 Copyright(c) 2023 DEGUEST Pte. Ltd.
447  
448 All rights reserved
449  
450 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
451  
452 =cut
453  
« lib/Net/API/CPAN/Release.pm ↑ Summary blib/lib/Net/API/CPAN/Activity.pm »