File Coverage

blib/lib/Boxer/Task/Bootstrap.pm
Criterion Covered Total %
statement 35 70 50.0
branch 0 14 0.0
condition 0 3 0.0
subroutine 12 14 85.7
pod 0 1 0.0
total 47 102 46.0


line stmt bran cond sub pod time code
1             package Boxer::Task::Bootstrap;
2              
3             =encoding UTF-8
4              
5             =cut
6              
7 1     1   1350 use v5.20;
  1         4  
8 1     1   6 use utf8;
  1         2  
  1         11  
9 1     1   32 use Role::Commons -all;
  1         3  
  1         8  
10 1     1   2015 use feature 'signatures';
  1         3  
  1         116  
11 1     1   8 use namespace::autoclean 0.16;
  1         21  
  1         8  
12 1     1   95 use autodie qw(:all);
  1         2  
  1         7  
13 1     1   6021 use IPC::System::Simple qw(runx);
  1         2  
  1         102  
14              
15 1     1   8 use Moo;
  1         2  
  1         5  
16 1     1   481 use MooX::StrictConstructor;
  1         2  
  1         7  
17             extends qw(Boxer::Task);
18              
19 1     1   933 use Types::Standard qw( Bool Str InstanceOf ArrayRef Maybe );
  1         3  
  1         13  
20              
21 1     1   1343 use strictures 2;
  1         7  
  1         40  
22 1     1   193 no warnings "experimental::signatures";
  1         3  
  1         701  
23              
24             =head1 VERSION
25              
26             Version v1.4.2
27              
28             =cut
29              
30             our $VERSION = "v1.4.2";
31              
32             has world => (
33             is => 'ro',
34             isa => InstanceOf ['Boxer::World'],
35             required => 1,
36             );
37              
38             has node => (
39             is => 'ro',
40             isa => Str,
41             required => 1,
42             );
43              
44             has helper => (
45             is => 'ro',
46             isa => Str,
47             required => 1,
48             );
49              
50             has mode => (
51             is => 'ro',
52             isa => Maybe [Str],
53             );
54              
55             has helper_args => (
56             is => 'ro',
57             isa => ArrayRef,
58             );
59              
60             has nonfree => (
61             is => 'ro',
62             isa => Bool,
63             required => 1,
64             default => sub {0},
65             );
66              
67             has apt => (
68             is => 'lazy',
69             isa => Bool,
70             );
71              
72             sub _build_apt ($self)
73 0     0     {
  0            
  0            
74 0           my $flag;
75 0           foreach my $helper (qw(mmdebstrap)) {
76 0 0         if ( $self->{helper} eq $helper ) {
77 0           $self->_logger->tracef(
78             'Enabling apt mode needed by bootstrap helper %s',
79             $helper,
80             );
81 0           return 1;
82             }
83             }
84 0           return 0;
85             }
86              
87             has dryrun => (
88             is => 'ro',
89             isa => Bool,
90             required => 1,
91             default => sub {0},
92             );
93              
94             sub run ($self)
95              
96 0     0 0   {
  0            
  0            
97 0           my $world = $self->world->map( $self->node, $self->nonfree, );
98 0           my @opts;
99              
100 0           my @pkgs = sort @{ $world->pkgs };
  0            
101 0           my @pkgs_avoid = sort @{ $world->pkgs_avoid };
  0            
102              
103 0 0         if ( $self->apt ) {
104 0           push @pkgs, sort map { $_ . '-' } @pkgs_avoid;
  0            
105 0           @pkgs_avoid = ();
106             }
107              
108 0 0         push @opts, '--include', join( ',', @pkgs )
109             if (@pkgs);
110 0 0         push @opts, '--exclude', join( ',', @pkgs_avoid )
111             if (@pkgs_avoid);
112 0           push @opts, $world->epoch, @{ $self->mode, $self->helper_args };
  0            
113              
114 0           my @command;
115 0 0 0       if ( $self->mode and $self->mode eq 'sudo' ) {
116 0           @command = ( 'sudo', '--', $self->helper, @opts );
117             }
118             else {
119 0           @command = ( $self->helper, @opts );
120             }
121              
122 0 0         $self->_logger->info(
123             "Bootstrap with " . $self->helper,
124             $self->_logger->is_debug() ? { commandline => [@command] } : (),
125             );
126 0 0         if ( $self->dryrun ) {
127 0           $self->_logger->debug('Skip execute command in dry-run mode');
128             }
129             else {
130 0           runx @command;
131             }
132              
133 0           1;
134             }
135              
136             =head1 AUTHOR
137              
138             Jonas Smedegaard C<< <dr@jones.dk> >>.
139              
140             =cut
141              
142             our $AUTHORITY = 'cpan:JONASS';
143              
144             =head1 COPYRIGHT AND LICENCE
145              
146             Copyright © 2019 Jonas Smedegaard
147              
148             This is free software; you can redistribute it and/or modify it under
149             the same terms as the Perl 5 programming language system itself.
150              
151             =head1 DISCLAIMER OF WARRANTIES
152              
153             THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
154             WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
155             MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
156              
157             =cut
158              
159             1;