line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::Provision::Tiny; |
2
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:GENE'; |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
# ABSTRACT: Provision computers |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
546
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
24
|
|
7
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
20
|
|
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
1009
|
use File::Which; |
|
1
|
|
|
|
|
1085
|
|
|
1
|
|
|
|
|
447
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '0.0404'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub new |
16
|
|
|
|
|
|
|
{ |
17
|
2
|
|
|
2
|
1
|
880
|
my $class = shift; |
18
|
2
|
|
|
|
|
3
|
my %args = @_; |
19
|
2
|
|
|
|
|
4
|
my $self = {}; |
20
|
2
|
|
|
|
|
2
|
bless $self, $class; |
21
|
2
|
|
|
|
|
9
|
$self->_init(%args, class => $class); |
22
|
2
|
|
|
|
|
6
|
return $self; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub _init |
26
|
|
|
|
|
|
|
{ |
27
|
2
|
|
|
2
|
|
3
|
my $self = shift; |
28
|
2
|
|
|
|
|
5
|
my %args = @_; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# Turn arguments into object attributes. |
31
|
2
|
|
50
|
|
|
13
|
$self->{$_} = $args{$_} || undef for keys %args; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# Set the system to provision. |
34
|
2
|
|
50
|
|
|
10
|
$self->{system} ||= 'osx'; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# Set the program to provision on the system. |
37
|
2
|
50
|
|
|
|
5
|
unless ($self->{program}) |
38
|
|
|
|
|
|
|
{ |
39
|
2
|
|
|
|
|
12
|
$self->{class} =~ s/App::Provision::(\w+)$/$1/; |
40
|
2
|
|
|
|
|
7
|
$self->{program} = lc $self->{class}; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub condition |
46
|
|
|
|
|
|
|
{ |
47
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
48
|
0
|
|
0
|
0
|
|
|
my $callback = shift || sub { which($self->{program}) }; |
|
0
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
my $condition = $callback->(); |
50
|
0
|
0
|
|
|
|
|
warn "$self->{program} ", ($condition ? 'is' : "isn't"), " installed\n"; |
51
|
0
|
0
|
|
|
|
|
return $condition ? 1 : 0; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub recipe |
56
|
|
|
|
|
|
|
{ |
57
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
58
|
0
|
|
|
|
|
|
my @steps = @_; |
59
|
0
|
0
|
0
|
|
|
|
$self->system_install(@steps) if $self->{force} || !$self->condition; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub system_install |
64
|
|
|
|
|
|
|
{ |
65
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
66
|
0
|
|
|
|
|
|
my @commands = @_; |
67
|
0
|
|
|
|
|
|
for my $cmd (@commands) |
68
|
|
|
|
|
|
|
{ |
69
|
|
|
|
|
|
|
#warn "CMD: @$cmd\n"; |
70
|
0
|
0
|
|
|
|
|
system(@$cmd) == 0 or warn "system @$cmd failed: $?"; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
1; |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
__END__ |