Docker/Role/Using.pm

filter: Statementstmt 100% 23 / 23 Branchbran 100% 6 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod 100% 1 / 1 totaltotal 100% 35 / 35 CC 5 SCAR 11.7
CC
5
Cov
100%
using
5.0
BEGIN
1.0
BEGIN
1.0
CRAP 3.2
« Docker/API/Secrets.pm ↑ Summary Docker/API/Volumes.pm »
1 package API::Docker::Role::Using;
2 # ABSTRACT: A resource class clone that bounds a run of calls
3 52 our $VERSION = '0.006';
4 52 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 52 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
6 52 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8  
9 # The options a clone carries. Both are read by
10 # API::Docker::Role::HTTP::_request and by nothing else, which is what makes
11 # the list closeable: every other option of _request describes the one request
12 # a method is building, not a run of them.
13 52 my %CARRIED = map { $_ => 1 } qw( connect_timeout read_timeout );
14  
15 has _request_options => (
16 is => 'ro',
17 534 ▶ default => sub { {} },
Subroutine __ANON__: called CC=1 SCAR=0.0
18 52 );
19  
20 180 ▶sub using {
Subroutine using: called CC=5 SCAR=16.1
Pod documented
21 180 my ($self, @args) = @_;
22  
23 180 ▶ croak __PACKAGE__ . '->using takes its options as pairs; got an odd number '
Branch: 1 branch
BranchTrueFalseTotal
if @args % 2 1 179 180
24 . 'of arguments' if @args % 2;
25  
26 179 ▶ croak __PACKAGE__ . '->using was given nothing to carry, so the clone it '
Branch: 1 branch
BranchTrueFalseTotal
unless @args 1 178 179
27 . 'would return is the object it was called on. It carries '
28 . join(' and ', sort keys %CARRIED)
29 . '; where the pairs are computed, test for them at the call'
30 unless @args;
31  
32 178 my %opts = @args;
33 178 for my $name (sort keys %opts) {
34 croak __PACKAGE__ . '->using does not carry \'' . $name . '\'. It carries '
35 . join(' and ', sort keys %CARRIED) . '; everything else a request '
36 . 'needs is an argument of the method that builds it'
37 331 ▶ unless $CARRIED{$name};
Branch: 1 branch
BranchTrueFalseTotal
unless $CARRIED{$name} 3 328 331
38 }
39  
40 # Built from the client and the options rather than copied wholesale: the
41 # resource classes hold exactly one piece of state, the client, and passing
42 # it through the constructor is what re-weakens the reference in the clone.
43 return ref($self)->new(
44 client => $self->client,
45 175 _request_options => { %{ $self->_request_options }, %opts },
46 );
47 }
48  
49  
50  
51 52 1;
52  
53 __END__
« Docker/API/Secrets.pm ↑ Summary Docker/API/Volumes.pm »