Blossom/Response.pm

filter: Statementstmt 81.4% 35 / 43 Branchbran 59.0% 13 / 22 Conditioncond 66.6% 2 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 80.0% 8 / 10 Podpod 100% 3 / 3 totaltotal 73.4% 61 / 83 CC 15 SCAR 18.8
CC
15
Cov
74%
header
20.0
BUILD
6.1
_validate_required_scalar
5.3
CRAP 6.5
« Blossom/_Bech32.pm ↑ Summary Blossom/_ConstructorArgs.pm »
1 package Net::Blossom::Response;
2  
3 13 ▶use strictures 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 13 ▶use Net::Blossom::_ConstructorArgs ();
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 13 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 13 ▶use Class::Tiny qw(method url status reason), {
Subroutine BEGIN: called CC=1 SCAR=0.2
9 0 ▶ headers => sub { {} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
10 13 content => '',
11 13 };
12  
13 8 ▶sub BUILDARGS {
Subroutine BUILDARGS: called CC=2 SCAR=7.0
Pod documented
14 8 my $class = shift;
15 8 my %args = Net::Blossom::_ConstructorArgs::normalize(@_);
16 8 my %known = map { $_ => 1 } qw(method url status reason headers content);
17 8 my @unknown = grep { !exists $known{$_} } keys %args;
18 8 ▶ croak "unknown argument(s): " . join(', ', sort @unknown) if @unknown;
Branch: 1 branch
BranchTrueFalseTotal
if @unknown 0 8 8
19  
20 8 return \%args;
21 }
22  
23 8 ▶sub BUILD {
Subroutine BUILD: called CC=6 SCAR=18.0
Pod documented
24 8 my ($self) = @_;
25 8 ▶ $self->headers({}) unless defined $self->headers;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->headers 0 8 8
26 8 ▶ $self->content('') unless defined $self->content;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->content 0 8 8
27 8 _validate_required_scalar($self, $_) for qw(method url status reason);
28 4 _validate_status($self->status);
29 3 ▶ croak "headers must be a hash reference" unless ref($self->headers) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self->headers eq "HASH" 1 2 3
30 2 ▶ croak "content must be a scalar" if ref($self->content);
Branch: 1 branch
BranchTrueFalseTotal
if ref $self->content 1 1 2
31 1 return;
32 }
33  
34 0 ▶sub header {
Subroutine header: not called CC=4 SCAR=30.0
Pod documented
35 0 my ($self, $name) = @_;
36 0 ▶ return undef unless defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 0 0 0
37 0 my $wanted = lc $name;
38 0 for my $key (keys %{$self->headers}) {
39 0 ▶ return $self->headers->{$key} if lc($key) eq $wanted;
Branch: 1 branch
BranchTrueFalseTotal
if lc $key eq $wanted 0 0 0
40 }
41 0 return undef;
42 }
43  
44 26 ▶sub _validate_required_scalar {
Subroutine _validate_required_scalar: called CC=5 SCAR=16.7
45 26 my ($self, $field) = @_;
46 26 ▶ croak "$field is required" unless defined $self->$field;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->$field 4 22 26
47 22 ▶ croak "$field must be a scalar" if ref($self->$field);
Branch: 1 branch
BranchTrueFalseTotal
if ref $self->$field 0 22 22
48 22 ▶ croak "$field is required" if $field =~ /\A(?:method|url)\z/ && !length $self->$field;
Branch: 1 branch
BranchTrueFalseTotal
if $field =~ /\A(?:method|url)\z/ and not length $self->$field 0 22 22
Condition66%2/3
$field =~ /\A(?:method|url)\z/ and not length $self->$field
!ll&&!rl&&r
9130
MC/DC0%0/2
$field =~ /\A(?:method|url)\z/ and not length $self->$field
$field =~ /\A(?:method|url)\z/ not length $self->$field
Truth table66%2/3
A and not(B)
A= $field =~ /\A(?:method|url)\z/B= not length $self->$field
ABresult
0X0
100
111
49 }
50  
51 4 ▶sub _validate_status {
Subroutine _validate_status: called CC=2 SCAR=6.9
52 4 my ($status) = @_;
53 4 ▶ croak "status must be an HTTP status code"
Branch: 1 branch
BranchTrueFalseTotal
unless $status =~ /\A[1-5][0-9][0-9]\z/ 1 3 4
54 unless $status =~ /\A[1-5][0-9][0-9]\z/;
55 }
56  
57 13 1;
58  
59 =pod
60  
61 =head1 NAME
62  
63 Net::Blossom::Response - Blossom HTTP success response object
64  
65 =head1 SYNOPSIS
66  
67 my $response = $client->get_blob($sha256);
68  
69 say $response->status;
70 say $response->header('content-type');
71  
72 =head1 DESCRIPTION
73  
74 C<Net::Blossom::Response> represents a successful HTTP response returned by
75 C<Net::Blossom::Client>.
76  
77 =head1 CONSTRUCTOR
78  
79 =head2 new
80  
81 my $response = Net::Blossom::Response->new(%args);
82  
83 Required arguments are C<method>, C<url>, C<status>, and C<reason>. C<status>
84 must be a three-digit HTTP status code from C<100> through C<599>.
85  
86 Optional C<headers> defaults to an empty hash reference. Optional C<content>
87 defaults to the empty string.
88  
89 Unknown arguments or invalid values croak.
90  
91 =head1 ACCESSORS
92  
93 =head2 method
94  
95 Returns the HTTP method.
96  
97 =head2 url
98  
99 Returns the request URL.
100  
101 =head2 status
102  
103 Returns the HTTP status code.
104  
105 =head2 reason
106  
107 Returns the HTTP reason phrase.
108  
109 =head2 headers
110  
111 Returns the response headers hash reference.
112  
113 =head2 content
114  
115 Returns the response body bytes as a scalar.
116  
117 =head1 METHODS
118  
119 =head2 header
120  
121 my $value = $response->header($name);
122  
123 Returns a response header value using case-insensitive lookup. Returns C<undef>
124 when C<$name> is undefined or the header is absent.
125  
126 =head1 INTERNAL METHODS
127  
128 =head2 BUILDARGS
129  
130 Normalizes constructor arguments for Class::Tiny.
131  
132 =head2 BUILD
133  
134 Validates the constructed object for Class::Tiny.
135  
136 =cut
« Blossom/_Bech32.pm ↑ Summary Blossom/_ConstructorArgs.pm »