Skip Menu |

This queue is for tickets about the SUPER CPAN distribution.

Report information
The Basics
Id: 21491
Status: resolved
Worked: 20 min
Priority: 0/
Queue: SUPER

People
Owner: chromatic [...] cpan.org
Requestors: jjore [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 1.14
Fixed in: (no value)



Subject: SUPER handles unusual class names poorly
The following three tests fail with the following error. Unable to create sub named "" at /home/josh/src/SUPER-1.14/blib/lib/SUPER.pm line 100. #!perl -T use Test::More tests => 3; use SUPER; use strict; no strict 'refs'; ## no critic strict use warnings FATAL => 'all'; { package Pirate; sub chumbucket { return 'Ahoy!'; } sub four_bells { return 'Belay that order!'; } sub keelhaul { return 'Rub some salt into it, ye scurvy dog.'; } } { # The ... class has a method named 'chumbucket' and inherits from # Pirate. *{'...::chumbucket'} = sub { SUPER::super; }; @{'...::ISA'} = 'Pirate'; my $obj = bless [], '...'; eval { is( $obj->chumbucket, Pirate->chumbucket, '...' ); }; if ( $@ ) { diag( $@ ); fail( 'Class ...' ); } } { *{"\n::belay"} = sub { SUPER::super; }; @{"\n::ISA"} = 'Pirate'; my $obj = bless [], "\n"; eval { is( $obj->belay, Pirate->belay ); }; if ( $@ ) { diag( $@ ); fail( 'Class \n' ); } } { *{'0::keelhaul'} = sub { SUPER::super; }; @{'0::ISA'} = 'Pirate'; my $obj = bless [], '0'; eval { is( $obj->keelhaul, Pirate->keelhaul ); }; if ( $@ ) { diag( $@ ); fail( 'Class 0' ); } }
Thanks! I ended up tweaking the tests to get this to work. First, super() only works within methods compiled within the appropriate packages. The test compiles them within the main package, so the dispatcher gets really confused. I switched to the SUPER() method call. Second, anonymous subroutines really need their own names, so I used the *__ANON__ trick. For example, I used: *{"\n::four_bells"} = sub { local *__ANON__ = 'four_bells'; $_[0]->SUPER }; I added some documentation to this effect and fixed the bug preventing the use of class names that evaluated to false but not undef. This'll be in 1.15, out very soon. -- c