Docker/Role/Entity/Container.pm

filter: Statementstmt 100% 74 / 74 Branchbran 90.0% 9 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 26 / 26 Podpod 100% 19 / 19 totaltotal 99.2% 128 / 129 CC 5 SCAR 5.1
CC
5
Cov
99%
is_running
5.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.7
« Docker/Role/Entity/Config.pm ↑ Summary Docker/Role/Entity/Secret.pm »
1 package API::Docker::Role::Entity::Container;
2 # ABSTRACT: Container operations, on the generated container types
3 53 our $VERSION = '0.006';
4 53 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 53 with 'API::Docker::Role::Entity';
6 53 requires 'id';
7 53 ▶use API::Docker::Type::ContainerInspectResponse;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 53 ▶use API::Docker::Type::ContainerSummary;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 53 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 53 ▶use Package::Stash;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 53 ▶use Scalar::Util qw( blessed );
Subroutine BEGIN: called CC=1 SCAR=0.0
12 53 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14  
15 2 ▶sub start {
Subroutine start: called CC=1 SCAR=0.0
Pod documented
16 2 my ($self) = @_;
17 2 return $self->client->containers->start($self->id);
18 }
19  
20  
21 2 ▶sub stop {
Subroutine stop: called CC=1 SCAR=0.0
Pod documented
22 2 my ($self, %opts) = @_;
23 2 return $self->client->containers->stop($self->id, %opts);
24 }
25  
26  
27 1 ▶sub restart {
Subroutine restart: called CC=1 SCAR=0.0
Pod documented
28 1 my ($self, %opts) = @_;
29 1 return $self->client->containers->restart($self->id, %opts);
30 }
31  
32  
33 1 ▶sub kill {
Subroutine kill: called CC=1 SCAR=0.0
Pod documented
34 1 my ($self, %opts) = @_;
35 1 return $self->client->containers->kill($self->id, %opts);
36 }
37  
38  
39 1 ▶sub remove {
Subroutine remove: called CC=1 SCAR=0.0
Pod documented
40 1 my ($self, %opts) = @_;
41 1 return $self->client->containers->remove($self->id, %opts);
42 }
43  
44  
45 2 ▶sub logs {
Subroutine logs: called CC=1 SCAR=0.0
Pod documented
46 2 my ($self, %opts) = @_;
47 2 return $self->client->containers->logs($self->id, %opts);
48 }
49  
50  
51 1 ▶sub attach {
Subroutine attach: called CC=1 SCAR=0.0
Pod documented
52 1 my ($self, %opts) = @_;
53 1 return $self->client->containers->attach($self->id, %opts);
54 }
55  
56  
57 1 ▶sub inspect {
Subroutine inspect: called CC=1 SCAR=0.0
Pod documented
58 1 my ($self) = @_;
59 1 return $self->client->containers->inspect($self->id);
60 }
61  
62  
63 1 ▶sub pause {
Subroutine pause: called CC=1 SCAR=0.0
Pod documented
64 1 my ($self) = @_;
65 1 return $self->client->containers->pause($self->id);
66 }
67  
68  
69 1 ▶sub unpause {
Subroutine unpause: called CC=1 SCAR=0.0
Pod documented
70 1 my ($self) = @_;
71 1 return $self->client->containers->unpause($self->id);
72 }
73  
74  
75 1 ▶sub top {
Subroutine top: called CC=1 SCAR=0.0
Pod documented
76 1 my ($self, %opts) = @_;
77 1 return $self->client->containers->top($self->id, %opts);
78 }
79  
80  
81 1 ▶sub stats {
Subroutine stats: called CC=1 SCAR=0.0
Pod documented
82 1 my ($self, %opts) = @_;
83 1 return $self->client->containers->stats($self->id, %opts);
84 }
85  
86  
87 1 ▶sub changes {
Subroutine changes: called CC=1 SCAR=0.0
Pod documented
88 1 my ($self) = @_;
89 1 return $self->client->containers->changes($self->id);
90 }
91  
92  
93 1 ▶sub export {
Subroutine export: called CC=1 SCAR=0.0
Pod documented
94 1 my ($self) = @_;
95 1 return $self->client->containers->export($self->id);
96 }
97  
98  
99 1 ▶sub resize {
Subroutine resize: called CC=1 SCAR=0.0
Pod documented
100 1 my ($self, %opts) = @_;
101 1 return $self->client->containers->resize($self->id, %opts);
102 }
103  
104  
105 1 ▶sub get_archive {
Subroutine get_archive: called CC=1 SCAR=0.0
Pod documented
106 1 my ($self, %opts) = @_;
107 1 return $self->client->containers->get_archive($self->id, %opts);
108 }
109  
110  
111 1 ▶sub put_archive {
Subroutine put_archive: called CC=1 SCAR=0.0
Pod documented
112 1 my ($self, $tar, %opts) = @_;
113 1 return $self->client->containers->put_archive($self->id, $tar, %opts);
114 }
115  
116  
117 1 ▶sub stat_archive {
Subroutine stat_archive: called CC=1 SCAR=0.0
Pod documented
118 1 my ($self, %opts) = @_;
119 1 return $self->client->containers->stat_archive($self->id, %opts);
120 }
121  
122  
123 10 ▶sub is_running {
Subroutine is_running: called CC=5 SCAR=16.1
Pod documented
124 10 my ($self) = @_;
125 10 my $state = $self->state;
126 10 ▶ return 0 unless defined $state;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $state 2 8 10
127 # The one place the two shapes have to be told apart: `state` is the status
128 # string on a ContainerSummary and an API::Docker::Type::ContainerState on
129 # a ContainerInspectResponse.
130 8 ▶ return $state->running ? 1 : 0 if blessed $state;
Branch: 2 branches
BranchTrueFalseTotal
if builtin::blessed($state) 4 4 8
$state->running ? : 2 2 4
131 4 ▶ return lc($state) eq 'running' ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
lc $state eq 'running' ? : 3 1 4
132 }
133  
134  
135 # --- composition -----------------------------------------------------------
136 #
137 # Here rather than in API::Docker::API::Containers, which is the other
138 # candidate: loading this role is then what puts the methods on the classes,
139 # and there is no program in which an API::Docker::Type::ContainerSummary has
140 # ->start and another in which it does not, depending on which module was
141 # loaded first.
142 #
143 # The clash check is not decoration. Moo composes a role into a class the
144 # class-wins way, so a generated accessor of the same name as a method here
145 # would silently keep its place and the method would be missing -- and the
146 # generated classes are written from a specification that grows fields
147 # without asking. None of the 19 names collides today; a future one says so
148 # on the first `use`.
149 {
150 53 my @provided = Package::Stash->new(__PACKAGE__)->list_all_symbols('CODE');
151 53 for my $class (
152 'API::Docker::Type::ContainerSummary',
153 'API::Docker::Type::ContainerInspectResponse',
154 ) {
155 106 my $fields = $class->docker_attributes;
156 106 my @clash = sort grep { $fields->{$_} } @provided;
157 106 ▶ croak __PACKAGE__ . ': ' . $class . ' declares ' . join(', ', @clash)
Branch: 1 branch
BranchTrueFalseTotal
if @clash 0 106 106
158 . ' as a daemon field; the generated accessor would win over the '
159 . 'method of that name and it would be missing without a word'
160 if @clash;
161 106 Moo::Role->apply_roles_to_package($class, __PACKAGE__);
162 }
163 }
164  
165  
166 53 1;
167  
168 __END__
« Docker/Role/Entity/Config.pm ↑ Summary Docker/Role/Entity/Secret.pm »