Server/BlobResult.pm

filter: Statementstmt 100% 47 / 47 Branchbran 95.4% 21 / 22 Conditioncond 77.7% 7 / 9 MC/DCmcdc 60.0% 3 / 5 Subroutinesub 100% 9 / 9 Podpod 100% 2 / 2 totaltotal 94.6% 89 / 94 CC 16 SCAR 18.7
CC
16
Cov
96%
_validate_body
11.0
BUILD
5.0
BUILDARGS
2.0
CRAP 6.5
« Server/Error.pm ↑ Summary Server/Response.pm »
1 package Net::Blossom::Server::BlobResult;
2  
3 2 ▶use strictures 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 2 ▶use Net::Blossom::BlobDescriptor;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Net::Blossom::_ConstructorArgs ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Class::Tiny qw(descriptor body);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 13 ▶sub BUILDARGS {
Subroutine BUILDARGS: called CC=2 SCAR=6.9
Pod documented
13 13 my $class = shift;
14 13 my %args = Net::Blossom::_ConstructorArgs::normalize(@_);
15 13 my %known = map { $_ => 1 } qw(descriptor body);
16 13 my @unknown = grep { !exists $known{$_} } keys %args;
17 13 ▶ croak "unknown argument(s): " . join(', ', sort @unknown) if @unknown;
Branch: 1 branch
BranchTrueFalseTotal
if @unknown 1 12 13
18  
19 12 return \%args;
20 }
21  
22 12 ▶sub BUILD {
Subroutine BUILD: called CC=5 SCAR=16.1
Pod documented
23 12 my ($self) = @_;
24 12 ▶ croak "descriptor is required" unless defined $self->descriptor;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->descriptor 1 11 12
25 11 ▶ croak "descriptor must be a Net::Blossom::BlobDescriptor"
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($self->descriptor) and $self->descriptor->isa("Net::Blossom::BlobDescriptor") 1 10 11
Condition66%2/3
builtin::blessed($self->descriptor) and $self->descriptor->isa("Net::Blossom::BlobDescriptor")
!ll&&!rl&&r
1010
MC/DC50%1/2
builtin::blessed($self->descriptor) and $self->descriptor->isa("Net::Blossom::BlobDescriptor")
builtin::blessed($self->descriptor) $self->descriptor->isa("Net::Blossom::BlobDescriptor")
Truth table66%2/3
A and B
A= builtin::blessed($self->descriptor)B= $self->descriptor->isa("Net::Blossom::BlobDescriptor")
ABresult
0X0
100
111
26 unless blessed($self->descriptor) && $self->descriptor->isa('Net::Blossom::BlobDescriptor');
27  
28 10 ▶ croak "body is required" unless defined $self->body;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->body 1 9 10
29 9 _validate_body($self->descriptor, $self->body);
30  
31 4 return;
32 }
33  
34 9 ▶sub _validate_body {
Subroutine _validate_body: called CC=11 SCAR=24.0
35 9 my ($descriptor, $body) = @_;
36  
37 9 ▶ if (!ref($body)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $body) 3 6 9
38 3 ▶ croak "body length must match descriptor size" unless length($body) == $descriptor->size;
Branch: 1 branch
BranchTrueFalseTotal
unless length $body == $descriptor->size 1 2 3
39 2 return;
40 }
41  
42 6 ▶ if (ref($body) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $body eq "ARRAY") 3 3 6
43 3 my $size = 0;
44 3 for my $chunk (@$body) {
45 4 ▶ croak "body array values must be defined" unless defined $chunk;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $chunk 0 4 4
46 4 ▶ croak "body array values must be scalars" if ref($chunk);
Branch: 1 branch
BranchTrueFalseTotal
if ref $chunk 1 3 4
47 3 $size += length $chunk;
48 }
49 2 ▶ croak "body length must match descriptor size" unless $size == $descriptor->size;
Branch: 1 branch
BranchTrueFalseTotal
unless $size == $descriptor->size 1 1 2
50 1 return;
51 }
52  
53 3 ▶ return if blessed($body) && ($body->can('read') || $body->can('getline'));
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($body) and $body->can("read") || $body->can("getline") 1 2 3
Condition83%5/6
builtin::blessed($body) and $body->can("read") || $body->can("getline")
!ll&&!rl&&r
111
$body->can("read") or $body->can("getline")
l!l&&r!l&&!r
101
MC/DC66%2/3
builtin::blessed($body) and $body->can("read") || $body->can("getline")
builtin::blessed($body) $body->can("read") $body->can("getline")
Truth table75%3/4
A and B or C
A= builtin::blessed($body)B= $body->can("read")C= $body->can("getline")
ABCresult
0XX0
1000
11X1
1011
54 2 croak "body must be a scalar, array reference, or stream object";
55 }
56  
57 2 1;
58  
59 =pod
60  
61 =head1 NAME
62  
63 Net::Blossom::Server::BlobResult - Result of a Blossom blob lookup
64  
65 =head1 SYNOPSIS
66  
67 use Net::Blossom::Server::BlobResult;
68  
69 my $result = Net::Blossom::Server::BlobResult->new(
70 descriptor => $blob,
71 body => $bytes,
72 );
73  
74 =head1 DESCRIPTION
75  
76 C<Net::Blossom::Server::BlobResult> describes a blob available for download. It
77 keeps the descriptor and response body together so server routing can return the
78 blob bytes with headers derived from the descriptor.
79  
80 =head1 CONSTRUCTOR
81  
82 =head2 new
83  
84 my $result = Net::Blossom::Server::BlobResult->new(%args);
85  
86 Required arguments:
87  
88 =over 4
89  
90 =item * C<descriptor>
91  
92 A C<Net::Blossom::BlobDescriptor> for the blob.
93  
94 =item * C<body>
95  
96 The blob body as a scalar, an array reference of scalar chunks, or a stream
97 object that provides C<read> or C<getline>. Scalar and array bodies must have a
98 total byte length equal to C<< $descriptor->size >>. Stream bodies are not read
99 or buffered by this object.
100  
101 =back
102  
103 Unknown arguments or invalid values croak.
104  
105 =head1 ACCESSORS
106  
107 =head2 descriptor
108  
109 Returns the C<Net::Blossom::BlobDescriptor>.
110  
111 =head2 body
112  
113 Returns the scalar, array reference, or stream object body.
114  
115 =head1 INTERNAL METHODS
116  
117 =head2 BUILDARGS
118  
119 Normalizes constructor arguments for Class::Tiny.
120  
121 =head2 BUILD
122  
123 Validates the constructed object for Class::Tiny.
124  
125 =cut
« Server/Error.pm ↑ Summary Server/Response.pm »