What do you think this code should produce?
use Test::More tests => 6;
{
class Foo;
sub new { bless {}, shift }
sub WHO { 'foo' }
}
class Bar {
sub new { bless {}, shift }
sub WHO { 'bar' }
::is( __PACKAGE__, 'Bar',
'class name block should set package name in block' );
}
is( __PACKAGE__, 'main', 'class name should not leak out of block' );
my $foo = Foo->new();
my $bar = Bar->new();
is( $foo->isa( 'Foo' ), 1, 'Foo constructor should work' );
is( $foo->WHO(), 'foo', '... in the right package' );
is( $bar->isa( 'Bar' ), 1, 'Bar constructor should work' );
is( $bar->WHO(), 'bar', '... in the right package' );
Oh, yes. This is Perl 5 code.
MooseX::Declare provides similar features. The class keyword only accepts a block with the class definition right now, but i'm also working on implementing "class Foo;" using B::Hooks::OP::Check::StashChange.
I'd be glad if we could have some basic syntax compatibility between MooseX::Declare and your class keyword patch, in case you want to add some kind of options to it so things like
"class Foo extends Bar {