/usr/share/perl5/Boxer/Task/Serialize.pm is in boxer 1.1.4-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 | package Boxer::Task::Serialize;
use 5.010;
use autodie;
use strictures 1;
use utf8;
use Carp qw<croak>;
use Moo;
extends 'Boxer::Task';
use Boxer::Types qw( SkelDir Suite );
use Types::Standard qw( Bool HashRef Str Undef );
use Types::Path::Tiny qw( Dir File Path );
use Path::Tiny;
use Try::Tiny;
use Template::Tiny;
use File::ShareDir qw(dist_dir);
use Role::Commons -all;
our $AUTHORITY = 'cpan:JONASS';
our $VERSION = 'v1.1.4';
# permit callers to sloppily pass undefined hash values
sub BUILDARGS
{
my ( $class, %args ) = @_;
delete @args{ grep !defined( $args{$_} ), keys %args };
return {%args};
}
has data => (
is => 'ro',
isa => HashRef,
required => 1,
);
has skeldir => (
is => 'ro',
isa => SkelDir,
coerce => 1,
required => 1,
default => sub { Path::Tiny->new( dist_dir('Boxer') )->child('skel') },
);
has infile => (
is => 'lazy',
isa => File,
coerce => File->coercion,
required => 1,
default => sub { $_[0]->skeldir->child('preseed.cfg.in') },
);
has altinfile => (
is => 'lazy',
isa => File,
coerce => File->coercion,
required => 1,
default => sub { $_[0]->skeldir->child('script.sh.in') },
);
has outdir => (
is => 'ro',
isa => Dir,
coerce => Dir->coercion,
required => 1,
default => sub {'.'},
);
has outfile => (
is => 'lazy',
isa => Path,
coerce => Path->coercion,
required => 1,
default => sub { $_[0]->outdir->child('preseed.cfg') },
);
has altoutfile => (
is => 'lazy',
isa => Path,
coerce => Path->coercion,
required => 1,
default => sub { $_[0]->outdir->child('script.sh') },
);
has node => (
is => 'ro',
isa => Str,
required => 1,
);
has nonfree => (
is => 'ro',
isa => Bool,
required => 1,
default => sub {0},
);
has suite => (
is => 'ro',
isa => Suite,
required => 1,
coerce => 1,
default => sub {'wheezy'},
);
my $pos = 1;
my @section_order = qw(
Administration
Service
Console
Desktop
Language
Framework
Task
Hardware
);
my %section_order = map { $_ => $pos++ } @section_order;
sub run
{
my $self = shift;
( defined( $self->data->{'nodes'}{ $self->node } ) )
or croak "Undefined node \"" . $self->node . "\".";
my %params = %{ $self->data->{'nodes'}{ $self->node }{'parameters'} };
my %desc;
my @section_keys = sort {
( $section_order{$a} // 1000 ) <=> ( $section_order{$b} // 1000 )
|| $a cmp $b
} keys %{ $params{doc} };
foreach my $key (@section_keys) {
my $headline = $params{doc}{$key}{headline}[0] || $key;
if (( $params{pkg} and $params{doc}{$key}{pkg} )
or ( $self->nonfree
and $params{'pkg-nonfree'}
and $params{doc}{$key}{'pkg-nonfree'} )
)
{
push @{ $desc{pkg} }, "# $headline";
if ( $params{pkg} ) {
foreach ( @{ $params{doc}{$key}{pkg} } ) {
push @{ $desc{pkg} }, "# * $_";
}
}
if ( $self->nonfree and $params{'pkg-nonfree'} ) {
foreach ( @{ $params{doc}{$key}{'pkg-nonfree'} } ) {
push @{ $desc{pkg} }, "# * [non-free] $_";
}
}
}
if ( $params{tweak} and $params{doc}{$key}{tweak} ) {
push @{ $desc{tweak} }, "# $headline";
foreach ( @{ $params{doc}{$key}{tweak} } ) {
push @{ $desc{tweak} }, "# * $_";
}
}
}
my $pkgdesc
= defined( $desc{pkg} )
? join( "\n", @{ $desc{pkg} } )
: '';
my $tweakdesc
= defined( $desc{tweak} )
? join( "\n", @{ $desc{tweak} } )
: '';
my @pkg = try { @{ $params{pkg} } }
catch {
$self->_logger->warning('No packages resolved');
return ();
};
my @pkgauto = try { @{ $params{'pkg-auto'} } }
catch {
$self->_logger->warning('No package auto-markings resolved');
return ();
};
my @pkgavoid = try { @{ $params{'pkg-avoid'} } }
catch {
$self->_logger->warning('No package avoidance resolved');
return ();
};
my @tweak = try { @{ $params{tweak} } }
catch {
$self->_logger->warning('No tweaks resolved');
return ();
};
if ( $self->nonfree ) {
push @pkg, @{ $params{'pkg-nonfree'} if ( $params{'pkg-nonfree'} ) };
push @pkgauto, @{ $params{'pkg-nonfree-auto'} }
if ( $params{'pkg-nonfree-auto'} );
}
my $pkglist = join( ' ', sort @pkg );
$pkglist .= " \\\n ";
$pkglist .= join( ' ', sort map { $_ . '-' } @pkgavoid );
my $pkgautolist = join( ' ', sort @pkgauto );
grep {chomp} @tweak;
my $tweaklist = join( ";\\\n ", @tweak );
$self->outdir->mkpath;
my $template = Template::Tiny->new(
TRIM => 1,
);
my %vars = (
node => $self->node,
suite => $self->suite,
pkgdesc => $pkgdesc,
pkglist => $pkglist,
tweakdesc => $tweakdesc,
tweaklist => $tweaklist,
pkgautolist => $pkgautolist,
);
# TODO: drop this when fixed boxer-data is in common use
if ( $vars{tweaklist} =~ s,__PKGAUTOLIST__,$pkgautolist, ) {
$self->_logger->warning(
'Embedding __PKGAUTOLIST__ in tweaks is deprecated');
$vars{pkgautolist} = undef;
}
my %altvars = %vars;
$altvars{tweaklist} =~ s,chroot\s+/target\s+,,g;
$altvars{tweaklist} =~ s,/target/,/,g;
# TODO: maybe move below (or only $''{ part?) to reclass parser
$altvars{tweaklist} =~ s/\\\K''(?=n)|\$\K''(?=\{)//g;
my $altcontent = '';
$template->process( \$self->altinfile->slurp, \%altvars, \$altcontent );
$self->altoutfile->spew( $altcontent . "\n" );
my $content = '';
$template->process( \$self->infile->slurp, \%vars, \$content );
$self->outfile->spew( $content . "\n" );
}
1;
|