Promise/Headers/Range.pm

filter: Statementstmt 97.2% 70 / 72 Branchbran 68.7% 11 / 16 Conditioncond 70.0% 7 / 10 MC/DCmcdc 33.3% 2 / 6 Subroutinesub 90.4% 19 / 21 Podpod 100% 5 / 5 totaltotal 87.6% 114 / 130 CC 14 SCAR 16.9
CC
14
Cov
90%
init
12.9
__ANON__
3.0
new_range
2.0
CRAP 5.4
« Promise/Headers/ContentDisposition.pm ↑ Summary Promise/Headers/ContentType.pm »
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
BranchTrueFalseTotal
if @_ == 1 and $self->_is_a($_[0], "Module::Generic::Null") 0 6 6
Condition66%2/3
@_ == 1 and $self->_is_a($_[0], "Module::Generic::Null")
!ll&&!rl&&r
150
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")
ABresult
0X0
100
111
33 6 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 5 1 6
34 {
35 5 my $this = shift( @_ );
36 5 my( $unit, $ref );
37 5 ▶ if( $self->_is_array( $this ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_array($this)) { } 0 5 5
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
BranchTrueFalseTotal
if ref $this and not overload::Method($this, "\"\"") 0 5 5
Condition33%1/3
ref $this and not overload::Method($this, "\"\"")
!ll&&!rl&&r
500
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, "\"\"")
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if ($this =~ s/^([a-zA-Z][a-zA-Z\_]+)[[:blank:]\h]*=[[:blank:]\h]*//) 5 0 5
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
BranchTrueFalseTotal
unless length $start 1 10 11
56 11 ▶ $end = undef if( !length( $end ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length $end 3 8 11
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
BranchTrueFalseTotal
$self->SUPER::init(@_) or return $self->pass_error 6 0 6
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 // ""
l!l
161
$_->end // ""
l!l
125
MC/DC100%1/1
$_->start // ""
$_->start
MC/DC100%1/1
$_->end // ""
$_->end
Truth table100%2/2
A
A= $_->start
Aresult
11
00
Truth table100%2/2
A
A= $_->end
Aresult
11
00
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__
« Promise/Headers/ContentDisposition.pm ↑ Summary Promise/Headers/ContentType.pm »