| 1 | ##---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 2 | ## Asynchronous HTTP Request and Promise - ~/lib/HTTP/Promise/Headers/Range.pm | ||||||||||||||||||||||||||||
| 3 | ## Version v0.1.0 | ||||||||||||||||||||||||||||
| 4 | ## Copyright(c) 2022 DEGUEST Pte. Ltd. | ||||||||||||||||||||||||||||
| 5 | ## Author: Jacques Deguest <jack@deguest.jp> | ||||||||||||||||||||||||||||
| 6 | ## Created 2022/05/08 | ||||||||||||||||||||||||||||
| 7 | ## Modified 2022/05/08 | ||||||||||||||||||||||||||||
| 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 HTTP::Promise::Headers::Range; | ||||||||||||||||||||||||||||
| 15 | BEGIN | ||||||||||||||||||||||||||||
| 16 | 3 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 3 | warnings::register_categories( 'HTTP::Promise' ); | |||||||||||||||||||||||||||
| 20 | 3 | ▶ | use parent qw( HTTP::Promise::Headers::Generic ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | 3 | our $VERSION = 'v0.1.0'; | |||||||||||||||||||||||||||
| 22 | }; | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 25 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | sub init | ||||||||||||||||||||||||||||
| 28 | 6 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
init: called CC=12 SCAR=25.6
Pod
documented
| |||||||||||||||||||||||||||||
| 29 | 6 | my $self = shift( @_ ); | |||||||||||||||||||||||||||
| 30 | 6 | $self->{ranges} = []; | |||||||||||||||||||||||||||
| 31 | 6 | $self->{unit} = 'bytes'; | |||||||||||||||||||||||||||
| 32 | 6 | ▶ | @_ = () if( @_ == 1 && $self->_is_a( $_[0] => 'Module::Generic::Null' ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@_ == 1 and $self->_is_a($_[0], "Module::Generic::Null")
MC/DC0%0/2
@_ == 1 and $self->_is_a($_[0], "Module::Generic::Null")
@_ == 1
$self->_is_a($_[0], "Module::Generic::Null")
Truth table66%2/3
A and B
A= @_ == 1B= $self->_is_a($_[0], "Module::Generic::Null")
| |||||||||||||||||||||||||||||
| 33 | 6 | ▶ | if( @_ ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | { | ||||||||||||||||||||||||||||
| 35 | 5 | my $this = shift( @_ ); | |||||||||||||||||||||||||||
| 36 | 5 | my( $unit, $ref ); | |||||||||||||||||||||||||||
| 37 | 5 | ▶ | if( $self->_is_array( $this ) ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | { | ||||||||||||||||||||||||||||
| 39 | 0 | $ref = $this; | |||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | else | ||||||||||||||||||||||||||||
| 42 | { | ||||||||||||||||||||||||||||
| 43 | 5 | ▶ | return( $self->error( "Bad argument provided '$this'. You can provide either an array reference or a string." ) ) if( ref( $this ) && !overload::Method( $this, '""' ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $this and not overload::Method($this, "\"\"")
MC/DC0%0/2
ref $this and not overload::Method($this, "\"\"")
ref $this
not overload::Method($this, "\"\"")
Truth table33%1/3
A and not(B)
A= ref $thisB= not overload::Method($this, "\"\"")
| |||||||||||||||||||||||||||||
| 44 | 5 | $this =~ s/^[[:blank:]\h]+|[[:blank:]\h]+$//g; | |||||||||||||||||||||||||||
| 45 | 5 | ▶ | if( $this =~ s/^([a-zA-Z][a-zA-Z\_]+)[[:blank:]\h]*=[[:blank:]\h]*// ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | { | ||||||||||||||||||||||||||||
| 47 | 5 | $unit = $1; | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | 5 | $ref = [split( /[[:blank:]\h]*,[[:blank:]\h]*/, "$this" )]; | |||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | 5 | my $ranges = $self->new_array; | |||||||||||||||||||||||||||
| 52 | 5 | foreach( @$ref ) | |||||||||||||||||||||||||||
| 53 | { | ||||||||||||||||||||||||||||
| 54 | 11 | my( $start, $end ) = split( /[[:blank:]\h]*-[[:blank:]\h]*/ ); | |||||||||||||||||||||||||||
| 55 | 11 | ▶ | $start = undef if( !length( $start ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | 11 | ▶ | $end = undef if( !length( $end ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | 11 | my $range = HTTP::Promise::Headers::Range::StartEnd->new( $start, $end ); | |||||||||||||||||||||||||||
| 58 | 11 | $ranges->push( $range ); | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | 5 | $self->ranges( $ranges ); | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | 6 | $self->{_init_strict_use_sub} = 1; | |||||||||||||||||||||||||||
| 63 | 6 | ▶ | $self->SUPER::init( @_ ) || return( $self->pass_error ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | 6 | $self->_field_name( 'Range' ); | |||||||||||||||||||||||||||
| 65 | 6 | return( $self ); | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | sub as_string | ||||||||||||||||||||||||||||
| 69 | 7 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
as_string: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 70 | 7 | my $self = shift( @_ ); | |||||||||||||||||||||||||||
| 71 | # In the sprintf, we use %s and not %d, because start or end may be undef, and it would inadvertently result in 0 | ||||||||||||||||||||||||||||
| 72 | 7 | ▶ | return( $self->unit->scalar . '=' . $self->ranges->map(sub{ sprintf( '%s-%s', ( $_->start // '' ), ( $_->end // '' ) ); })->join( ', ' )->scalar ); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
Condition100%4/4
$_->start // ""
$_->end // ""
MC/DC100%1/1
$_->start // ""
$_->start
MC/DC100%1/1
$_->end // ""
$_->end
Truth table100%2/2
A
A= $_->start
Truth table100%2/2
A
A= $_->end
| |||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 0 | ▶ | sub new_range { HTTP::Promise::Headers::Range::StartEnd->new( @_ ) }; | ||||||||||||||||||||||||||
|
Subroutine
new_range: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 26 | ▶ | sub ranges { return( shift->_set_get_array_as_object( 'ranges', @_ ) ); } | ||||||||||||||||||||||||||
|
Subroutine
ranges: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 11 | ▶ | sub unit { return( shift->_set_get_scalar_as_object( 'unit', @_ ) ); } | ||||||||||||||||||||||||||
|
Subroutine
unit: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | { | ||||||||||||||||||||||||||||
| 82 | package | ||||||||||||||||||||||||||||
| 83 | HTTP::Promise::Headers::Range::StartEnd; | ||||||||||||||||||||||||||||
| 84 | BEGIN | ||||||||||||||||||||||||||||
| 85 | { | ||||||||||||||||||||||||||||
| 86 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 87 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 88 | 3 | ▶ | use parent qw( Module::Generic ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 89 | }; | ||||||||||||||||||||||||||||
| 90 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 91 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | sub init | ||||||||||||||||||||||||||||
| 94 | 11 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
init: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 95 | 11 | my $self = shift( @_ ); | |||||||||||||||||||||||||||
| 96 | 11 | my @args = @_; | |||||||||||||||||||||||||||
| 97 | 11 | @$self{qw( start end )} = splice( @_, 0, 2 ); | |||||||||||||||||||||||||||
| 98 | 11 | return( $self->SUPER::init( @_ ) ); | |||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 44 | ▶ | sub end { return( shift->_set_get_number( 'end', @_ ) ); } | ||||||||||||||||||||||||||
|
Subroutine
end: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 34 | ▶ | sub start { return( shift->_set_get_number( 'start', @_ ) ); } | ||||||||||||||||||||||||||
|
Subroutine
start: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 3 | 1; | |||||||||||||||||||||||||||
| 107 | # NOTE: POD | ||||||||||||||||||||||||||||
| 108 | __END__ | ||||||||||||||||||||||||||||