line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Docker::Image; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
149682
|
use strict; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
105
|
|
4
|
3
|
|
|
3
|
|
15
|
use warnings; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
85
|
|
5
|
|
|
|
|
|
|
|
6
|
3
|
|
|
3
|
|
2215
|
use Time::HiRes 'sleep'; |
|
3
|
|
|
|
|
4061
|
|
|
3
|
|
|
|
|
18
|
|
7
|
3
|
|
|
3
|
|
9184
|
use Data::Util ':check'; |
|
3
|
|
|
|
|
3860
|
|
|
3
|
|
|
|
|
732
|
|
8
|
3
|
|
|
3
|
|
1940
|
use Class::Load qw/try_load_class/; |
|
3
|
|
|
|
|
88036
|
|
|
3
|
|
|
|
|
290
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
use Class::Accessor::Lite ( |
11
|
3
|
|
|
|
|
26
|
ro => [qw/tag container_ports container_id/], |
12
|
3
|
|
|
3
|
|
3334
|
); |
|
3
|
|
|
|
|
4164
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $VERSION = "0.04"; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub new { |
17
|
6
|
|
|
6
|
1
|
9596
|
my $class = shift; |
18
|
6
|
50
|
|
|
|
47
|
my %args = @_ == 1 ? %{$_[0]} : @_; |
|
0
|
|
|
|
|
0
|
|
19
|
|
|
|
|
|
|
|
20
|
6
|
|
100
|
|
|
46
|
my $boot_class = delete $args{boot} || 'Test::Docker::Image::Boot'; |
21
|
|
|
|
|
|
|
|
22
|
6
|
100
|
|
|
|
32
|
try_load_class( $boot_class ) or die "failed to load $boot_class"; |
23
|
|
|
|
|
|
|
|
24
|
5
|
|
|
|
|
394
|
my $image_tag = delete $args{tag}; |
25
|
5
|
100
|
|
|
|
40
|
die "tag argument is required" unless $image_tag; |
26
|
|
|
|
|
|
|
|
27
|
4
|
100
|
|
|
|
68
|
die "container_ports argument must be ArrayRef" |
28
|
|
|
|
|
|
|
unless is_array_ref $args{container_ports}; |
29
|
|
|
|
|
|
|
|
30
|
2
|
|
|
|
|
23
|
my @ports = map { ('-p', $_) } @{ $args{container_ports} }; |
|
3
|
|
|
|
|
11
|
|
|
2
|
|
|
|
|
7
|
|
31
|
|
|
|
|
|
|
|
32
|
2
|
|
|
|
|
14
|
my $boot = $boot_class->new; |
33
|
2
|
|
|
|
|
11
|
my $container_id = $boot->docker_run(\@ports, $image_tag); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# wait to launch the container |
36
|
2
|
|
50
|
|
|
1009667
|
sleep $args{sleep_sec} || 0.5; |
37
|
|
|
|
|
|
|
|
38
|
2
|
|
|
|
|
55
|
my $self = bless { |
39
|
|
|
|
|
|
|
tag => $image_tag, |
40
|
|
|
|
|
|
|
container_ports => $args{container_ports}, |
41
|
|
|
|
|
|
|
container_id => $container_id, |
42
|
|
|
|
|
|
|
boot => $boot, |
43
|
|
|
|
|
|
|
boot_class => $boot_class, |
44
|
|
|
|
|
|
|
}, $class; |
45
|
|
|
|
|
|
|
|
46
|
2
|
|
|
|
|
26
|
return $self; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub port { |
50
|
1
|
|
|
1
|
1
|
58
|
my ($self, $container_port) = @_; |
51
|
1
|
|
|
|
|
9
|
return $self->{boot}->docker_port($self->container_id, $container_port); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub host { |
55
|
0
|
|
|
0
|
1
|
0
|
$_[0]->{boot}->host; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub DESTROY { |
59
|
2
|
|
|
2
|
|
7727
|
my $self = shift; |
60
|
2
|
|
|
|
|
12
|
$self->{boot}->on_destroy( $self->container_id ); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
1; |
64
|
|
|
|
|
|
|
__END__ |