develooper Front page | perl.perl5.porters | Postings from July 2001

[PATCH t/op/method.t] SUPER:: strangeness

Thread Previous | Thread Next
From:
Piers Cawley
Date:
July 6, 2001 02:56
Subject:
[PATCH t/op/method.t] SUPER:: strangeness
Message ID:
m2ith6xu9e.fsf@despairon.bofh.org.uk
A few patches to test the SUPER:: pseudoclass. A couple of the tests
are marked TODO, it seems that SUPER:: does its dispatch based on the
package that it was compiled in, rather than the class it was called
in.

--- t/op/method.t.bak	Fri May 25 03:11:26 2001
+++ t/op/method.t	Wed Jul  4 18:21:21 2001
@@ -9,7 +9,7 @@
     @INC = '../lib';
 }
 
-print "1..72\n";
+print "1..75\n";
 
 @A::ISA = 'B';
 @B::ISA = 'C';
@@ -21,7 +21,9 @@
 sub test {
   print "# got `$_[0]', expected `$_[1]'\nnot " unless $_[0] eq $_[1]; 
   # print "not " unless shift eq shift;
-  print "ok ", ++$cnt, "\n"
+  print "ok ", ++$cnt;
+  print " @_[2..$#_]" if @_ > 2;
+  print "\n";
 }
 
 # First, some basic checks of method-calling syntax:
@@ -231,6 +233,34 @@
 eval 'sub Foo::boogie { "yes, sir!" }';
 test( $::{"Foo::"} ? "ok" : "none", "ok");  # should exist now
 test( Foo->boogie(), "yes, sir!");
+
+# Some simpleminded tests for the SUPER:: pseudoclass. 
+# Note that, right now, SUPER:: seems to start looking in the package
+# it was compiled in, rather than in the class it was called in.
+# Which is wrong. Hence the two TODO tests.
+package Parent;
+
+sub foo { 1 };
+
+package Child;
+
+@Child::ISA = 'Parent';
+
+sub child_foo {
+    my $self = shift;
+    $self->SUPER::foo;
+}
+
+package main;
+
+sub Child::main_foo { $_[0]->SUPER::foo }
+
+*Child::late_foo = sub { $_[0]->SUPER::foo };
+
+
+test( scalar(eval {Child->child_foo}), 1 );
+test( scalar(eval {Child->main_foo}), 1, "# TODO SUPER:: non intuitive");
+test( scalar(eval {Child->late_foo}), 1, "# TODO SUPER:: non intuitive");
 
 # TODO: universal.t should test NoSuchPackage->isa()/can()
 

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About