HTTP/Request.pm

filter: Statementstmt 100% 84 / 84 Branchbran 85.7% 48 / 56 Conditioncond 95.8% 23 / 24 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 100% 11 / 11 Podpod 100% 7 / 7 totaltotal 90.5% 173 / 191 CC 39 SCAR 22.4
CC
39
Cov
95%
new
18.0
authority
6.0
target
5.0
CRAP 9.4
« HTTP/Auth/Basic.pm ↑ Summary HTTP/Response.pm »
1 package Uniform::HTTP::Request;
2  
3 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 8 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 8 ▶use parent 'Uniform::HTTP::Message';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 8 our $VERSION = '0.04';
9  
10 69 ▶sub new {
Subroutine new: called CC=18 SCAR=28.9
Pod documented
11 69 my ($class, @args) = @_;
12 69 my $args = Uniform::HTTP::Message::_named_args('new', @args);
13  
14 69 for my $name (keys %$args) {
15 295 ▶ croak "unknown constructor option '$name'"
Branch: 1 branch
BranchTrueFalseTotal
unless $name eq "method" or $name eq "target" or $name eq "scheme" or $name eq "authority" or $name eq "protocol" or $name eq "version" or $name eq "headers" or $name eq "trailers" or $name eq "body" 0 295 295
Condition95%23/24
$name eq "method" or $name eq "target" or $name eq "scheme" or $name eq "authority" or $name eq "protocol" or $name eq "version" or $name eq "headers" or $name eq "trailers" or $name eq "body"
l!l&&r!l&&!r
29410
$name eq "method" or $name eq "target" or $name eq "scheme" or $name eq "authority" or $name eq "protocol" or $name eq "version" or $name eq "headers" or $name eq "trailers"
l!l&&r!l&&!r
29221
$name eq "method" or $name eq "target" or $name eq "scheme" or $name eq "authority" or $name eq "protocol" or $name eq "version" or $name eq "headers"
l!l&&r!l&&!r
255373
$name eq "method" or $name eq "target" or $name eq "scheme" or $name eq "authority" or $name eq "protocol" or $name eq "version"
l!l&&r!l&&!r
2173840
$name eq "method" or $name eq "target" or $name eq "scheme" or $name eq "authority" or $name eq "protocol"
l!l&&r!l&&!r
1853278
$name eq "method" or $name eq "target" or $name eq "scheme" or $name eq "authority"
l!l&&r!l&&!r
15629110
$name eq "method" or $name eq "target" or $name eq "scheme"
l!l&&r!l&&!r
13620139
$name eq "method" or $name eq "target"
l!l&&r!l&&!r
6868159
MC/DC0%0/9
$name eq "method" or $name eq "target" or $name eq "scheme" or $name eq "authority" or $name eq "protocol" or $name eq "version" or $name eq "headers" or $name eq "trailers" or $name eq "body"
$name eq "method" $name eq "target" $name eq "scheme" $name eq "authority" $name eq "protocol" $name eq "version" $name eq "headers" $name eq "trailers" $name eq "body"
Truth table90%9/10
A or B or C or D or E or F or G or H or I
A= $name eq "method"B= $name eq "target"C= $name eq "scheme"D= $name eq "authority"E= $name eq "protocol"F= $name eq "version"G= $name eq "headers"H= $name eq "trailers"I= $name eq "body"
ABCDEFGHIresult
1XXXXXXXX1
01XXXXXXX1
001XXXXXX1
0001XXXXX1
00001XXXX1
000001XXX1
0000001XX1
00000001X1
0000000011
0000000000
16 unless $name eq 'method'
17 || $name eq 'target'
18 || $name eq 'scheme'
19 || $name eq 'authority'
20 || $name eq 'protocol'
21 || $name eq 'version'
22 || $name eq 'headers'
23 || $name eq 'trailers'
24 || $name eq 'body';
25 }
26  
27 69 ▶ croak 'method is required' unless exists $args->{method};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $args->{"method"} 1 68 69
28 68 ▶ croak 'target is required' unless exists $args->{target};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $args->{"target"} 1 67 68
29  
30 67 my @common;
31 67 for my $name (qw(version headers trailers body)) {
32 268 ▶ push @common, $name => $args->{$name} if exists $args->{$name};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args->{$name} 78 190 268
33 }
34  
35 67 my $self = $class->SUPER::new(@common);
36 67 $self->method($args->{method});
37 66 $self->target($args->{target});
38 65 ▶ $self->scheme($args->{scheme}) if exists $args->{scheme};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args->{"scheme"} 20 45 65
39 65 ▶ $self->authority($args->{authority}) if exists $args->{authority};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args->{"authority"} 29 36 65
40 61 ▶ $self->protocol($args->{protocol}) if exists $args->{protocol};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args->{"protocol"} 32 29 61
41 49 return $self;
42 }
43  
44 75 ▶sub method {
Subroutine method: called CC=4 SCAR=13.9
Pod documented
45 75 my ($self, @args) = @_;
46 75 ▶ return $self->{method} unless @args;
Branch: 1 branch
BranchTrueFalseTotal
unless @args 3 72 75
47 72 ▶ croak 'method() accepts at most one value' unless @args == 1;
Branch: 1 branch
BranchTrueFalseTotal
unless @args == 1 0 72 72
48  
49 72 $self->_assert_initial_mutable;
50 69 my $method = Uniform::HTTP::Message::_byte_string('method', $args[0]);
51 69 ▶ croak 'method must be an HTTP token'
Branch: 1 branch
BranchTrueFalseTotal
unless $method =~ /\A[!\#\$%&'*+\-.\^_`|~0-9A-Za-z]+\z/ 1 68 69
52 unless $method =~ /\A[!\#\$%&'*+\-.\^_`|~0-9A-Za-z]+\z/;
53 68 $self->{method} = $method;
54 68 return $self;
55 }
56  
57 110 ▶sub target {
Subroutine target: called CC=5 SCAR=16.2
Pod documented
58 110 my ($self, @args) = @_;
59 110 ▶ return $self->{target} unless @args;
Branch: 1 branch
BranchTrueFalseTotal
unless @args 40 70 110
60 70 ▶ croak 'target() accepts at most one value' unless @args == 1;
Branch: 1 branch
BranchTrueFalseTotal
unless @args == 1 0 70 70
61  
62 70 $self->_assert_initial_mutable;
63 67 my $target = Uniform::HTTP::Message::_byte_string('target', $args[0]);
64 67 ▶ croak 'target must not be empty' unless length $target;
Branch: 1 branch
BranchTrueFalseTotal
unless length $target 0 67 67
65 67 ▶ croak 'target must not contain spaces or control bytes'
Branch: 1 branch
BranchTrueFalseTotal
if $target =~ /[\x00-\x20\x7f]/ 1 66 67
66 if $target =~ /[\x00-\x20\x7f]/;
67 66 $self->{target} = $target;
68 66 return $self;
69 }
70  
71 66 ▶sub scheme {
Subroutine scheme: called CC=5 SCAR=16.2
Pod documented
72 66 my ($self, @args) = @_;
73 66 ▶ return $self->{scheme} unless @args;
Branch: 1 branch
BranchTrueFalseTotal
unless @args 41 25 66
74 25 ▶ croak 'scheme() accepts at most one value' unless @args == 1;
Branch: 1 branch
BranchTrueFalseTotal
unless @args == 1 0 25 25
75  
76 25 $self->_assert_initial_mutable;
77 22 ▶ if (!defined $args[0]) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args[0]) 1 21 22
78 1 $self->{scheme} = undef;
79 1 return $self;
80 }
81  
82 21 my $scheme = Uniform::HTTP::Message::_byte_string('scheme', $args[0]);
83 21 ▶ croak 'scheme must be a valid URI scheme'
Branch: 1 branch
BranchTrueFalseTotal
unless $scheme =~ /\A[A-Za-z][A-Za-z0-9+.-]*\z/ 0 21 21
84 unless $scheme =~ /\A[A-Za-z][A-Za-z0-9+.-]*\z/;
85 21 $self->{scheme} = $scheme;
86 21 return $self;
87 }
88  
89 76 ▶sub authority {
Subroutine authority: called CC=6 SCAR=17.9
Pod documented
90 76 my ($self, @args) = @_;
91 76 ▶ return $self->{authority} unless @args;
Branch: 1 branch
BranchTrueFalseTotal
unless @args 42 34 76
92 34 ▶ croak 'authority() accepts at most one value' unless @args == 1;
Branch: 1 branch
BranchTrueFalseTotal
unless @args == 1 0 34 34
93  
94 34 $self->_assert_initial_mutable;
95 31 ▶ if (!defined $args[0]) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args[0]) 1 30 31
96 1 $self->{authority} = undef;
97 1 return $self;
98 }
99  
100 30 my $authority = Uniform::HTTP::Message::_byte_string(
101 'authority', $args[0],
102 );
103 30 ▶ croak 'authority must not be empty' unless length $authority;
Branch: 1 branch
BranchTrueFalseTotal
unless length $authority 1 29 30
104 29 ▶ croak 'authority contains a prohibited delimiter or control byte'
Branch: 1 branch
BranchTrueFalseTotal
if $authority =~ m[[\x00-\x20\x7f/?#]] 3 26 29
105 if $authority =~ /[\x00-\x20\x7f\/?#]/;
106 26 $self->{authority} = $authority;
107 26 return $self;
108 }
109  
110 154 ▶sub protocol {
Subroutine protocol: called CC=5 SCAR=16.1
Pod documented
111 154 my ($self, @args) = @_;
112 154 ▶ return $self->{protocol} unless @args;
Branch: 1 branch
BranchTrueFalseTotal
unless @args 68 86 154
113 86 ▶ croak 'protocol() accepts at most one value' unless @args == 1;
Branch: 1 branch
BranchTrueFalseTotal
unless @args == 1 1 85 86
114  
115 85 $self->_assert_initial_mutable;
116 81 ▶ if (!defined $args[0]) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args[0]) 18 63 81
117 18 $self->{protocol} = undef;
118 18 return $self;
119 }
120  
121 63 my $protocol = Uniform::HTTP::Message::_byte_string('protocol', $args[0]);
122 59 ▶ croak 'protocol must be an HTTP token'
Branch: 1 branch
BranchTrueFalseTotal
unless $protocol =~ /\A[!\#\$%&'*+\-.\^_`|~0-9A-Za-z]+\z/ 20 39 59
123 unless $protocol =~ /\A[!\#\$%&'*+\-.\^_`|~0-9A-Za-z]+\z/;
124 39 $self->{protocol} = $protocol;
125 39 return $self;
126 }
127  
128 39 ▶sub target_is_exact {
Subroutine target_is_exact: called CC=2 SCAR=7.1
Pod documented
129 39 my ($self, @args) = @_;
130 39 ▶ croak 'target_is_exact() does not accept arguments' if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 39 39
131 39 return 1;
132 }
133  
134 8 1;
135  
136 __END__
« HTTP/Auth/Basic.pm ↑ Summary HTTP/Response.pm »