File Coverage

blib/lib/Boxer/Task/Serialize.pm
Criterion Covered Total %
statement 64 64 100.0
branch 6 8 75.0
condition n/a
subroutine 17 17 100.0
pod 0 1 0.0
total 87 90 96.6


line stmt bran cond sub pod time code
1             package Boxer::Task::Serialize;
2              
3             =encoding UTF-8
4              
5             =cut
6              
7 3     3   2566 use v5.20;
  3         10  
8 3     3   18 use utf8;
  3         6  
  3         20  
9 3     3   88 use Role::Commons -all;
  3         4  
  3         20  
10 3     3   5060 use feature 'signatures';
  3         6  
  3         291  
11 3     3   20 use namespace::autoclean 0.16;
  3         48  
  3         19  
12 3     3   190 use autodie;
  3         5  
  3         28  
13              
14 3     3   13711 use Path::Tiny;
  3         7  
  3         207  
15 3     3   1600 use File::ShareDir qw(dist_dir);
  3         32464  
  3         146  
16 3     3   1300 use Boxer::File::WithSkeleton;
  3         5  
  3         88  
17              
18 3     3   19 use Moo;
  3         4  
  3         11  
19 3     3   1171 use MooX::StrictConstructor;
  3         6  
  3         11  
20             extends qw(Boxer::Task);
21              
22 3     3   2169 use Types::Standard qw( Bool Maybe Str Undef InstanceOf );
  3         7  
  3         15  
23 3     3   3184 use Types::Path::Tiny qw( Dir File Path );
  3         6  
  3         10  
24 3     3   1639 use Boxer::Types qw( SkelDir SerializationList );
  3         7  
  3         10  
25              
26 3     3   1155 use strictures 2;
  3         17  
  3         104  
27 3     3   429 no warnings "experimental::signatures";
  3         6  
  3         1447  
28              
29             =head1 VERSION
30              
31             Version v1.4.3
32              
33             =cut
34              
35             our $VERSION = "v1.4.3";
36              
37             has world => (
38             is => 'ro',
39             isa => InstanceOf ['Boxer::World'],
40             required => 1,
41             );
42              
43             has skeldir => (
44             is => 'ro',
45             isa => Maybe [SkelDir],
46             coerce => 1,
47             );
48              
49             has infile => (
50             is => 'ro',
51             isa => File,
52             coerce => 1,
53             );
54              
55             has altinfile => (
56             is => 'ro',
57             isa => File,
58             coerce => 1,
59             );
60              
61             has outdir => (
62             is => 'ro',
63             isa => Dir,
64             coerce => 1,
65             );
66              
67             has outfile => (
68             is => 'ro',
69             isa => Path,
70             coerce => 1,
71             );
72              
73             has altoutfile => (
74             is => 'ro',
75             isa => Path,
76             coerce => 1,
77             );
78              
79             has node => (
80             is => 'ro',
81             isa => Str,
82             required => 1,
83             );
84              
85             has format => (
86             is => 'ro',
87             isa => SerializationList,
88             coerce => 1,
89             required => 1,
90             );
91              
92             has nonfree => (
93             is => 'ro',
94             isa => Bool,
95             required => 1,
96             default => sub {0},
97             );
98              
99             sub run ($self)
100 6     6 0 1675 {
  6         12  
  6         10  
101 6         59 my $world = $self->world->map( $self->node, $self->nonfree, );
102              
103 6 100       858 if ( grep( /^preseed$/, @{ $self->format } ) ) {
  6         56  
104 4         40 my @args = (
105             basename => 'preseed.cfg',
106             skeleton_dir => $self->skeldir,
107             skeleton_path => $self->infile,
108             file_dir => $self->outdir,
109             file_path => $self->outfile,
110             );
111 4 50       88 $self->_logger->info(
112             'Serializing to preseed',
113             $self->_logger->is_debug() ? {@args} : (),
114             );
115 4         1925 my $file = Boxer::File::WithSkeleton->new(@args);
116 4         290 $world->as_file($file);
117             }
118              
119 6 100       16 if ( grep( /^script$/, @{ $self->format } ) ) {
  6         52  
120 4         41 my @args = (
121             basename => 'script.sh',
122             skeleton_dir => $self->skeldir,
123             skeleton_path => $self->altinfile,
124             file_dir => $self->outdir,
125             file_path => $self->altoutfile,
126             );
127 4 50       81 $self->_logger->info(
128             'Serializing to script',
129             $self->_logger->is_debug() ? {@args} : (),
130             );
131 4         1586 my $file = Boxer::File::WithSkeleton->new(@args);
132 4         302 $world->as_file( $file, 1 );
133             }
134              
135 6         377 1;
136             }
137              
138             =head1 AUTHOR
139              
140             Jonas Smedegaard C<< >>.
141              
142             =cut
143              
144             our $AUTHORITY = 'cpan:JONASS';
145              
146             =head1 COPYRIGHT AND LICENCE
147              
148             Copyright © 2013-2016 Jonas Smedegaard
149              
150             This is free software; you can redistribute it and/or modify it under
151             the same terms as the Perl 5 programming language system itself.
152              
153             =head1 DISCLAIMER OF WARRANTIES
154              
155             THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
156             WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
157             MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
158              
159             =cut
160              
161             1;