From: Paul Fenwick Date: Sat, 4 Jul 2009 06:41:39 +0000 (+1000) Subject: Merge autodie 2.05 into core. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=02b13d1d542bbe5c0b940a475065f8e25e0d6722;p=p5sagit%2Fp5-mst-13.2.git Merge autodie 2.05 into core. 2.05 Sat Jul 4 16:33:01 AUSEST 2009 * BUGFIX: format_default() in autodie::exception no longer returns a string with file and line attached. This would cause the file and line information to appear twice when format handlers would choose to fall back to the defaults. The file and line information is now always added by stringify(). (RT #47520, thanks to Michael Schwern) * BUGFIX: Exceptions thrown by 2-argument open() are more likely to specify the mode as 'for reading' when no explicit mode was given. (RT #47520, thanks to Michael Schwern) Signed-off-by: H.Merijn Brand --- diff --git a/lib/Fatal.pm b/lib/Fatal.pm index be20a2b..50ad335 100644 --- a/lib/Fatal.pm +++ b/lib/Fatal.pm @@ -39,7 +39,7 @@ use constant ERROR_58_HINTS => q{Non-subroutine %s hints for %s are not supporte use constant MIN_IPC_SYS_SIMPLE_VER => 0.12; # All the Fatal/autodie modules share the same version number. -our $VERSION = '2.04'; +our $VERSION = '2.05'; our $Debug ||= 0; @@ -99,6 +99,7 @@ my %TAGS = ( ':2.02' => [qw(:default)], ':2.03' => [qw(:default)], ':2.04' => [qw(:default)], + ':2.05' => [qw(:default)], ); $TAGS{':all'} = [ keys %TAGS ]; diff --git a/lib/autodie.pm b/lib/autodie.pm index 1f8d7e5..5cfb643 100644 --- a/lib/autodie.pm +++ b/lib/autodie.pm @@ -8,7 +8,7 @@ our @ISA = qw(Fatal); our $VERSION; BEGIN { - $VERSION = '2.04'; + $VERSION = '2.05'; } use constant ERROR_WRONG_FATAL => q{ diff --git a/lib/autodie/exception.pm b/lib/autodie/exception.pm index 5a09617..b04c82a 100644 --- a/lib/autodie/exception.pm +++ b/lib/autodie/exception.pm @@ -14,7 +14,7 @@ use overload use if ($] >= 5.010), overload => '~~' => "matches"; -our $VERSION = '2.04'; +our $VERSION = '2.05'; my $PACKAGE = __PACKAGE__; # Useful to have a scalar for hash keys. @@ -417,8 +417,20 @@ sub _format_open { [^&] # Not an ampersand (which means a dup) }x; - # Have a funny mode? Use the default format. - return $this->format_default if not defined $mode; + if (not $mode) { + # Maybe it's a 2-arg open without any mode at all? + # Detect the most simple case for this, where our + # file consists only of word characters. + + if ( $file =~ m{^\s*\w+\s*$} ) { + $mode = '<' + } + else { + # Otherwise, we've got no idea what's going on. + # Use the default. + return $this->format_default; + } + } # Localising $! means perl make make it a pretty error for us. local $! = $this->errno; @@ -517,7 +529,7 @@ sub stringify { return $sub->($this) . $this->add_file_and_line; } - return $this->format_default; + return $this->format_default . $this->add_file_and_line; } @@ -568,8 +580,7 @@ sub format_default { # Format our beautiful error. - return "Can't $call(". join(q{, }, @args) . "): $!" . - $this->add_file_and_line; + return "Can't $call(". join(q{, }, @args) . "): $!" ; # TODO - Handle user-defined errors from hash. diff --git a/lib/autodie/exception/system.pm b/lib/autodie/exception/system.pm index 59b2eaf..d5b5bad 100644 --- a/lib/autodie/exception/system.pm +++ b/lib/autodie/exception/system.pm @@ -5,7 +5,7 @@ use warnings; use base 'autodie::exception'; use Carp qw(croak); -our $VERSION = '2.04'; +our $VERSION = '2.05'; my $PACKAGE = __PACKAGE__; diff --git a/lib/autodie/hints.pm b/lib/autodie/hints.pm index db22467..80952ef 100644 --- a/lib/autodie/hints.pm +++ b/lib/autodie/hints.pm @@ -5,7 +5,7 @@ use warnings; use constant PERL58 => ( $] < 5.009 ); -our $VERSION = '2.04'; +our $VERSION = '2.05'; =head1 NAME diff --git a/lib/autodie/t/open.t b/lib/autodie/t/open.t index 3a2d493..9964ba0 100755 --- a/lib/autodie/t/open.t +++ b/lib/autodie/t/open.t @@ -16,3 +16,34 @@ ok($@, "2-arg opening non-existent file fails"); like($@, qr/for reading/, "Well-formatted 2-arg open failure"); unlike($@, qr/GLOB\(0x/, "No ugly globs in 2-arg open messsage"); + +# RT 47520. 2-argument open without mode would repeat the file +# and line number. + +eval { + use autodie; + + open(my $fh, NO_SUCH_FILE); +}; + +isa_ok($@, 'autodie::exception'); +like( $@, qr/at \S+ line \d+/, "At least one mention"); +unlike($@, qr/at \S+ line \d+\s+at \S+ line \d+/, "...but not too mentions"); + +# RT 47520-ish. 2-argument open without a mode should be marked +# as 'for reading'. +like($@, qr/for reading/, "Well formatted 2-arg open without mode"); + +# We also shouldn't get repeated messages, even if the default mode +# was used. Single-arg open always falls through to the default +# formatter. + +eval { + use autodie; + + open( NO_SUCH_FILE . "" ); +}; + +isa_ok($@, 'autodie::exception'); +like( $@, qr/at \S+ line \d+/, "At least one mention"); +unlike($@, qr/at \S+ line \d+\s+at \S+ line \d+/, "...but not too mentions");