| 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 | 1 | ▶ | { | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 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'; | |||||||||||
| 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 | 0 | ▶ | { | ||||||||||
|
Subroutine
init: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 29 | 0 | 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 | ▶ | $self->SUPER::init( %$opts) || return( $self->pass_error ); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 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 | 0 | ▶ | { | ||||||||||
|
Subroutine
load_data: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||
| 46 | 0 | my $self = shift( @_ ); | |||||||||||
| 47 | 0 | ▶ | my $data = CORE::shift( @_ ) || | ||||||||||
|
Condition0%0/2
shift @_ || (return $self->error('No data was provided to load.'))
MC/DC0%0/1
shift @_ || (return $self->error('No data was provided to load.'))
shift @_
Truth table0%0/2
A
A= shift @_
| |||||||||||||
| 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
| |||||||||||||
| 50 | 0 | ▶ | if( !exists( $data->{hits} ) ) | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 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
| |||||||||||||
| 56 | 0 | ▶ | $self->SUPER::load_data( $data ) || return( $self->pass_error ); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 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 | 0 | ▶ | { | ||||||||||
|
Subroutine
init: not called CC=4 SCAR=30.0
| |||||||||||||
| 80 | 0 | my $self = shift( @_ ); | |||||||||||
| 81 | 0 | ▶ | $self->{favorites} = undef unless( exists( $self->{favorites} ) ); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 82 | 0 | ▶ | $self->{score} = undef unless( exists( $self->{score} ) ); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 83 | 0 | $self->{_init_strict_use_sub} = 1; | |||||||||||
| 84 | 0 | ▶ | $self->SUPER::init( @_ ) || return( $self->pass_error ); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 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__ | ||||||||||||