| 1 | package Test::Smoke::Patcher; | ||||||||||||||||||||||||||||
| 2 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 3 | our $VERSION = '0.012'; | |||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use base 'Exporter'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use File::Spec; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use Cwd; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use Test::Smoke::Util qw( get_regen_headers ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 3 | our @EXPORT = qw( &TRY_REGEN_HEADERS ); | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | sub MAX_FLAG_COUNT () { 16 } | ||||||||||||||||||||||||||||
| 15 | sub ALL_FLAGS () { (2**MAX_FLAG_COUNT) - 1 } | ||||||||||||||||||||||||||||
| 16 | sub TRY_REGEN_HEADERS () { 1 } | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 3 | my %CONFIG = ( | |||||||||||||||||||||||||||
| 19 | df_ddir => File::Spec->rel2abs( cwd ), | ||||||||||||||||||||||||||||
| 20 | df_fdir => undef, | ||||||||||||||||||||||||||||
| 21 | df_pfile => undef, | ||||||||||||||||||||||||||||
| 22 | df_patchbin => 'patch', | ||||||||||||||||||||||||||||
| 23 | df_popts => '', # '-p1' is added in call_patch() | ||||||||||||||||||||||||||||
| 24 | df_flags => 0, | ||||||||||||||||||||||||||||
| 25 | df_regen => 1, # regen => set/unset TRY_REGEN_HEADERS in flags | ||||||||||||||||||||||||||||
| 26 | df_oldpatch => 0, | ||||||||||||||||||||||||||||
| 27 | df_v => 0, | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | valid_type => { single => 1, multi => 1 }, | ||||||||||||||||||||||||||||
| 30 | single => [qw( pfile patchbin popts flags regen oldpatch )], | ||||||||||||||||||||||||||||
| 31 | multi => [qw( pfile patchbin popts flags regen oldpatch )], | ||||||||||||||||||||||||||||
| 32 | ); | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | =head1 NAME | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | Test::Smoke::Patcher - OO interface to help patching the source-tree | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | use Test::Smoke::Patcher; | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | my $patcher = Test::Smoke::Patcher->new( single => { | ||||||||||||||||||||||||||||
| 43 | ddir => $build_dir, | ||||||||||||||||||||||||||||
| 44 | pfile => $patch, | ||||||||||||||||||||||||||||
| 45 | popts => '-p1', | ||||||||||||||||||||||||||||
| 46 | v => 1, # 0..2 | ||||||||||||||||||||||||||||
| 47 | }); | ||||||||||||||||||||||||||||
| 48 | $patcher->patch; | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | or | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | my $patcher = Test::Smoke::Patcher->new( multi => { | ||||||||||||||||||||||||||||
| 53 | ddir => $buildir, | ||||||||||||||||||||||||||||
| 54 | pfile => $patch_info, | ||||||||||||||||||||||||||||
| 55 | v => 1, #0..2 | ||||||||||||||||||||||||||||
| 56 | }); | ||||||||||||||||||||||||||||
| 57 | $patcher->patch; | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | Okay, you will need a working B<patch> program, which I believe is available | ||||||||||||||||||||||||||||
| 62 | for most platforms perl runs on. | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | There are two ways to initialise the B<Test::Smoke::Patcher> object. | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | =over 4 | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | =item B<single> mode | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | The B<pfile> attribute is a pointer to a I<single> patch. | ||||||||||||||||||||||||||||
| 71 | There are four (4) ways to specify that patch. | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | =over 4 | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | =item I<refernece to a SCALAR> | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | The scalar holds the complete patch as literal text. | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | =item I<reference to an ARRAY> | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | The array holds a list of lines (with newlines) that make up the | ||||||||||||||||||||||||||||
| 82 | patch as literal text (C<< $patch = join "", @$array_ref >>). | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | =item I<reference to a GLOB> | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | You passed an opened filehandle to a file containing the patch. | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | =item I<filename> | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | If none of the above apply, it is assumed you passed a filename. | ||||||||||||||||||||||||||||
| 91 | Relative paths are rooted at the builddir (B<ddir> attribute). | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | =back | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | =item B<multi> mode | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | The B<pfile> attribute is a pointer to a recource that contains filenames | ||||||||||||||||||||||||||||
| 98 | of patches. | ||||||||||||||||||||||||||||
| 99 | The format of this recource is one filename per line optionally followed | ||||||||||||||||||||||||||||
| 100 | by a semi-colon (;) and switches for the patch program. | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | The patch-resource can also be specified in four (4) ways. | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | =over 4 | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | =item I<reference to a SCALAR> | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | =item I<reference to an ARRAY> | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | =item I<reference to a GLOB> | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | =item I<filename> | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | =back | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | =back | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | =head2 TRY_REGEN_HEADERS | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | Constant: 1 | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | =head2 MAX_FLAG_COUNT | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | Constant: 16 | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | =head2 ALL_FLAGS | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | Constant: 2**MAX_FLAG_COUNT) - 1 | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | =head1 METHODS | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | =over 4 | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | =cut | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | =item Test::Smoke::Patcher->new( $type => \%args ); | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | C<new()> crates the object. Valid types are B<single> and B<multi>. | ||||||||||||||||||||||||||||
| 139 | Valid keys for C<%args>: | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | * ddir: the build directory | ||||||||||||||||||||||||||||
| 142 | * fdir: the intermediate forest dir (preferred) | ||||||||||||||||||||||||||||
| 143 | * pfile: path to either the patch (single) or a textfile (multi) | ||||||||||||||||||||||||||||
| 144 | * popts: options to pass to 'patch' (-p1) | ||||||||||||||||||||||||||||
| 145 | * patchbin: full path to the patch binary (patch) | ||||||||||||||||||||||||||||
| 146 | * regen: flag to set/unset the TRY_REGEN_HEADERS flag | ||||||||||||||||||||||||||||
| 147 | * v: verbosity 0..2 | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | =cut | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | 3 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=10 SCAR=26.6
Pod
documented
| |||||||||||||||||||||||||||||
| 152 | 3 | my $proto = shift; | |||||||||||||||||||||||||||
| 153 | 3 | ▶ | my $class = ref $proto || $proto; | ||||||||||||||||||||||||||
|
Condition33%1/3
ref $proto || $proto
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | 3 | my $type = lc shift; | |||||||||||||||||||||||||||
| 156 | 3 | ▶ | unless ( $type && exists $CONFIG{valid_type}->{ $type } ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$type and exists $CONFIG{"valid_type"}{$type}
MC/DC0%0/2
$type and exists $CONFIG{"valid_type"}{$type}
$type
exists $CONFIG{"valid_type"}{$type}
Truth table33%1/3
A and B
A= $typeB= exists $CONFIG{"valid_type"}{$type}
| |||||||||||||||||||||||||||||
| 157 | 0 | ▶ | defined $type or $type = 'undef'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 158 | 0 | require Carp; | |||||||||||||||||||||||||||
| 159 | 0 | Carp::croak( "Invalid Patcher-type: '$type'" ); | |||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | 3 | ▶ | my %args_raw = @_ ? UNIVERSAL::isa( $_[0], 'HASH' ) ? %{ $_[0] } : @_ : (); | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | my %args = map { | ||||||||||||||||||||||||||||
| 165 | 3 | ( my $key = $_ ) =~ s/^-?(.+)$/lc $1/e; | |||||||||||||||||||||||||||
| 166 | 6 | ( $key => $args_raw{ $_ } ); | |||||||||||||||||||||||||||
| 167 | } keys %args_raw; | ||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | my %fields = map { | ||||||||||||||||||||||||||||
| 170 | 27 | ▶ | my $value = exists $args{$_} ? $args{ $_ } : $CONFIG{ "df_$_" }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 171 | 27 | ( $_ => $value ) | |||||||||||||||||||||||||||
| 172 | 3 | } ( v => ddir => fdir => @{ $CONFIG{ $type } } ); | |||||||||||||||||||||||||||
| 173 | $fields{pdir} = File::Spec->rel2abs( | ||||||||||||||||||||||||||||
| 174 | defined $fields{fdir} ? $fields{fdir} : $fields{ddir} | ||||||||||||||||||||||||||||
| 175 | 3 | ▶ | ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 176 | 3 | $fields{ptype} = $type; | |||||||||||||||||||||||||||
| 177 | 3 | ▶ | if ($fields{regen}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 178 | 3 | $fields{flags} = ($fields{flags} | TRY_REGEN_HEADERS) & ALL_FLAGS; | |||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||
| 180 | else { | ||||||||||||||||||||||||||||
| 181 | 0 | $fields{flags} = ($fields{flags} & ~TRY_REGEN_HEADERS) & ALL_FLAGS; | |||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | 3 | bless { %fields }, $class; | |||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | =item Test::Smoke::Patcher->config( $key[, $value] ) | ||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | C<config()> is an interface to the package lexical C<%CONFIG>, | ||||||||||||||||||||||||||||
| 190 | which holds all the default values for the C<new()> arguments. | ||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | With the special key B<all_defaults> this returns a reference | ||||||||||||||||||||||||||||
| 193 | to a hash holding all the default values. | ||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | =cut | ||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | 2 | ▶ | sub config { | ||||||||||||||||||||||||||
|
Subroutine
config: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 198 | 2 | my $dummy = shift; | |||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||
| 200 | 2 | my $key = lc shift; | |||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||
| 202 | 2 | ▶ | if ( $key eq 'all_defaults' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 203 | my %default = map { | ||||||||||||||||||||||||||||
| 204 | 1 | my( $pass_key ) = $_ =~ /^df_(.+)/; | |||||||||||||||||||||||||||
| 205 | 9 | ( $pass_key => $CONFIG{ $_ } ); | |||||||||||||||||||||||||||
| 206 | } grep /^df_/ => keys %CONFIG; | ||||||||||||||||||||||||||||
| 207 | 1 | return \%default; | |||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | 1 | ▶ | return undef unless exists $CONFIG{ "df_$key" }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | 1 | ▶ | $CONFIG{ "df_$key" } = shift if @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | 1 | return $CONFIG{ "df_$key" }; | |||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||
| 217 | =item $patcher->patch | ||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||
| 219 | C<patch()> is a simple dispatcher. | ||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||
| 221 | =cut | ||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||
| 223 | 1 | ▶ | sub patch { | ||||||||||||||||||||||||||
|
Subroutine
patch: called CC=3 SCAR=13.6
Pod
documented
| |||||||||||||||||||||||||||||
| 224 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||
| 226 | 1 | my $method = "patch_$self->{ptype}"; | |||||||||||||||||||||||||||
| 227 | 1 | my $ret = $self->$method( @_ ); | |||||||||||||||||||||||||||
| 228 | 1 | ▶ | $ret &&= $self->perl_regen_headers; | ||||||||||||||||||||||||||
|
Condition33%1/3
$ret &&= $self->perl_regen_headers
MC/DC0%0/2
$ret &&= $self->perl_regen_headers
$ret
$self->perl_regen_headers
Truth table33%1/3
A &&= B
A= $retB= $self->perl_regen_headers
| |||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||
| 230 | 1 | ▶ | if ( $self->{fdir} ) { # This is a forest setup, re-sync | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 231 | 0 | require Test::Smoke::Syncer; | |||||||||||||||||||||||||||
| 232 | my %options = ( | ||||||||||||||||||||||||||||
| 233 | hdir => $self->{fdir}, | ||||||||||||||||||||||||||||
| 234 | ddir => $self->{ddir}, | ||||||||||||||||||||||||||||
| 235 | v => $self->{v}, | ||||||||||||||||||||||||||||
| 236 | 0 | ); | |||||||||||||||||||||||||||
| 237 | 0 | my $resync = Test::Smoke::Syncer->new( hardlink => %options ); | |||||||||||||||||||||||||||
| 238 | 0 | $resync->sync; | |||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||
| 240 | 1 | return $ret; | |||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||
| 243 | =item perl_regen_headers( ) | ||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||
| 245 | Try to run F<regen_headers.pl> if the flag is set. | ||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||
| 247 | =cut | ||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||
| 249 | 1 | ▶ | sub perl_regen_headers { | ||||||||||||||||||||||||||
|
Subroutine
perl_regen_headers: called CC=10 SCAR=28.6
Pod
documented
| |||||||||||||||||||||||||||||
| 250 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 251 | 1 | ▶ | return 1 unless $self->{flags} & TRY_REGEN_HEADERS; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||
| 253 | 1 | my $regen_headers = get_regen_headers( $self->{pdir} ); | |||||||||||||||||||||||||||
| 254 | my $regen_perly = $self->{perly} | ||||||||||||||||||||||||||||
| 255 | 1 | ▶ | ? qq|$^X "| . File::Spec->catfile( $self->{pdir}, 'regen_perly.pl' ). | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 256 | qq|"| | ||||||||||||||||||||||||||||
| 257 | : ""; | ||||||||||||||||||||||||||||
| 258 | 1 | my @regens = grep $_ => ( $regen_headers, $regen_perly ); | |||||||||||||||||||||||||||
| 259 | 1 | for my $regen ( @regens ) { | |||||||||||||||||||||||||||
| 260 | 2 | my $cwd = cwd; | |||||||||||||||||||||||||||
| 261 | 2 | ▶ | chdir $self->{pdir} or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 262 | 2 | local *RUN_REGEN; | |||||||||||||||||||||||||||
| 263 | 2 | ▶ | if ( open RUN_REGEN, "$regen |" ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 264 | 2 | ▶ | $self->{v} and print "Started [$regen]\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 265 | 2 | ▶ | while ( <RUN_REGEN> ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 266 | 0 | ▶ | $self->{v} and print; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 267 | } | ||||||||||||||||||||||||||||
| 268 | 2 | ▶ | close RUN_REGEN or do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 269 | 0 | require Carp; | |||||||||||||||||||||||||||
| 270 | 0 | Carp::carp( "Error while running [$regen]" ); | |||||||||||||||||||||||||||
| 271 | 0 | return; | |||||||||||||||||||||||||||
| 272 | }; | ||||||||||||||||||||||||||||
| 273 | } else { | ||||||||||||||||||||||||||||
| 274 | 0 | require Carp; | |||||||||||||||||||||||||||
| 275 | 0 | Carp::carp( "Could not fork [$regen]" ); | |||||||||||||||||||||||||||
| 276 | 0 | return; | |||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||
| 278 | 2 | chdir $cwd; | |||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||
| 280 | 1 | return 1; | |||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||
| 283 | =item $patcher->patch_single( ) | ||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||
| 285 | C<patch_single()> checks if the B<pfile> attribute is a plain scalar | ||||||||||||||||||||||||||||
| 286 | or a ref to a scalar, array, glob. In the first case this is taken to | ||||||||||||||||||||||||||||
| 287 | be a filename. A GLOB-ref is a filehandle, the other two are taken to | ||||||||||||||||||||||||||||
| 288 | be literal content. | ||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||
| 290 | =cut | ||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||
| 292 | 0 | ▶ | sub patch_single { | ||||||||||||||||||||||||||
|
Subroutine
patch_single: not called CC=11 SCAR=48.8
Pod
documented
| |||||||||||||||||||||||||||||
| 293 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||
| 295 | 0 | ▶ | my $pfile = shift || $self->{pfile}; | ||||||||||||||||||||||||||
|
Condition0%0/3
shift() || $self->{'pfile'}
MC/DC0%0/2
shift() || $self->{'pfile'}
shift()
$self->{'pfile'}
Truth table0%0/3
A || B
A= shift()B= $self->{'pfile'}
| |||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||
| 297 | 0 | local *PATCH; | |||||||||||||||||||||||||||
| 298 | 0 | my $content; | |||||||||||||||||||||||||||
| 299 | 0 | ▶ | if ( ref $pfile eq 'SCALAR' ) { | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 300 | 0 | $content = $$pfile; | |||||||||||||||||||||||||||
| 301 | 0 | ▶ | $self->{pfinfo} ||= 'internal content'; | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->{"pfinfo"} ||= "internal content"
MC/DC0%0/1
$self->{"pfinfo"} ||= "internal content"
$self->{"pfinfo"}
Truth table0%0/2
A
A= $self->{"pfinfo"}
| |||||||||||||||||||||||||||||
| 302 | } elsif ( ref $pfile eq 'ARRAY' ) { | ||||||||||||||||||||||||||||
| 303 | 0 | $content = join "", @$pfile; | |||||||||||||||||||||||||||
| 304 | 0 | ▶ | $self->{pfinfo} ||= 'internal content'; | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->{"pfinfo"} ||= "internal content"
MC/DC0%0/1
$self->{"pfinfo"} ||= "internal content"
$self->{"pfinfo"}
Truth table0%0/2
A
A= $self->{"pfinfo"}
| |||||||||||||||||||||||||||||
| 305 | } elsif ( ref $pfile eq 'GLOB' ) { | ||||||||||||||||||||||||||||
| 306 | 0 | *PATCH = *$pfile; | |||||||||||||||||||||||||||
| 307 | 0 | $content = do { local $/; <PATCH> }; | |||||||||||||||||||||||||||
| 308 | 0 | ▶ | $self->{pfinfo} ||= 'file content'; | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->{"pfinfo"} ||= "file content"
MC/DC0%0/1
$self->{"pfinfo"} ||= "file content"
$self->{"pfinfo"}
Truth table0%0/2
A
A= $self->{"pfinfo"}
| |||||||||||||||||||||||||||||
| 309 | } else { | ||||||||||||||||||||||||||||
| 310 | my $full_name = File::Spec->file_name_is_absolute( $pfile ) | ||||||||||||||||||||||||||||
| 311 | 0 | ▶ | ? $pfile : File::Spec->rel2abs( $pfile, $self->{pdir} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||
| 313 | 0 | $self->{pfinfo} = $full_name; | |||||||||||||||||||||||||||
| 314 | 0 | ▶ | open PATCH, "< $full_name" or do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 315 | 0 | require Carp; | |||||||||||||||||||||||||||
| 316 | 0 | Carp::croak( "Cannot open '$full_name': $!" ); | |||||||||||||||||||||||||||
| 317 | }; | ||||||||||||||||||||||||||||
| 318 | 0 | $content = do { local $/; <PATCH> }; | |||||||||||||||||||||||||||
| 319 | 0 | close PATCH; | |||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||
| 322 | 0 | ▶ | $self->{v} and print "Get patch from $self->{pfinfo}\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 323 | 0 | $self->call_patch( \$content, @_ ); | |||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||
| 326 | =item $patcher->patch_multi( ) | ||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||
| 328 | C<patch_multi()> checks the B<pfile> attribute is a plain scalar | ||||||||||||||||||||||||||||
| 329 | or a ref to a scalar, array, glob. In the first case this is taken to | ||||||||||||||||||||||||||||
| 330 | be a filename. A GLOB-ref is a filehandle, the other two are taken to | ||||||||||||||||||||||||||||
| 331 | be literal content. | ||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||
| 333 | =cut | ||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||
| 335 | 1 | ▶ | sub patch_multi { | ||||||||||||||||||||||||||
|
Subroutine
patch_multi: called CC=17 SCAR=41.8
Pod
documented
| |||||||||||||||||||||||||||||
| 336 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||
| 338 | 1 | ▶ | my $pfile = shift || $self->{pfile}; | ||||||||||||||||||||||||||
|
Condition33%1/3
shift() || $self->{'pfile'}
MC/DC0%0/2
shift() || $self->{'pfile'}
shift()
$self->{'pfile'}
Truth table33%1/3
A || B
A= shift()B= $self->{'pfile'}
| |||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||
| 340 | 1 | local *PATCHES; | |||||||||||||||||||||||||||
| 341 | 1 | my @patches; | |||||||||||||||||||||||||||
| 342 | 1 | ▶ | if ( ref $pfile eq 'SCALAR' ) { | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 343 | 0 | @patches = split /\n/, $$pfile; | |||||||||||||||||||||||||||
| 344 | 0 | ▶ | $self->{pfinfo} ||= 'internal content'; | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->{"pfinfo"} ||= "internal content"
MC/DC0%0/1
$self->{"pfinfo"} ||= "internal content"
$self->{"pfinfo"}
Truth table0%0/2
A
A= $self->{"pfinfo"}
| |||||||||||||||||||||||||||||
| 345 | } elsif ( ref $pfile eq 'ARRAY' ) { | ||||||||||||||||||||||||||||
| 346 | 0 | chomp( @patches = @$pfile ); | |||||||||||||||||||||||||||
| 347 | 0 | ▶ | $self->{pfinfo} ||= 'internal content'; | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->{"pfinfo"} ||= "internal content"
MC/DC0%0/1
$self->{"pfinfo"} ||= "internal content"
$self->{"pfinfo"}
Truth table0%0/2
A
A= $self->{"pfinfo"}
| |||||||||||||||||||||||||||||
| 348 | } elsif ( ref $pfile eq 'GLOB' ) { | ||||||||||||||||||||||||||||
| 349 | 0 | *PATCHES = *$pfile; | |||||||||||||||||||||||||||
| 350 | 0 | chomp( @patches = <PATCHES> ); | |||||||||||||||||||||||||||
| 351 | 0 | ▶ | $self->{pfinfo} ||= 'file content'; | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->{"pfinfo"} ||= "file content"
MC/DC0%0/1
$self->{"pfinfo"} ||= "file content"
$self->{"pfinfo"}
Truth table0%0/2
A
A= $self->{"pfinfo"}
| |||||||||||||||||||||||||||||
| 352 | } else { | ||||||||||||||||||||||||||||
| 353 | my $full_name = File::Spec->file_name_is_absolute( $pfile ) | ||||||||||||||||||||||||||||
| 354 | 1 | ▶ | ? $pfile : File::Spec->rel2abs( $pfile, $self->{pdir} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 355 | 1 | $self->{pfinfo} = $full_name; | |||||||||||||||||||||||||||
| 356 | 1 | ▶ | open PATCHES, "< $full_name" or do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 357 | 0 | require Carp; | |||||||||||||||||||||||||||
| 358 | 0 | Carp::croak( "Cannot open '$self->{pfile}': $!" ); | |||||||||||||||||||||||||||
| 359 | }; | ||||||||||||||||||||||||||||
| 360 | 1 | chomp( @patches = <PATCHES> ); | |||||||||||||||||||||||||||
| 361 | 1 | close PATCHES; | |||||||||||||||||||||||||||
| 362 | } | ||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||
| 364 | 1 | ▶ | $self->{v} and print "Get patchinfo from $self->{pfinfo}\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||
| 366 | 1 | my $ok = 1; | |||||||||||||||||||||||||||
| 367 | 1 | foreach my $patch ( @patches ) { | |||||||||||||||||||||||||||
| 368 | 2 | ▶ | next if $patch =~ /^\s*[#]/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 369 | 1 | ▶ | next if $patch =~ /^\s*$/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 370 | 1 | ▶ | if ( $patch =~ /^\s*!\s*perly$/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 371 | 1 | $self->{perly} = 1; | |||||||||||||||||||||||||||
| 372 | 1 | next; | |||||||||||||||||||||||||||
| 373 | } | ||||||||||||||||||||||||||||
| 374 | 0 | my( $filename, $switches, $descr ) = split /\s*;\s*/, $patch, 3; | |||||||||||||||||||||||||||
| 375 | 0 | ▶ | $descr = $descr ? $descr . " ($filename)" : $filename; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 376 | 0 | eval { $self->patch_single( $filename, $switches, $descr ) }; | |||||||||||||||||||||||||||
| 377 | 0 | ▶ | if ( $@ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 378 | 0 | require Carp; | |||||||||||||||||||||||||||
| 379 | 0 | Carp::carp( "[$filename] $@" ); | |||||||||||||||||||||||||||
| 380 | 0 | $ok = 0; | |||||||||||||||||||||||||||
| 381 | } | ||||||||||||||||||||||||||||
| 382 | } | ||||||||||||||||||||||||||||
| 383 | 1 | return $ok; | |||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||
| 386 | =item $self->_make_opts( $switches ) | ||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||
| 388 | C<_make_opts()> just creates a string of options to pass to the | ||||||||||||||||||||||||||||
| 389 | B<patch> program. Some implementations of patch do not grog '-u', | ||||||||||||||||||||||||||||
| 390 | so be careful! | ||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||
| 392 | =cut | ||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||
| 394 | 1 | ▶ | sub _make_opts { | ||||||||||||||||||||||||||
|
Subroutine
_make_opts: called CC=7 SCAR=22.7
| |||||||||||||||||||||||||||||
| 395 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 396 | 1 | @_ = grep defined $_ => @_; | |||||||||||||||||||||||||||
| 397 | 1 | ▶ | my $switches = @_ ? join " ", @_ : ""; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||
| 399 | 1 | ▶ | my $opts = $switches || $self->{popts} || ""; | ||||||||||||||||||||||||||
|
Condition40%2/5
$switches || $self->{'popts'} || ''
$switches or $self->{"popts"}
MC/DC0%0/2
$switches || $self->{'popts'} || ''
$switches
$self->{"popts"}
Truth table33%1/3
A or B
A= $switchesB= $self->{"popts"}
| |||||||||||||||||||||||||||||
| 400 | 1 | ▶ | $opts .= " -p1" unless $opts =~ /-[a-zA-Z]*p\d/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 401 | # $opts .= " -b" unless $opts =~ /-[a-zA-Z]*b/i; | ||||||||||||||||||||||||||||
| 402 | 1 | ▶ | $opts .= " --verbose" if $self->{v} > 1 && !$self->{oldpatch}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{"v"} > 1 and not $self->{"oldpatch"}
MC/DC0%0/2
$self->{"v"} > 1 and not $self->{"oldpatch"}
$self->{"v"} > 1
not $self->{"oldpatch"}
Truth table33%1/3
A and not(B)
A= $self->{"v"} > 1B= not $self->{"oldpatch"}
| |||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||
| 404 | 1 | return $opts; | |||||||||||||||||||||||||||
| 405 | } | ||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||
| 407 | =item $patcher->call_patch( $ref_to_content ) | ||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||
| 409 | C<call_patch()> opens a pipe to the B<patch> program and prints | ||||||||||||||||||||||||||||
| 410 | C<< $$ref_to_content >> to it. It will Carp::croak() on any error! | ||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||
| 412 | =cut | ||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||
| 414 | 0 | ▶ | sub call_patch { | ||||||||||||||||||||||||||
|
Subroutine
call_patch: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||
| 415 | 0 | my( $self, $ref_to_content, $switches, $descr ) = @_; | |||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||
| 417 | 0 | local *PATCHBIN; | |||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||
| 419 | 0 | my $opts = $self->_make_opts( $switches ); | |||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||
| 421 | 0 | ▶ | my $redir = $self->{v} ? "" : ">" . File::Spec->devnull . " 2>&1"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||
| 423 | 0 | my $cwd = cwd(); | |||||||||||||||||||||||||||
| 424 | 0 | ▶ | chdir $self->{pdir} or do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 425 | 0 | require Carp; | |||||||||||||||||||||||||||
| 426 | 0 | Carp::croak( "Cannot chdir($self->{pdir}): $!" ); | |||||||||||||||||||||||||||
| 427 | }; | ||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||
| 429 | # patch is verbose enough if $self->{v} == 1 | ||||||||||||||||||||||||||||
| 430 | 0 | ▶ | $self->{v} > 1 and | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 431 | print "[$self->{pfinfo}] | $self->{patchbin} $opts $redir\n"; | ||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||
| 433 | 0 | ▶ | if ( open PATCHBIN, "| $self->{patchbin} $opts $redir" ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 434 | 0 | binmode PATCHBIN; | |||||||||||||||||||||||||||
| 435 | 0 | print PATCHBIN $$ref_to_content; | |||||||||||||||||||||||||||
| 436 | 0 | ▶ | close PATCHBIN or do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 437 | 0 | require Carp; | |||||||||||||||||||||||||||
| 438 | 0 | Carp::croak( "Error while patching from '$self->{pfinfo}': $!" ); | |||||||||||||||||||||||||||
| 439 | }; | ||||||||||||||||||||||||||||
| 440 | } else { | ||||||||||||||||||||||||||||
| 441 | 0 | require Carp; | |||||||||||||||||||||||||||
| 442 | 0 | Carp::croak( "Cannot fork ($self->{patchbin}): $!" ); | |||||||||||||||||||||||||||
| 443 | } | ||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||
| 445 | # Add a line to patchlevel.h if $descr | ||||||||||||||||||||||||||||
| 446 | 0 | ▶ | if ( defined $descr ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 447 | 0 | require Test::Smoke::Util; | |||||||||||||||||||||||||||
| 448 | 0 | Test::Smoke::Util::set_local_patch( $self->{pdir}, $descr ); | |||||||||||||||||||||||||||
| 449 | } | ||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||
| 451 | 0 | ▶ | chdir $cwd or do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 452 | 0 | require Carp; | |||||||||||||||||||||||||||
| 453 | 0 | Carp::croak( "Cannot chdir($cwd) back: $!" ); | |||||||||||||||||||||||||||
| 454 | }; | ||||||||||||||||||||||||||||
| 455 | } | ||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||
| 457 | =back | ||||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||
| 459 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||
| 461 | L<patch>, L<Test::Smoke::Syncer::Snapshot> | ||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||
| 463 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||
| 465 | (c) 2002-2003, All rights reserved. | ||||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||
| 467 | * Abe Timmerman <abeltje@cpan.org> | ||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||
| 469 | This library is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||
| 470 | it under the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||
| 472 | See: | ||||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||
| 474 | =over 4 | ||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||
| 476 | =item * http://www.perl.com/perl/misc/Artistic.html | ||||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||
| 478 | =item * http://www.gnu.org/copyleft/gpl.html | ||||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||
| 480 | =back | ||||||||||||||||||||||||||||
| 481 | |||||||||||||||||||||||||||||
| 482 | This program is distributed in the hope that it will be useful, | ||||||||||||||||||||||||||||
| 483 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||||||||||||||||||||||||
| 484 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||||||||||||||||||||||||||||
| 485 | |||||||||||||||||||||||||||||
| 486 | =cut | ||||||||||||||||||||||||||||