t/op/method.t: Add tests for subless AUTOLOAD and DESTROY
authorBrian Fraser <fraserbn@gmail.com>
Thu, 2 Feb 2012 04:10:52 +0000 (01:10 -0300)
committerFather Chrysostomos <sprout@cpan.org>
Thu, 2 Feb 2012 06:48:12 +0000 (22:48 -0800)
t/op/method.t

index 13547bc..3339dde 100644 (file)
@@ -13,7 +13,7 @@ BEGIN {
 use strict;
 no warnings 'once';
 
-plan(tests => 91);
+plan(tests => 95);
 
 @A::ISA = 'B';
 @B::ISA = 'C';
@@ -388,3 +388,19 @@ is $kalled, 1, 'calling a class method via a magic variable';
     ok eval { () = main->lbiggles(local($foo,$bar)); 1 },
       'foo->lv(local($foo,$bar)) is not called in lvalue context';
 }
+
+{
+   # AUTOLOAD and DESTROY can be declared without a leading sub,
+   # like BEGIN and friends.
+   package NoSub;
+
+   eval 'AUTOLOAD { our $AUTOLOAD; return $AUTOLOAD }';
+   ::ok( !$@, "AUTOLOAD without a leading sub is legal" );
+
+   eval "DESTROY { ::pass( q!DESTROY without a leading sub is legal and gets called! ) }";
+   {
+      ::ok( NoSub->can("AUTOLOAD"), "...and sets up an AUTOLOAD normally" );
+      ::is( eval { NoSub->bluh }, "NoSub::bluh", "...which works as expected" );
+   }
+   { bless {}, "NoSub"; }
+}