lib/Net/API/CPAN/List/Web.pm

filter: Statementstmt 53.0% 35 / 66 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 66.6% 12 / 18 Podpod 100% 3 / 3 totaltotal 47.1% 50 / 106 CC 10 SCAR 26.0
CC
10
Cov
42%
load_data
42.0
init
20.0
init
6.0
CRAP 13.4
« blib/lib/Net/API/CPAN/Cover.pm ↑ Summary blib/lib/Net/API/CPAN/Scroll.pm »
1 ##----------------------------------------------------------------------------
2 ## Meta CPAN API - ~/lib/Net/API/CPAN/List/Web.pm
3 ## Version v0.1.0
4 ## Copyright(c) 2023 DEGUEST Pte. Ltd.
5 ## Author: Jacques Deguest <jack@deguest.jp>
6 ## Created 2023/09/23
7 ## Modified 2023/09/23
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 package Net::API::CPAN::List::Web;
15 BEGIN
16 {
17 1 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶ use parent qw( Net::API::CPAN::List );
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶ use vars qw( $VERSION );
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶ our $VERSION = 'v0.1.0';
Subroutine BEGIN: called CC=1 SCAR=0.0
22 };
23  
24 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 sub init
28 {
29 0 ▶ my $self = shift( @_ );
Subroutine init: not called CC=2 SCAR=17.9
Pod documented
30 # We capture the options passed, and we remove 'hits' that is treated specially
31 0 my $opts = $self->_get_args_as_hash( @_ );
32 0 $opts->{data} = { hits => delete( $opts->{hits} ) };
33 0 $self->{container} = 'hits';
34 # The elements will be instantiated as Net::API::CPAN::List::Web::Element objects
35 0 $self->{type} = 'Net::API::CPAN::List::Web::Element';
36 0 $self->{_init_strict_use_sub} = 1;
37 # We want the property 'total' to be processed first, so it can be overriden if necessary
38 0 $self->{_init_params_order} = [qw( distribution total data )];
39 0 ▶ $self->SUPER::init( %$opts) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->SUPER::init(%$opts) or return $self->pass_error 0 0 0
40 0 $self->message( 4, "Instantiating ", ref( $self ), " object for distribution '", $opts->{distribution}, "' with total ", $self->total );
41 0 return( $self );
42 }
43  
44 sub load_data
45 {
46 0 ▶ my $self = shift( @_ );
Subroutine load_data: not called CC=6 SCAR=37.4
Pod documented
47 0 ▶ my $data = CORE::shift( @_ ) ||
Condition0%0/2
shift @_ || (return $self->error('No data was provided to load.'))
l!l
00
MC/DC0%0/1
shift @_ || (return $self->error('No data was provided to load.'))
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
48 return( $self->error( "No data was provided to load." ) );
49 0 ▶ return( $self->error( "Data provided is not an hash reference." ) ) if( ref( $data ) ne 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $data ne "HASH" 0 0 0
50 0 ▶ if( !exists( $data->{hits} ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $data->{"hits"}) 0 0 0
51 {
52 0 return( $self->error( "No property 'hits' in the data provided." ) );
53 }
54 0 $self->message( 4, "Loading data received with ", scalar( keys( %$data ) ), " properties: ", join( ', ', sort( keys( %$data ) ) ) );
55 0 ▶ $self->distribution( $data->{hits}->[0]->{distribution} ) if( !$self->distribution );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->distribution 0 0 0
56 0 ▶ $self->SUPER::load_data( $data ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->SUPER::load_data($data) or return $self->pass_error 0 0 0
57 # We cannot trust the property 'total' unfortunately
58 0 $self->message( 4, "Setting total to '", $self->items->length, "'" );
59 0 $self->total( $self->items->length );
60 0 return( $self );
61 }
62  
63 0 ▶sub distribution { return( shift->_set_get_scalar_as_object( 'distribution', @_ ) ); }
Subroutine distribution: not called CC=1 SCAR=6.9
Pod documented
64  
65 # NOTE: Net::API::CPAN::List::Web::Element class
66 package
67 Net::API::CPAN::List::Web::Element;
68 BEGIN
69 {
70 1 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
71 1 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
72 1 ▶ use parent qw( Net::API::CPAN::Module );
Subroutine BEGIN: called CC=1 SCAR=0.0
73 };
74  
75 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
76 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
77  
78 sub init
79 {
80 0 ▶ my $self = shift( @_ );
Subroutine init: not called CC=4 SCAR=30.0
81 0 ▶ $self->{favorites} = undef unless( exists( $self->{favorites} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"favorites"} 0 0 0
82 0 ▶ $self->{score} = undef unless( exists( $self->{score} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"score"} 0 0 0
83 0 $self->{_init_strict_use_sub} = 1;
84 0 ▶ $self->SUPER::init( @_ ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->SUPER::init(@_) or return $self->pass_error 0 0 0
85 0 $self->{fields} = [qw(
86 abstract author authorized date description distribution documentation favorites
87 id indexed path pod_lines release score status
88 )];
89 0 return( $self );
90 }
91  
92 0 ▶sub favorites { return( shift->_set_get_number( { field => 'favorites', undef_ok => 1 }, @_ ) ); }
Subroutine favorites: not called CC=1 SCAR=6.9
93  
94 0 ▶sub score { return( shift->_set_get_number( { field => 'score', undef_ok => 1 }, @_ ) ); }
Subroutine score: not called CC=1 SCAR=6.9
95  
96 1 1;
97 # NOTE: POD
98 __END__
99  
100 =encoding utf-8
101  
102 =head1 NAME
103  
104 Net::API::CPAN::List::Web - Web Search Result List Object Class
105  
106 =head1 SYNOPSIS
107  
108 use Net::API::CPAN::List::Web;
109 my $list = Net::API::CPAN::List::Web->new(
110 {
111 distribution => "Folklore-Japan",
112 hits => [
113 {
114 abstract => "Japan Folklore Object Class",
115 author => "MOMOTARO",
116 authorized => 1,
117 date => "2023-07-17T09:43:41",
118 description => "Folklore::Japan is a totally fictious perl 5 module designed to serve as an example for the MetaCPAN API.",
119 distribution => "Folklore-Japan",
120 documentation => "Folklore::Japan",
121 favorites => 1,
122 id => "abcd1234edfgh56789",
123 indexed => 1,
124 module => [
125 {
126 associated_pod => "MOMOTARO/Folklore-Japan-v0.1.0/lib/Folklore/Japan.pm",
127 authorized => 1,
128 indexed => 1,
129 name => "Folklore::Japan",
130 version => 'v0.1.0',,
131 version_numified => 0.001000,
132 },
133 ],
134 path => "lib/Folklore/Japan.pm",
135 pod_lines => [12, 320],
136 release => "Folklore-Japan-v0.1.0",
137 score => 0.031563006,
138 status => "latest",
139 },
140 ],
141 total => 1,
142 }
143 ) || die( Net::API::CPAN::List::Web->error );
144  
145 =head1 VERSION
146  
147 v0.1.0
148  
149 =head1 DESCRIPTION
150  
151 This object class is used to represent web search result. It inherits from L<Net::API::CPAN::List>, because this result set is basically a result set within a result set.
152  
153 This class object type C<list_web> is used when instantiating a new L<Net::API::CPAN::List> object, so that each of the data array elements are instantiated as an object of this class.
154  
155 So the overall structure would look like this:
156  
157 Net::API::CPAN::List object = [
158 Net::API::CPAN::List::Web object,
159 Net::API::CPAN::List::Web object,
160 Net::API::CPAN::List::Web object,
161 # etc..
162 ]
163  
164 =head1 METHODS
165  
166 For all other methods, please refer to this class parent L<Net::API::CPAN::List>
167  
168 =head2 distribution
169  
170 String. This represents the distribution name for this sub-result set.
171  
172 =head1 AUTHOR
173  
174 Jacques Deguest E<lt>F<jack@deguest.jp>E<gt>
175  
176 =head1 SEE ALSO
177  
178 L<Net::API::CPAN::List>
179  
180 =head1 COPYRIGHT & LICENSE
181  
182 Copyright(c) 2023 DEGUEST Pte. Ltd.
183  
184 All rights reserved
185  
186 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
187  
188 =cut
« blib/lib/Net/API/CPAN/Cover.pm ↑ Summary blib/lib/Net/API/CPAN/Scroll.pm »