| 1 | package Net::Blossom::Server::UploadResult; | ||||||||||||||||||||||||||||
| 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 created); | ||||||||||||||||||||||||||
|
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 | 8 | ▶ | sub BUILDARGS { | ||||||||||||||||||||||||||
|
Subroutine
BUILDARGS: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 13 | 8 | my $class = shift; | |||||||||||||||||||||||||||
| 14 | 8 | my %args = Net::Blossom::_ConstructorArgs::normalize(@_); | |||||||||||||||||||||||||||
| 15 | 8 | my %known = map { $_ => 1 } qw(descriptor created); | |||||||||||||||||||||||||||
| 16 | 8 | my @unknown = grep { !exists $known{$_} } keys %args; | |||||||||||||||||||||||||||
| 17 | 8 | ▶ | croak "unknown argument(s): " . join(', ', sort @unknown) if @unknown; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 7 | return \%args; | |||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 7 | ▶ | sub BUILD { | ||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||||||||||||||||||
| 23 | 7 | my ($self) = @_; | |||||||||||||||||||||||||||
| 24 | 7 | ▶ | croak "descriptor is required" unless defined $self->descriptor; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 25 | 6 | ▶ | croak "descriptor must be a Net::Blossom::BlobDescriptor" | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
builtin::blessed($self->descriptor) and $self->descriptor->isa("Net::Blossom::BlobDescriptor")
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")
| |||||||||||||||||||||||||||||
| 26 | unless blessed($self->descriptor) && $self->descriptor->isa('Net::Blossom::BlobDescriptor'); | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 5 | ▶ | croak "created is required" unless defined $self->created; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 29 | 4 | ▶ | croak "created must be a scalar" if ref($self->created); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 30 | 3 | ▶ | croak "created must be 0 or 1" unless $self->created =~ /\A[01]\z/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 31 | 2 | ▶ | $self->created($self->created ? 1 : 0); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 2 | return; | |||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 2 | 1; | |||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | =pod | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | =head1 NAME | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | Net::Blossom::Server::UploadResult - Result of a Blossom blob upload | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | use Net::Blossom::Server::UploadResult; | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | my $result = Net::Blossom::Server::UploadResult->new( | ||||||||||||||||||||||||||||
| 49 | descriptor => $blob, | ||||||||||||||||||||||||||||
| 50 | created => 1, | ||||||||||||||||||||||||||||
| 51 | ); | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | C<Net::Blossom::Server::UploadResult> describes the outcome of a successful | ||||||||||||||||||||||||||||
| 56 | upload. It keeps the blob descriptor separate from whether the blob bytes were | ||||||||||||||||||||||||||||
| 57 | newly stored. | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | Server routing can use C<created> to choose the BUD-02 response status: C<201> | ||||||||||||||||||||||||||||
| 60 | for a newly stored blob and C<200> when the blob already existed. | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | =head1 CONSTRUCTOR | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | =head2 new | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | my $result = Net::Blossom::Server::UploadResult->new(%args); | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | Required arguments: | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | =over 4 | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | =item * C<descriptor> | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | A C<Net::Blossom::BlobDescriptor> for the uploaded blob. | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | =item * C<created> | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | C<1> when the blob bytes were newly stored, or C<0> when the blob already | ||||||||||||||||||||||||||||
| 79 | existed. | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | =back | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | Unknown arguments or invalid values croak. | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | =head1 ACCESSORS | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | =head2 descriptor | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | Returns the C<Net::Blossom::BlobDescriptor>. | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | =head2 created | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | Returns C<1> for a newly stored blob and C<0> for an existing blob. | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | =head1 INTERNAL METHODS | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | =head2 BUILDARGS | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | Normalizes constructor arguments for Class::Tiny. | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | =head2 BUILD | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | Validates the constructed object for Class::Tiny. | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | =cut | ||||||||||||||||||||||||||||