File Coverage

lib/Net/API/CPAN/Distribution.pm
Criterion Covered Total %
statement 44 54 81.4
branch 9 20 45.0
condition 3 23 13.0
subroutine 13 17 76.4
pod 9 9 100.0
total 78 123 63.4


line stmt bran cond sub pod time code
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     2   225411 use strict;
  2         12  
  2         79  
20 2     2   9 use warnings;
  2         5  
  2         58  
21 2     2   12 use parent qw( Net::API::CPAN::Generic );
  2         6  
  2         14  
22 2     2   116 use vars qw( $VERSION );
  2         3  
  2         107  
23 2     2   40 our $VERSION = 'v0.1.0';
24             };
25              
26 2     2   11 use strict;
  2         9  
  2         43  
27 2     2   9 use warnings;
  2         4  
  2         1478  
28              
29             sub init
30             {
31 1     1 1 9280 my $self = shift( @_ );
32 1 50       68 $self->{bugs} = undef unless( CORE::exists( $self->{bugs} ) );
33 1 50       5 $self->{external_package} = undef unless( CORE::exists( $self->{external_package} ) );
34 1 50       5 $self->{name} = undef unless( CORE::exists( $self->{name} ) );
35 1         3 $self->{object} = 'distribution';
36 1 50       4 $self->{river} = undef unless( CORE::exists( $self->{river} ) );
37             $self->{_init_preprocess} = sub
38             {
39 1     1   90 my $this = shift( @_ );
40 1 50       7 if( $self->_is_array( $this ) )
    0          
41             {
42 1         17 for( my $i = 0; $i < scalar( @$this ); $i += 2 )
43             {
44 5 100       16 if( $this->[$i] eq 'bugs' )
45             {
46 1         4 my $ref = $this->[$i + 1];
47 1 50 33     13 if( ref( $ref ) eq 'HASH' &&
      33        
      33        
48             exists( $ref->{rt} ) &&
49             ref( $ref->{rt} ) eq 'HASH' &&
50             exists( $ref->{rt}->{new} ) )
51             {
52 1         3 $ref->{rt}->{recent} = CORE::delete( $ref->{rt}->{new} );
53 1         5 $this->[$i + 1] = $ref;
54             }
55             }
56             }
57             }
58             elsif( $self->_is_hash( $this ) )
59             {
60 0 0 0     0 if( exists( $this->{bugs} ) &&
      0        
      0        
      0        
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         0 $this->{bugs}->{rt}->{recent} = CORE::delete( $this->{bugs}->{rt}->{new} );
67             }
68             }
69 1         3 return( $this );
70 1         5 };
71 1         3 $self->{_init_strict_use_sub} = 1;
72 1         3 $self->{_exception_class} = 'Net::API::CPAN::Exception';
73 1 50       6 $self->SUPER::init( @_ ) || return( $self->pass_error );
74 1         5 $self->{fields} = [qw( bugs external_package name river )];
75 1         6 return( $self );
76             }
77              
78 2     2 1 4221 sub bugs { return( shift->_set_get_class( 'bugs', {
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     2 1 1552 sub external_package { return( shift->_set_get_class( 'external_package', {
105             cygwin => "scalar_as_object",
106             debian => "scalar_as_object",
107             fedora => "scalar_as_object",
108             }, @_ ) ); }
109              
110 0     0 1 0 sub github { return( shift->bugs->github ); }
111              
112             sub metacpan_url
113             {
114 0     0 1 0 my $self = shift( @_ );
115 0   0     0 my $name = $self->name ||
116             return( $self->error( "No distribution name is set to return a Meta CPAN URL for this distribution." ) );
117 0         0 my $api_uri = $self->api->api_uri->clone;
118 0         0 $api_uri->path( "/release/$name" );
119 0         0 return( $api_uri );
120             }
121              
122 2     2 1 647672 sub name { return( shift->_set_get_scalar_as_object( 'name', @_ ) ); }
123              
124 0     0 1 0 sub object { return( shift->_set_get_scalar_as_object( 'object', @_ ) ); }
125              
126 2     2 1 5615 sub river { return( shift->_set_get_class( 'river', {
127             bucket => "integer",
128             bus_factor => "integer",
129             immediate => "integer",
130             total => "integer",
131             }, @_ ) ); }
132              
133 0     0 1   sub rt { return( shift->bugs->rt ); }
134              
135             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