| line | stmt | bran | cond | sub | pod | time | code | 
| 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 |  |  | 1 |  | 1021 | use strict; | 
|  | 1 |  |  |  |  | 3 |  | 
|  | 1 |  |  |  |  | 35 |  | 
| 18 | 1 |  |  | 1 |  | 5 | use warnings; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 33 |  | 
| 19 | 1 |  |  | 1 |  | 6 | use parent qw( Net::API::CPAN::List ); | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 8 |  | 
| 20 | 1 |  |  | 1 |  | 74 | use vars qw( $VERSION ); | 
|  | 1 |  |  |  |  | 3 |  | 
|  | 1 |  |  |  |  | 52 |  | 
| 21 | 1 |  |  | 1 |  | 23 | our $VERSION = 'v0.1.0'; | 
| 22 |  |  |  |  |  |  | }; | 
| 23 |  |  |  |  |  |  |  | 
| 24 | 1 |  |  | 1 |  | 6 | use strict; | 
|  | 1 |  |  |  |  | 4 |  | 
|  | 1 |  |  |  |  | 20 |  | 
| 25 | 1 |  |  | 1 |  | 4 | use warnings; | 
|  | 1 |  |  |  |  | 4 |  | 
|  | 1 |  |  |  |  | 380 |  | 
| 26 |  |  |  |  |  |  |  | 
| 27 |  |  |  |  |  |  | sub init | 
| 28 |  |  |  |  |  |  | { | 
| 29 | 0 |  |  | 0 | 1 |  | my $self = shift( @_ ); | 
| 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 | 0 |  |  |  |  | $self->SUPER::init( %$opts) || return( $self->pass_error ); | 
| 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 |  |  | 0 | 1 |  | my $self = shift( @_ ); | 
| 47 | 0 |  | 0 |  |  |  | my $data = CORE::shift( @_ ) || | 
| 48 |  |  |  |  |  |  | return( $self->error( "No data was provided to load." ) ); | 
| 49 | 0 | 0 |  |  |  |  | return( $self->error( "Data provided is not an hash reference." ) ) if( ref( $data ) ne 'HASH' ); | 
| 50 | 0 | 0 |  |  |  |  | if( !exists( $data->{hits} ) ) | 
| 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 | 0 |  |  |  |  | $self->distribution( $data->{hits}->[0]->{distribution} ) if( !$self->distribution ); | 
| 56 | 0 | 0 |  |  |  |  | $self->SUPER::load_data( $data ) || return( $self->pass_error ); | 
| 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 |  |  | 0 | 1 |  | sub distribution { return( shift->_set_get_scalar_as_object( 'distribution', @_ ) ); } | 
| 64 |  |  |  |  |  |  |  | 
| 65 |  |  |  |  |  |  | # NOTE: Net::API::CPAN::List::Web::Element class | 
| 66 |  |  |  |  |  |  | package | 
| 67 |  |  |  |  |  |  | Net::API::CPAN::List::Web::Element; | 
| 68 |  |  |  |  |  |  | BEGIN | 
| 69 | 1 |  |  |  |  | 59 | { | 
| 70 | 1 |  |  | 1 |  | 9 | use strict; | 
|  | 1 |  |  |  |  | 3 |  | 
|  | 1 |  |  |  |  | 49 |  | 
| 71 | 1 |  |  | 1 |  | 7 | use warnings; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 36 |  | 
| 72 | 1 |  |  | 1 |  | 5 | use parent qw( Net::API::CPAN::Module ); | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 5 |  | 
| 73 |  |  |  |  |  |  | }; | 
| 74 |  |  |  |  |  |  |  | 
| 75 | 1 |  |  | 1 |  | 5 | use strict; | 
|  | 1 |  |  |  |  | 20 |  | 
|  | 1 |  |  |  |  | 4 |  | 
| 76 | 1 |  |  | 1 |  | 2 | use warnings; | 
|  | 1 |  |  |  |  | 212 |  | 
|  | 0 |  |  |  |  |  |  | 
| 77 |  |  |  |  |  |  |  | 
| 78 |  |  |  |  |  |  | sub init | 
| 79 |  |  |  |  |  |  | { | 
| 80 | 0 |  |  | 0 |  |  | my $self = shift( @_ ); | 
| 81 | 0 | 0 |  |  |  |  | $self->{favorites} = undef unless( exists( $self->{favorites} ) ); | 
| 82 | 0 | 0 |  |  |  |  | $self->{score} = undef unless( exists( $self->{score} ) ); | 
| 83 | 0 |  |  |  |  |  | $self->{_init_strict_use_sub} = 1; | 
| 84 | 0 | 0 |  |  |  |  | $self->SUPER::init( @_ ) || return( $self->pass_error ); | 
| 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 |  |  | 0 |  |  | sub favorites { return( shift->_set_get_number( { field => 'favorites', undef_ok => 1 }, @_ ) ); } | 
| 93 |  |  |  |  |  |  |  | 
| 94 |  |  |  | 0 |  |  | sub score { return( shift->_set_get_number( { field => 'score', undef_ok => 1 }, @_ ) ); } | 
| 95 |  |  |  |  |  |  |  | 
| 96 |  |  |  |  |  |  | 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 |