/usr/share/perl5/Dist/Zilla/Plugin/Run/Role/Runner.pm is in libdist-zilla-plugin-run-perl 0.043-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 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 | use strict;
use warnings;
package Dist::Zilla::Plugin::Run::Role::Runner;
# vim: set ts=8 sts=4 sw=4 tw=115 et :
our $VERSION = '0.043';
use Moose::Role;
use namespace::autoclean;
use File::Spec (); # core
use Config (); # core
use Moose::Util 'find_meta';
has perlpath => (
is => 'ro',
isa => 'Str',
lazy => 1,
builder => 'current_perl_path',
);
has censor_commands => (
is => 'ro',
isa => 'Bool',
default => 0,
);
has [ qw(run run_if_trial run_no_trial run_if_release run_no_release) ] => (
is => 'ro',
isa => 'ArrayRef[Str]',
default => sub { [] },
);
has eval => (
is => 'ro',
isa => 'ArrayRef[Str]',
default => sub { [] },
);
has fatal_errors => (
is => 'ro',
isa => 'Bool',
default => 1,
);
has quiet => (
is => 'ro',
isa => 'Bool',
default => 0,
);
around dump_config => sub
{
my ($orig, $self) = @_;
my $config = $self->$orig;
$config->{+__PACKAGE__} = {
(map { $_ => $self->$_ ? 1 : 0 } qw(fatal_errors quiet)),
map {
@{ $self->$_ }
# look for user:password URIs
? ( $_ => [ map { $self->censor_commands || /\b\w+:[^@]+@\b/ ? 'REDACTED' : $_ } @{ $self->$_ } ] )
: ()
}
qw(run run_if_trial run_no_trial run_if_release run_no_release eval),
};
return $config;
};
around BUILDARGS => sub {
my ( $orig, $class, @args ) = @_;
my $built = $class->$orig(@args);
foreach my $dep (qw( notexist_fatal )) {
if ( exists $built->{$dep} ) {
warn(" !\n ! $class attribute '$dep' is deprecated and has no effect.\n !\n");
delete $built->{$dep};
}
}
return $built;
};
sub _is_trial {
my $self = shift;
# we want to avoid provoking other plugins prematurely, but also be as
# accurate as we can with this status
my $release_status_attr = find_meta($self->zilla)->find_attribute_by_name('release_status');
return ( $self->zilla->is_trial ? 1 : 0 ) if
not $release_status_attr # legacy (before Dist::Zilla 5.035)
or $release_status_attr->has_value($self->zilla);
# otherwise, only use the logic that does not require zilla->version
# before Dist::Zilla 5.035, this is what $zilla->is_trial returned
return eval { $self->zilla->_release_status_from_env =~ /\A(?:testing|unstable)\z/ } ? 1 : 0;
}
sub _call_script {
my ( $self, $params ) = @_;
foreach my $run_cmd (@{$self->run}) {
$self->_run_cmd($run_cmd, $params);
}
foreach my $run_cmd (@{$self->run_if_trial}) {
if ($self->_is_trial) {
$self->_run_cmd($run_cmd, $params);
} else {
$self->log_debug([ 'not executing, because no trial: %s', $run_cmd ]);
}
}
foreach my $run_cmd (@{$self->run_no_trial}) {
if ($self->_is_trial) {
$self->log_debug([ 'not executing, because trial: %s', $run_cmd ]);
} else {
$self->_run_cmd($run_cmd, $params);
}
}
my $is_release = defined $ENV{'DZIL_RELEASING'} && $ENV{'DZIL_RELEASING'} == 1 ? 1 : 0;
foreach my $run_cmd (@{$self->run_if_release}) {
if ($is_release) {
$self->_run_cmd($run_cmd, $params);
} else {
$self->log_debug([ 'not executing, because no release: %s', $run_cmd ]);
}
}
foreach my $run_cmd (@{$self->run_no_release}) {
if ($is_release) {
$self->log_debug([ 'not executing, because release: %s', $run_cmd ]);
} else {
$self->_run_cmd($run_cmd, $params);
}
}
if (my @code = @{ $self->eval }) {
my $code = join "\n", @code;
$self->_eval_cmd($code, $params);
}
}
sub _run_cmd {
my ( $self, $run_cmd, $params, $dry_run ) = @_;
if ($dry_run) {
$self->log_debug([ 'dry run, would run: %s', $run_cmd ]);
return;
}
return if not $run_cmd;
require IPC::Open3; # core
my $command = $self->build_formatter($params)->format($run_cmd);
$self->${ $self->quiet ? \'log_debug' : \'log' }([ 'executing: %s', $command ]);
# autoflush STDOUT so we can see command output right away
local $| = 1;
# combine STDOUT and STDERR for ease of proxying through the logger
my $pid = IPC::Open3::open3(my ($in, $out), undef, $command);
binmode $out, ':crlf' if $^O eq 'MSWin32';
chomp(my @lines = <$out>); # logger appends its own newline
$self->${ $self->quiet ? \'log_debug' : \'log' }($_) for @lines;
# zombie repellent
waitpid($pid, 0);
if (my $status = ($? >> 8)) {
if ($self->fatal_errors and $self->quiet and not $self->zilla->logger->get_debug) {
$self->log([ 'executed: %s', $command ]);
$self->log($_) for @lines;
}
$self->${ $self->fatal_errors ? \'log_fatal' : $self->quiet ? \'log_debug' : \'log'}
([ 'command exited with status %s (%s)', $status, $? ]);
}
else {
$self->log_debug('command executed successfully');
}
}
sub _eval_cmd {
my ( $self, $code, $params, $dry_run ) = @_;
if ($dry_run) {
$self->log_debug([ 'dry run, would evaluate: %s', $code ]);
return;
}
$code = $self->build_formatter($params)->format($code);
$self->${ $self->quiet ? \'log_debug' : \'log' }([ 'evaluating: %s', $code ]);
my $sub = __eval_wrapper($code);
$sub->($self);
my $error = $@;
if (defined $error and $error ne '') {
if ($self->fatal_errors and $self->quiet and not $self->zilla->logger->get_debug) {
$self->log([ 'evaluated: %s', $code]);
}
$self->${ $self->fatal_errors ? \'log_fatal' : $self->quiet ? \'log_debug' : \'log'}
([ 'evaluation died: %s', $error ]);
}
}
sub __eval_wrapper {
my $code = shift;
sub { eval $code };
}
around mvp_multivalue_args => sub {
my ($original, $self) = @_;
my @res = $self->$original();
push @res, qw( run run_no_trial run_if_trial run_if_release run_no_release eval );
@res;
};
my $path_separator = (File::Spec->catfile(qw(a b)) =~ m/^a(.+?)b$/)[0];
sub build_formatter {
my ( $self, $params ) = @_;
require String::Formatter;
String::Formatter->VERSION(0.102082);
my $codes = {
# not always available
# explicitly pass a string (not an object) [rt-72008]
a => defined $params->{archive} ? "$params->{archive}" : '',
# build dir or mint dir
d => sub {
# stringify build directory
my $dir = $params->{dir} || $self->zilla->built_in;
$dir ? "$dir" : '';
},
# distribution name
n => sub { $self->zilla->name },
# backward compatibility (don't error)
s => '',
# portability
p => $path_separator,
x => sub { $self->perlpath },
};
# available during build, not mint
unless( $params->{minting} ){
$codes->{v} = sub { $self->zilla->version };
$codes->{t} = sub { $self->_is_trial ? '-TRIAL' : '' };
}
# positional replacement of %s (backward compatible)
if( my @pos = @{ $params->{pos} || [] } ){
# where are you defined-or // operator?
$codes->{s} = sub {
my $s = shift(@pos);
$s = $s->() if ref $s eq 'CODE';
defined($s) ? $s : '';
};
}
return String::Formatter->new({ codes => $codes });
}
sub current_perl_path { $^X }
1;
|