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   3116 use v5.20;
  3         12  
8 3     3   18 use utf8;
  3         9  
  3         25  
9 3     3   96 use Role::Commons -all;
  3         10  
  3         26  
10 3     3   5981 use feature 'signatures';
  3         10  
  3         351  
11 3     3   21 use namespace::autoclean 0.16;
  3         59  
  3         19  
12 3     3   241 use autodie;
  3         8  
  3         25  
13              
14 3     3   16247 use Path::Tiny;
  3         8  
  3         238  
15 3     3   1820 use File::ShareDir qw(dist_dir);
  3         47774  
  3         165  
16 3     3   1468 use Boxer::File::WithSkeleton;
  3         10  
  3         106  
17              
18 3     3   20 use Moo;
  3         9  
  3         14  
19 3     3   1486 use MooX::StrictConstructor;
  3         6  
  3         21  
20             extends qw(Boxer::Task);
21              
22 3     3   2523 use Types::Standard qw( Bool Maybe Str Undef InstanceOf );
  3         7  
  3         72  
23 3     3   3716 use Types::Path::Tiny qw( Dir File Path );
  3         7  
  3         13  
24 3     3   1903 use Boxer::Types qw( SkelDir SerializationList );
  3         9  
  3         13  
25              
26 3     3   1379 use strictures 2;
  3         16  
  3         113  
27 3     3   521 no warnings "experimental::signatures";
  3         8  
  3         1757  
28              
29             =head1 VERSION
30              
31             Version v1.4.1
32              
33             =cut
34              
35             our $VERSION = "v1.4.1";
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 2058 {
  6         18  
  6         12  
101 6         59 my $world = $self->world->map( $self->node, $self->nonfree, );
102              
103 6 100       983 if ( grep( /^preseed$/, @{ $self->format } ) ) {
  6         82  
104 4         118 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       109 $self->_logger->info(
112             'Serializing to preseed',
113             $self->_logger->is_debug() ? {@args} : (),
114             );
115 4         2276 my $file = Boxer::File::WithSkeleton->new(@args);
116 4         355 $world->as_file($file);
117             }
118              
119 6 100       14 if ( grep( /^script$/, @{ $self->format } ) ) {
  6         115  
120 4         47 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       98 $self->_logger->info(
128             'Serializing to script',
129             $self->_logger->is_debug() ? {@args} : (),
130             );
131 4         1697 my $file = Boxer::File::WithSkeleton->new(@args);
132 4         324 $world->as_file( $file, 1 );
133             }
134              
135 6         378 1;
136             }
137              
138             =head1 AUTHOR
139              
140             Jonas Smedegaard C<< <dr@jones.dk> >>.
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;