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 10 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 10 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 10 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 10 ▶use parent 'Uniform::HTTP::Message';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 10 our $VERSION = '0.06';
9  
10 73 ▶sub new {
Subroutine new: called CC=18 SCAR=28.9
Pod documented
11 73 my ($class, @args) = @_;
12 73 my $args = Uniform::HTTP::Message::_named_args('new', @args);
13  
14 73 for my $name (keys %$args) {
15 310 ▶ 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 310 310
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
30820
$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
30532
$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
267385
$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
2283943
$name eq "method" or $name eq "target" or $name eq "scheme" or $name eq "authority" or $name eq "protocol"
l!l&&r!l&&!r
1953382
$name eq "method" or $name eq "target" or $name eq "scheme" or $name eq "authority"
l!l&&r!l&&!r
16530115
$name eq "method" or $name eq "target" or $name eq "scheme"
l!l&&r!l&&!r
14421145
$name eq "method" or $name eq "target"
l!l&&r!l&&!r
7272166
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 73 ▶ croak 'method is required' unless exists $args->{method};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $args->{"method"} 1 72 73
28 72 ▶ croak 'target is required' unless exists $args->{target};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $args->{"target"} 1 71 72
29  
30 71 my @common;
31 71 for my $name (qw(version headers trailers body)) {
32 284 ▶ push @common, $name => $args->{$name} if exists $args->{$name};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args->{$name} 82 202 284
33 }
34  
35 71 my $self = $class->SUPER::new(@common);
36 71 $self->method($args->{method});
37 70 $self->target($args->{target});
38 69 ▶ $self->scheme($args->{scheme}) if exists $args->{scheme};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args->{"scheme"} 21 48 69
39 69 ▶ $self->authority($args->{authority}) if exists $args->{authority};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args->{"authority"} 30 39 69
40 65 ▶ $self->protocol($args->{protocol}) if exists $args->{protocol};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args->{"protocol"} 33 32 65
41 53 return $self;
42 }
43  
44 82 ▶sub method {
Subroutine method: called CC=4 SCAR=13.9
Pod documented
45 82 my ($self, @args) = @_;
46 82 ▶ return $self->{method} unless @args;
Branch: 1 branch
BranchTrueFalseTotal
unless @args 5 77 82
47 77 ▶ croak 'method() accepts at most one value' unless @args == 1;
Branch: 1 branch
BranchTrueFalseTotal
unless @args == 1 0 77 77
48  
49 77 $self->_assert_initial_mutable;
50 74 my $method = Uniform::HTTP::Message::_byte_string('method', $args[0]);
51 74 ▶ croak 'method must be an HTTP token'
Branch: 1 branch
BranchTrueFalseTotal
unless $method =~ /\A[!\#\$%&'*+\-.\^_`|~0-9A-Za-z]+\z/ 2 72 74
52 unless $method =~ /\A[!\#\$%&'*+\-.\^_`|~0-9A-Za-z]+\z/;
53 72 $self->{method} = $method;
54 72 return $self;
55 }
56  
57 115 ▶sub target {
Subroutine target: called CC=5 SCAR=16.2
Pod documented
58 115 my ($self, @args) = @_;
59 115 ▶ return $self->{target} unless @args;
Branch: 1 branch
BranchTrueFalseTotal
unless @args 41 74 115
60 74 ▶ croak 'target() accepts at most one value' unless @args == 1;
Branch: 1 branch
BranchTrueFalseTotal
unless @args == 1 0 74 74
61  
62 74 $self->_assert_initial_mutable;
63 71 my $target = Uniform::HTTP::Message::_byte_string('target', $args[0]);
64 71 ▶ croak 'target must not be empty' unless length $target;
Branch: 1 branch
BranchTrueFalseTotal
unless length $target 0 71 71
65 71 ▶ croak 'target must not contain spaces or control bytes'
Branch: 1 branch
BranchTrueFalseTotal
if $target =~ /[\x00-\x20\x7f]/ 1 70 71
66 if $target =~ /[\x00-\x20\x7f]/;
67 70 $self->{target} = $target;
68 70 return $self;
69 }
70  
71 67 ▶sub scheme {
Subroutine scheme: called CC=5 SCAR=16.2
Pod documented
72 67 my ($self, @args) = @_;
73 67 ▶ return $self->{scheme} unless @args;
Branch: 1 branch
BranchTrueFalseTotal
unless @args 41 26 67
74 26 ▶ croak 'scheme() accepts at most one value' unless @args == 1;
Branch: 1 branch
BranchTrueFalseTotal
unless @args == 1 0 26 26
75  
76 26 $self->_assert_initial_mutable;
77 23 ▶ if (!defined $args[0]) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args[0]) 1 22 23
78 1 $self->{scheme} = undef;
79 1 return $self;
80 }
81  
82 22 my $scheme = Uniform::HTTP::Message::_byte_string('scheme', $args[0]);
83 22 ▶ croak 'scheme must be a valid URI scheme'
Branch: 1 branch
BranchTrueFalseTotal
unless $scheme =~ /\A[A-Za-z][A-Za-z0-9+.-]*\z/ 0 22 22
84 unless $scheme =~ /\A[A-Za-z][A-Za-z0-9+.-]*\z/;
85 22 $self->{scheme} = $scheme;
86 22 return $self;
87 }
88  
89 77 ▶sub authority {
Subroutine authority: called CC=6 SCAR=17.9
Pod documented
90 77 my ($self, @args) = @_;
91 77 ▶ return $self->{authority} unless @args;
Branch: 1 branch
BranchTrueFalseTotal
unless @args 42 35 77
92 35 ▶ croak 'authority() accepts at most one value' unless @args == 1;
Branch: 1 branch
BranchTrueFalseTotal
unless @args == 1 0 35 35
93  
94 35 $self->_assert_initial_mutable;
95 32 ▶ if (!defined $args[0]) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args[0]) 1 31 32
96 1 $self->{authority} = undef;
97 1 return $self;
98 }
99  
100 31 my $authority = Uniform::HTTP::Message::_byte_string(
101 'authority', $args[0],
102 );
103 31 ▶ croak 'authority must not be empty' unless length $authority;
Branch: 1 branch
BranchTrueFalseTotal
unless length $authority 1 30 31
104 30 ▶ croak 'authority contains a prohibited delimiter or control byte'
Branch: 1 branch
BranchTrueFalseTotal
if $authority =~ m[[\x00-\x20\x7f/?#]] 3 27 30
105 if $authority =~ /[\x00-\x20\x7f\/?#]/;
106 27 $self->{authority} = $authority;
107 27 return $self;
108 }
109  
110 155 ▶sub protocol {
Subroutine protocol: called CC=5 SCAR=16.1
Pod documented
111 155 my ($self, @args) = @_;
112 155 ▶ return $self->{protocol} unless @args;
Branch: 1 branch
BranchTrueFalseTotal
unless @args 68 87 155
113 87 ▶ croak 'protocol() accepts at most one value' unless @args == 1;
Branch: 1 branch
BranchTrueFalseTotal
unless @args == 1 1 86 87
114  
115 86 $self->_assert_initial_mutable;
116 82 ▶ if (!defined $args[0]) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args[0]) 18 64 82
117 18 $self->{protocol} = undef;
118 18 return $self;
119 }
120  
121 64 my $protocol = Uniform::HTTP::Message::_byte_string('protocol', $args[0]);
122 60 ▶ croak 'protocol must be an HTTP token'
Branch: 1 branch
BranchTrueFalseTotal
unless $protocol =~ /\A[!\#\$%&'*+\-.\^_`|~0-9A-Za-z]+\z/ 20 40 60
123 unless $protocol =~ /\A[!\#\$%&'*+\-.\^_`|~0-9A-Za-z]+\z/;
124 40 $self->{protocol} = $protocol;
125 40 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 10 1;
135  
136 __END__
« HTTP/Auth/Basic.pm ↑ Summary HTTP/Response.pm »