r31220 - in /branches/upstream/libautodie-perl/current: Changes MANIFEST META.yml lib/Fatal.pm lib/autodie.pm lib/autodie/exception.pm lib/autodie/exception/system.pm t/basic_exceptions.t t/caller.t t/lib/Caller_helper.pm t/scope_leak.t t/user-context.t

angelabad-guest at users.alioth.debian.org angelabad-guest at users.alioth.debian.org
Sat Feb 28 14:32:53 UTC 2009


Author: angelabad-guest
Date: Sat Feb 28 14:32:46 2009
New Revision: 31220

URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=31220
Log:
[svn-upgrade] Integrating new upstream version, libautodie-perl (1.999)

Added:
    branches/upstream/libautodie-perl/current/t/caller.t   (with props)
    branches/upstream/libautodie-perl/current/t/lib/Caller_helper.pm   (with props)
    branches/upstream/libautodie-perl/current/t/user-context.t   (with props)
Modified:
    branches/upstream/libautodie-perl/current/Changes
    branches/upstream/libautodie-perl/current/MANIFEST
    branches/upstream/libautodie-perl/current/META.yml
    branches/upstream/libautodie-perl/current/lib/Fatal.pm
    branches/upstream/libautodie-perl/current/lib/autodie.pm
    branches/upstream/libautodie-perl/current/lib/autodie/exception.pm
    branches/upstream/libautodie-perl/current/lib/autodie/exception/system.pm
    branches/upstream/libautodie-perl/current/t/basic_exceptions.t
    branches/upstream/libautodie-perl/current/t/scope_leak.t

Modified: branches/upstream/libautodie-perl/current/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libautodie-perl/current/Changes?rev=31220&op=diff
==============================================================================
--- branches/upstream/libautodie-perl/current/Changes (original)
+++ branches/upstream/libautodie-perl/current/Changes Sat Feb 28 14:32:46 2009
@@ -1,4 +1,42 @@
 Revision history for autodie
+
+        * BUGFIX: Autodie now correctly propagates into string evals
+          under 5.10+.  Autodie completely fails to propagate into
+          string evals under 5.8.  No fix for 5.8 is known.
+
+        * BUGFIX: The caller() method on autodie::exception objects
+          should now always report the correct caller.  While it
+          would always get the line, file, and package correct, previously
+          it would sometimes report less-than-helpful callers like
+          '__ANON__' or '(eval)'.
+
+        * BUGFIX: autodie was treating system() as a user-sub, not
+          a built-in.  This could tigger extra (unnecessary) work
+          inside autodie, but otherwise had no user impact.
+
+        * DOCUMENTATION: The synopsis for autodie::exception::system
+          previously implied system() was made autodying by default.
+          This was not the case.  It must still be enabled with
+          use autodie qw(system).
+
+        * DOCUMENTATION: Noted the 5.8 string eval bug in
+          autodie/BUGS.
+
+        * TEST: Added test for correct caller output on
+          autodie::exception objects.  Thanks to Piers Harding
+          for spotting this bug at KiwiFoo.
+
+        * TEST: Added tests for user-defined autodying functions
+          changing behaviour depending upon context.  This was
+          reported in http://perlmonks.org/?node_id=744246 .
+
+        * TEST: Tests for autodie propagating into string eval.
+
+        * TEST: Expanded tests to ensure autodie::exception returns
+          the correct line number and caller.
+
+        * TEST: Expanded tests to ensure autodie::exception returns
+          correct information when calling subroutines in external files.
 
 1.998 Sat Jan  3 11:19:53 AUSEDT 2009
 

Modified: branches/upstream/libautodie-perl/current/MANIFEST
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libautodie-perl/current/MANIFEST?rev=31220&op=diff
==============================================================================
--- branches/upstream/libautodie-perl/current/MANIFEST (original)
+++ branches/upstream/libautodie-perl/current/MANIFEST Sat Feb 28 14:32:46 2009
@@ -23,6 +23,7 @@
 t/basic_exceptions.t
 t/binmode.t
 t/boilerplate.t
+t/caller.t
 t/context.t
 t/context_lexical.t
 t/crickey.t
@@ -44,6 +45,7 @@
 t/lib/autodie/test/au/exception.pm
 t/lib/autodie/test/badname.pm
 t/lib/autodie/test/missing.pm
+t/lib/Caller_helper.pm
 t/lib/lethal.pm
 t/lib/pujHa/ghach.pm
 t/lib/pujHa/ghach/Dotlh.pm
@@ -59,6 +61,7 @@
 t/system.t
 t/truncate.t
 t/unlink.t
+t/user-context.t
 t/usersub.t
 t/version.t
 t/version_tag.t

Modified: branches/upstream/libautodie-perl/current/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libautodie-perl/current/META.yml?rev=31220&op=diff
==============================================================================
--- branches/upstream/libautodie-perl/current/META.yml (original)
+++ branches/upstream/libautodie-perl/current/META.yml Sat Feb 28 14:32:46 2009
@@ -24,4 +24,4 @@
   bugtracker: http://rt.cpan.org/NoAuth/Bugs.html?Dist=autodie
   license: http://dev.perl.org/licenses/
   repository: http://github.com/pfenwick/autodie/tree/master
-version: 1.998
+version: 1.999

Modified: branches/upstream/libautodie-perl/current/lib/Fatal.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libautodie-perl/current/lib/Fatal.pm?rev=31220&op=diff
==============================================================================
--- branches/upstream/libautodie-perl/current/lib/Fatal.pm (original)
+++ branches/upstream/libautodie-perl/current/lib/Fatal.pm Sat Feb 28 14:32:46 2009
@@ -31,7 +31,7 @@
 use constant MIN_IPC_SYS_SIMPLE_VER => 0.12;
 
 # All the Fatal/autodie modules share the same version number.
-our $VERSION = '1.998';
+our $VERSION = '1.999';
 
 our $Debug ||= 0;
 
@@ -84,6 +84,7 @@
     ':1.996' => [qw(:default)],
     ':1.997' => [qw(:default)],
     ':1.998' => [qw(:default)],
+    ':1.999' => [qw(:default)],
 
 );
 
@@ -759,6 +760,7 @@
 
         $call = 'CORE::system';
         $name = 'system';
+        $core = 1;
 
     } elsif ($name eq 'exec') {
         # Exec doesn't have a prototype.  We don't care.  This
@@ -861,9 +863,19 @@
 
             sub$real_proto {
 
+                # If we're inside a string eval, we can end up with a
+                # whacky filename.  The following code allows autodie
+                # to propagate correctly into string evals.
+
+                my \$caller_level = 0;
+
+                while ( (caller \$caller_level)[1] =~ m{^\\(eval \\d+\\)\$} ) {
+                    \$caller_level++;
+                }
+
                 # If we're called from the correct file, then use the
                 # autodying code.
-                goto &\$code if ((caller)[1] eq \$filename);
+                goto &\$code if ((caller \$caller_level)[1] eq \$filename);
 
                 # Oh bother, we've leaked into another file.  Call the
                 # original code.  Note that \$sref may actually be a

Modified: branches/upstream/libautodie-perl/current/lib/autodie.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libautodie-perl/current/lib/autodie.pm?rev=31220&op=diff
==============================================================================
--- branches/upstream/libautodie-perl/current/lib/autodie.pm (original)
+++ branches/upstream/libautodie-perl/current/lib/autodie.pm Sat Feb 28 14:32:46 2009
@@ -8,7 +8,7 @@
 our $VERSION;
 
 BEGIN {
-    $VERSION = "1.998";
+    $VERSION = "1.999";
 }
 
 use constant ERROR_WRONG_FATAL => q{
@@ -307,6 +307,11 @@
 is used with package filehandles (eg, C<FILE>).  It's strongly recommended
 you use scalar filehandles instead.
 
+Under Perl 5.8 only, C<autodie> I<does not> propagate into string C<eval>
+statements, although it can be explicitly enabled inside a string
+C<eval>.  This bug does not affect block C<eval> statements in
+any version of Perl.
+
 When using C<autodie> or C<Fatal> with user subroutines, the
 declaration of those subroutines must appear before the first use of
 C<Fatal> or C<autodie>, or have been exported from a module.

Modified: branches/upstream/libautodie-perl/current/lib/autodie/exception.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libautodie-perl/current/lib/autodie/exception.pm?rev=31220&op=diff
==============================================================================
--- branches/upstream/libautodie-perl/current/lib/autodie/exception.pm (original)
+++ branches/upstream/libautodie-perl/current/lib/autodie/exception.pm Sat Feb 28 14:32:46 2009
@@ -14,7 +14,7 @@
 
 use if ($] >= 5.010), overload => '~~'  => "matches";
 
-our $VERSION = '1.998';
+our $VERSION = '1.999';
 
 my $PACKAGE = __PACKAGE__;  # Useful to have a scalar for hash keys.
 
@@ -628,6 +628,28 @@
 
     }
 
+    # We now have everything correct, *except* for our subroutine
+    # name.  If it's __ANON__ or (eval), then we need to keep on
+    # digging deeper into our stack to find the real name.  However we
+    # don't update our other information, since that will be correct
+    # for our current exception.
+
+    my $first_guess_subroutine = $sub;
+
+    while (defined $sub and $sub =~ /^\(eval\)$|::__ANON__$/) {
+        $depth++;
+
+        $sub = (CORE::caller($depth))[3];
+    }
+
+    # If we end up falling out the bottom of our stack, then our
+    # __ANON__ guess is the best we can get.  This includes situations
+    # where we were called from thetop level of a program.
+
+    if (not defined $sub) {
+        $sub = $first_guess_subroutine;
+    }
+
     $this->{$PACKAGE}{package} = $package;
     $this->{$PACKAGE}{file}    = $file;
     $this->{$PACKAGE}{line}    = $line;

Modified: branches/upstream/libautodie-perl/current/lib/autodie/exception/system.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libautodie-perl/current/lib/autodie/exception/system.pm?rev=31220&op=diff
==============================================================================
--- branches/upstream/libautodie-perl/current/lib/autodie/exception/system.pm (original)
+++ branches/upstream/libautodie-perl/current/lib/autodie/exception/system.pm Sat Feb 28 14:32:46 2009
@@ -5,7 +5,7 @@
 use base 'autodie::exception';
 use Carp qw(croak);
 
-our $VERSION = '1.998';
+our $VERSION = '1.999';
 
 my $PACKAGE = __PACKAGE__;
 
@@ -16,7 +16,7 @@
 =head1 SYNOPSIS
 
     eval {
-        use autodie;
+        use autodie qw(system);
 
         system($cmd, @args);
 

Modified: branches/upstream/libautodie-perl/current/t/basic_exceptions.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libautodie-perl/current/t/basic_exceptions.t?rev=31220&op=diff
==============================================================================
--- branches/upstream/libautodie-perl/current/t/basic_exceptions.t (original)
+++ branches/upstream/libautodie-perl/current/t/basic_exceptions.t Sat Feb 28 14:32:46 2009
@@ -1,13 +1,15 @@
 #!/usr/bin/perl -w
 use strict;
 
-use Test::More tests => 13;
+use Test::More tests => 17;
 
 use constant NO_SUCH_FILE => "this_file_had_better_not_exist";
 
+my $line;
+
 eval {
 	use autodie ':io';
-	open(my $fh, '<', NO_SUCH_FILE);
+	$line = __LINE__; open(my $fh, '<', NO_SUCH_FILE);
 };
 
 like($@, qr/Can't open '\w+' for reading: /, "Prety printed open msg");
@@ -21,7 +23,24 @@
 is($@->function, 'CORE::open', "Correct dying sub");
 is($@->package, __PACKAGE__, "Correct package");
 is($@->caller,__PACKAGE__."::__ANON__", "Correct caller");
+is($@->line, $line, "Correct line");
 is($@->args->[1], '<', 'Correct mode arg');
 is($@->args->[2], NO_SUCH_FILE, 'Correct filename arg');
 ok($@->matches('open'), 'Looks like an error from open');
 ok($@->matches(':io'),  'Looks like an error from :io');
+
+# Testing of caller info with a real subroutine.
+
+my $line2;
+
+sub xyzzy {
+    use autodie ':io';
+    $line2 = __LINE__; open(my $fh, '<', NO_SUCH_FILE);
+    return;
+};
+
+eval { xyzzy(); };
+
+isa_ok($@, 'autodie::exception');
+is($@->caller, __PACKAGE__."::xyzzy", "Subroutine caller test");
+is($@->line, $line2, "Subroutine line test");

Added: branches/upstream/libautodie-perl/current/t/caller.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libautodie-perl/current/t/caller.t?rev=31220&op=file
==============================================================================
--- branches/upstream/libautodie-perl/current/t/caller.t (added)
+++ branches/upstream/libautodie-perl/current/t/caller.t Sat Feb 28 14:32:46 2009
@@ -1,0 +1,34 @@
+#!/usr/bin/perl -w
+use strict;
+use warnings;
+use autodie;
+use Test::More 'no_plan';
+use FindBin qw($Bin);
+use lib "$Bin/lib";
+use Caller_helper;
+
+use constant NO_SUCH_FILE => "kiwifoo_is_so_much_fun";
+
+eval {
+    foo();
+};
+
+isa_ok($@, 'autodie::exception');
+
+is($@->caller, 'main::foo', "Caller should be main::foo");
+
+sub foo {
+    use autodie;
+    open(my $fh, '<', NO_SUCH_FILE);
+}
+
+eval {
+    Caller_helper::foo();
+};
+
+isa_ok($@, 'autodie::exception');
+
+is($@->line,     $Caller_helper::line,     "External line number check");
+is($@->file,     $INC{"Caller_helper.pm"}, "External filename check");
+is($@->package, "Caller_helper",           "External package check");
+is($@->caller,  "Caller_helper::foo",      "External subname check");

Propchange: branches/upstream/libautodie-perl/current/t/caller.t
------------------------------------------------------------------------------
    svn:keywords = Id

Added: branches/upstream/libautodie-perl/current/t/lib/Caller_helper.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libautodie-perl/current/t/lib/Caller_helper.pm?rev=31220&op=file
==============================================================================
--- branches/upstream/libautodie-perl/current/t/lib/Caller_helper.pm (added)
+++ branches/upstream/libautodie-perl/current/t/lib/Caller_helper.pm Sat Feb 28 14:32:46 2009
@@ -1,0 +1,13 @@
+package Caller_helper;
+
+our $line;
+
+sub foo {
+    use autodie;
+
+    $line = __LINE__; open(my $fh, '<', "no_such_file_here");
+
+    return;
+}
+
+1;

Propchange: branches/upstream/libautodie-perl/current/t/lib/Caller_helper.pm
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: branches/upstream/libautodie-perl/current/t/scope_leak.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libautodie-perl/current/t/scope_leak.t?rev=31220&op=diff
==============================================================================
--- branches/upstream/libautodie-perl/current/t/scope_leak.t (original)
+++ branches/upstream/libautodie-perl/current/t/scope_leak.t Sat Feb 28 14:32:46 2009
@@ -35,3 +35,44 @@
 };
 
 is($@,"","Other package open should be unaffected");
+
+# Due to odd filenames reported when doing string evals,
+# older versions of autodie would not propogate into string evals.
+
+eval q{
+    open(my $fh, '<', NO_SUCH_FILE);
+};
+
+TODO: {
+    local $TODO = "No known way of propagating into string eval in 5.8"
+        if $] < 5.010;
+
+    ok($@, "Failing-open string eval should throw an exception");
+    isa_ok($@, 'autodie::exception');
+}
+
+eval q{
+    no autodie;
+
+    open(my $fh, '<', NO_SUCH_FILE);
+};
+
+is("$@","","disabling autodie in string context should work");
+
+eval {
+    open(my $fh, '<', NO_SUCH_FILE);
+};
+
+ok($@,"...but shouldn't disable it for the calling code.");
+isa_ok($@, 'autodie::exception');
+
+eval q{
+    no autodie;
+
+    use autodie qw(open);
+
+    open(my $fh, '<', NO_SUCH_FILE);
+};
+
+ok($@,"Wacky flipping of autodie in string eval should work too!");
+isa_ok($@, 'autodie::exception');

Added: branches/upstream/libautodie-perl/current/t/user-context.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libautodie-perl/current/t/user-context.t?rev=31220&op=file
==============================================================================
--- branches/upstream/libautodie-perl/current/t/user-context.t (added)
+++ branches/upstream/libautodie-perl/current/t/user-context.t Sat Feb 28 14:32:46 2009
@@ -1,0 +1,59 @@
+#!/usr/bin/perl -w
+use strict;
+use warnings;
+use Test::More 'no_plan';
+use File::Copy;
+use constant NO_SUCH_FILE => 'this_file_had_better_not_exist';
+use constant EXCEPTION => 'autodie::exception';
+
+# http://perlmonks.org/?node_id=744246 describes a situation where
+# using autodie on user-defined functions can fail, depending upon
+# their context.  These tests attempt to detect this bug.
+
+eval {
+    use autodie qw(copy);
+    copy(NO_SUCH_FILE, 'xyzzy');
+};
+
+isa_ok($@,EXCEPTION,"Copying a non-existent file should throw an error");
+
+eval {
+    use autodie qw(copy);
+    my $x = copy(NO_SUCH_FILE, 'xyzzy');
+};
+
+isa_ok($@,EXCEPTION,"This shouldn't change with scalar context");
+
+eval {
+    use autodie qw(copy);
+    my @x = copy(NO_SUCH_FILE, 'xyzzy');
+};
+
+TODO: {
+    local $TODO = "Fixed in 'hints' branch";
+
+    isa_ok($@,EXCEPTION,"This shouldn't change with array context");
+}
+
+# For good measure, test with built-ins.
+
+eval {
+    use autodie qw(open);
+    open(my $fh, '<', 'xyzzy');
+};
+
+isa_ok($@,EXCEPTION,"Opening a non-existent file should throw an error");
+
+eval {
+    use autodie qw(open);
+    my $x = open(my $fh, '<', 'xyzzy');
+};
+
+isa_ok($@,EXCEPTION,"This shouldn't change with scalar context");
+
+eval {
+    use autodie qw(open);
+    my @x = open(my $fh, '<', 'xyzzy');
+};
+
+isa_ok($@,EXCEPTION,"This shouldn't change with array context");

Propchange: branches/upstream/libautodie-perl/current/t/user-context.t
------------------------------------------------------------------------------
    svn:keywords = Id




More information about the Pkg-perl-cvs-commits mailing list