Skip to content

Commit b27c3a6

Browse files
authored
patch: add paths to error messages
* Improve error messages if open() fails * INFILE was listed instead of the original file path * OUTFILE was listed instead of the path provided to -o, e.g. if I specify an invalid argument * Style: switch filehandles to my-variables * Style: add more quotes for hash keys
1 parent 725ee97 commit b27c3a6

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

bin/patch

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use constant EX_SUCCESS => 0;
2424
use constant EX_REJECTS => 1;
2525
use constant EX_FAILURE => 2;
2626

27-
my $VERSION = '0.31';
27+
my $VERSION = '0.32';
2828

2929
$|++;
3030

@@ -434,11 +434,12 @@ sub bless {
434434
}
435435

436436
# Open original file.
437-
local *IN;
438-
open IN, '<', $in or $self->skip("Couldn't open INFILE: $!\n");
439-
binmode IN;
440-
$self->{i_fh} = *IN; # input filehandle
441-
$self->{i_file} = $in; # input filename
437+
my $in_fh;
438+
open $in_fh, '<', $in
439+
or $self->skip("Cannot open input file '$in': $!\n");
440+
binmode $in_fh;
441+
$self->{'i_fh'} = $in_fh;
442+
$self->{'i_file'} = $in;
442443

443444
# Open output file.
444445
if ($self->{check}) {
@@ -448,13 +449,14 @@ sub bless {
448449
$self->{'o_file'} = '-';
449450
$self->{'d_fh'} = length $self->{'ifdef'} ? *STDOUT : File::Temp->new;
450451
} else {
451-
local *OUT;
452-
open OUT, '+>', $out or $self->skip("Couldn't open OUTFILE: $!\n");
453-
binmode OUT;
454-
$|++, select $_ for select OUT;
455-
$self->{o_fh} = *OUT;
456-
$self->{o_file} = $out;
457-
$self->{d_fh} = length $self->{ifdef} ? *OUT : File::Temp->new();
452+
my $out_fh;
453+
open $out_fh, '+>', $out
454+
or $self->skip("Cannot open output file '$out': $!\n");
455+
binmode $out_fh;
456+
$|++, select $_ for select $out_fh;
457+
$self->{'o_fh'} = $out_fh;
458+
$self->{'o_file'} = $out;
459+
$self->{'d_fh'} = length $self->{'ifdef'} ? $out_fh : File::Temp->new();
458460
}
459461

460462
$self->{'reject-file'} = "$out.rej" unless defined $self->{'reject-file'};

0 commit comments

Comments
 (0)