File Coverage

blib/lib/WWW/Docker/Image.pm
Criterion Covered Total %
statement 6 14 42.8
branch n/a
condition n/a
subroutine 2 6 33.3
pod 0 4 0.0
total 8 24 33.3


line stmt bran cond sub pod time code
1             package WWW::Docker::Image;
2             # ABSTRACT: Docker image entity
3              
4 10     10   64 use Moo;
  10         43  
  10         58  
5 10     10   3499 use namespace::clean;
  10         22  
  10         63  
6              
7             our $VERSION = '0.101';
8              
9             =head1 SYNOPSIS
10              
11             my $docker = WWW::Docker->new;
12             my $images = $docker->images->list;
13             my $image = $images->[0];
14              
15             say $image->Id;
16             say join ', ', @{$image->RepoTags};
17             say $image->Size;
18              
19             $image->tag(repo => 'myrepo/app', tag => 'v1');
20             $image->remove;
21              
22             =head1 DESCRIPTION
23              
24             This class represents a Docker image. Instances are returned by
25             L methods.
26              
27             =cut
28              
29             has client => (
30             is => 'ro',
31             weak_ref => 1,
32             );
33              
34             =attr client
35              
36             Reference to L client.
37              
38             =cut
39              
40             has Id => (is => 'ro');
41              
42             =attr Id
43              
44             Image ID (usually sha256:... hash).
45              
46             =cut
47              
48             has ParentId => (is => 'ro');
49             has RepoTags => (is => 'ro');
50              
51             =attr RepoTags
52              
53             ArrayRef of repository tags (e.g., C<["nginx:latest", "nginx:1.21"]>).
54              
55             =cut
56              
57             has RepoDigests => (is => 'ro');
58             has Created => (is => 'ro');
59             has Size => (is => 'ro');
60              
61             =attr Size
62              
63             Image size in bytes.
64              
65             =cut
66              
67             has SharedSize => (is => 'ro');
68             has VirtualSize => (is => 'ro');
69             has Labels => (is => 'ro');
70             has Containers => (is => 'ro');
71              
72             # Attributes from inspect response
73             has Architecture => (is => 'ro');
74             has Os => (is => 'ro');
75             has Config => (is => 'ro');
76             has RootFS => (is => 'ro');
77             has Metadata => (is => 'ro');
78              
79             sub inspect {
80 0     0 0   my ($self) = @_;
81 0           return $self->client->images->inspect($self->Id);
82             }
83              
84             =method inspect
85              
86             my $updated = $image->inspect;
87              
88             Get fresh image information.
89              
90             =cut
91              
92             sub history {
93 0     0 0   my ($self) = @_;
94 0           return $self->client->images->history($self->Id);
95             }
96              
97             =method history
98              
99             my $history = $image->history;
100              
101             Get image layer history.
102              
103             =cut
104              
105             sub tag {
106 0     0 0   my ($self, %opts) = @_;
107 0           return $self->client->images->tag($self->Id, %opts);
108             }
109              
110             =method tag
111              
112             $image->tag(repo => 'myrepo/app', tag => 'v1');
113              
114             Tag the image.
115              
116             =cut
117              
118             sub remove {
119 0     0 0   my ($self, %opts) = @_;
120 0           return $self->client->images->remove($self->Id, %opts);
121             }
122              
123             =method remove
124              
125             $image->remove(force => 1);
126              
127             Remove the image.
128              
129             =cut
130              
131             =seealso
132              
133             =over
134              
135             =item * L - Image API operations
136              
137             =item * L - Main Docker client
138              
139             =back
140              
141             =cut
142              
143             1;