| 1 | ##---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||
| 2 | ## Meta CPAN API - ~/lib/Net/API/CPAN/Activity.pm | ||||||||||||||||||||||||||||||||||
| 3 | ## Version v0.1.0 | ||||||||||||||||||||||||||||||||||
| 4 | ## Copyright(c) 2023 DEGUEST Pte. Ltd. | ||||||||||||||||||||||||||||||||||
| 5 | ## Author: Jacques Deguest <jack@deguest.jp> | ||||||||||||||||||||||||||||||||||
| 6 | ## Created 2023/09/12 | ||||||||||||||||||||||||||||||||||
| 7 | ## Modified 2023/09/12 | ||||||||||||||||||||||||||||||||||
| 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::Activity; | ||||||||||||||||||||||||||||||||||
| 15 | BEGIN | ||||||||||||||||||||||||||||||||||
| 16 | 2 | ▶ | { | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 17 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 18 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 19 | 2 | ▶ | use parent qw( Net::API::CPAN::Generic ); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 20 | 2 | ▶ | use vars qw( $VERSION ); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 21 | 2 | ▶ | use DateTime; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 22 | 2 | our $VERSION = 'v0.1.0'; | |||||||||||||||||||||||||||||||||
| 23 | }; | ||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||
| 25 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 26 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||
| 28 | sub init | ||||||||||||||||||||||||||||||||||
| 29 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||
|
Subroutine
init: called CC=3 SCAR=11.3
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 30 | 1 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||
| 31 | 1 | ▶ | $self->{activity} = [] unless( exists( $self->{activity} ) ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 32 | 1 | $self->{_init_strict_use_sub} = 1; | |||||||||||||||||||||||||||||||||
| 33 | 1 | ▶ | $self->SUPER::init( @_ ) || return( $self->pass_error ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 34 | 1 | return( $self ); | |||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||
| 37 | sub activity | ||||||||||||||||||||||||||||||||||
| 38 | 2 | ▶ | { | ||||||||||||||||||||||||||||||||
|
Subroutine
activity: called CC=10 SCAR=28.3
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 39 | 2 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||
| 40 | 2 | ▶ | if( @_ ) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 41 | { | ||||||||||||||||||||||||||||||||||
| 42 | 1 | my $data = shift( @_ ); | |||||||||||||||||||||||||||||||||
| 43 | 1 | my $months; | |||||||||||||||||||||||||||||||||
| 44 | 1 | ▶ | if( $self->_is_array( $data ) ) | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 45 | { | ||||||||||||||||||||||||||||||||||
| 46 | 1 | $months = $data; | |||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||
| 48 | ▶ | elsif( ref( $data ) eq 'HASH' && | |||||||||||||||||||||||||||||||||
|
Condition0%0/6
ref $data eq "HASH" and exists $data->{"activity"} and $self->_is_array($data->{"activity"})
ref $data eq "HASH" and exists $data->{"activity"}
MC/DC0%0/3
ref $data eq "HASH" and exists $data->{"activity"} and $self->_is_array($data->{"activity"})
ref $data eq "HASH"
exists $data->{"activity"}
$self->_is_array($data->{"activity"})
Truth table0%0/4
A and B and C
A= ref $data eq "HASH"B= exists $data->{"activity"}C= $self->_is_array($data->{"activity"})
| |||||||||||||||||||||||||||||||||||
| 49 | exists( $data->{activity} ) && | ||||||||||||||||||||||||||||||||||
| 50 | $self->_is_array( $data->{activity} ) ) | ||||||||||||||||||||||||||||||||||
| 51 | { | ||||||||||||||||||||||||||||||||||
| 52 | 0 | $months = $data->{activity}; | |||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||
| 55 | 1 | ▶ | if( !defined( $months ) ) | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 56 | { | ||||||||||||||||||||||||||||||||||
| 57 | 0 | return( $self->error( "No data was provided. I was expecting either an array of integers, or an hash with a 'activity' property pointing to that array of integers." ) ); | |||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||
| 59 | elsif( scalar( @$months ) != 24 ) | ||||||||||||||||||||||||||||||||||
| 60 | { | ||||||||||||||||||||||||||||||||||
| 61 | 0 | ▶ | warn( "The data provided contains ", scalar( @$months ), " elements versus the 24 that were expected." ) if( $self->_is_warnings_enabled( 'Net::API::CPAN' ) ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||
| 63 | # A copy from MetaCPAN::Query::Release->activity() | ||||||||||||||||||||||||||||||||||
| 64 | # <https://github.com/metacpan/metacpan-api/blob/db7c3a90925ec85e6ae6a9f6dd64677305feac8d/lib/MetaCPAN/Query/Release.pm#L303> | ||||||||||||||||||||||||||||||||||
| 65 | 1 | my $start = DateTime->now->truncate( to => 'month' )->subtract( months => 23 ); | |||||||||||||||||||||||||||||||||
| 66 | # from the furthest to most recent month | ||||||||||||||||||||||||||||||||||
| 67 | # 0 being the start, and 23 being our current month | ||||||||||||||||||||||||||||||||||
| 68 | 1 | my $a = $self->new_array; | |||||||||||||||||||||||||||||||||
| 69 | 1 | my $hash = $self->new_hash; | |||||||||||||||||||||||||||||||||
| 70 | # Allow reference as hash keys | ||||||||||||||||||||||||||||||||||
| 71 | 1 | $hash->key_object(1); | |||||||||||||||||||||||||||||||||
| 72 | 1 | for( 0..23 ) | |||||||||||||||||||||||||||||||||
| 73 | { | ||||||||||||||||||||||||||||||||||
| 74 | 24 | my $dt = $start->clone->add( months => $_ ); | |||||||||||||||||||||||||||||||||
| 75 | 24 | $a->push({ dt => $dt, value => $months->[$_] }); | |||||||||||||||||||||||||||||||||
| 76 | 24 | $hash->{ $dt } = $months->[$_]; | |||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||
| 78 | 1 | $self->{activity} = $a; | |||||||||||||||||||||||||||||||||
| 79 | 1 | $self->{activities} = $hash; | |||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||
| 81 | 2 | return( $self->_set_get_array_as_object( 'activity' ) ); | |||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||
| 84 | 1 | ▶ | sub activities { return( shift->_set_get_hash_as_mix_object( 'activities', @_ ) ); } | ||||||||||||||||||||||||||||||||
|
Subroutine
activities: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||
| 86 | 2 | 1; | |||||||||||||||||||||||||||||||||
| 87 | # NOTE: POD | ||||||||||||||||||||||||||||||||||
| 88 | __END__ | ||||||||||||||||||||||||||||||||||