Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

chromatic (983)

chromatic
  (email not shown publicly)
http://wgz.org/chromatic/

Blog Information [technorati.com] Profile for chr0matic [technorati.com]

Journal of chromatic (983)

Thursday December 11, 2008
09:55 PM

I Have a Secret Too

[ #38077 ]

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.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • I find this Perl intriguing and I would like to have it in my interpreter.
  • Do we really need perl6? :)
  • 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 { .. }" and similar would be possible.