From: Stevan Little Date: Fri, 24 Mar 2006 04:00:29 +0000 (+0000) Subject: whoot X-Git-Tag: 0_05~63 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=159da176568ed56fcdc9a03167750e7e307f9a7d;p=gitmo%2FMoose.git whoot --- diff --git a/Changes b/Changes index c4f1da8..bd068e0 100644 --- a/Changes +++ b/Changes @@ -6,6 +6,8 @@ Revision history for Perl extension Moose it now captures errors and deals with inline packages correctly (bug found by mst, solution stolen from alias) + - added super/override & inner/augment features + - added tests and docs for these * Moose::Object - BUILDALL now takes a reference of the %params diff --git a/lib/Moose.pm b/lib/Moose.pm index 58d431d..68d44dc 100644 --- a/lib/Moose.pm +++ b/lib/Moose.pm @@ -327,6 +327,32 @@ This three items are syntactic sugar for the before, after and around method modifier features that L provides. More information on these can be found in the L documentation for now. +=item B + +The keyword C is a noop when called outside of an C method. In +the context of an C method, it will call the next most appropriate +superclass method with the same arguments as the original method. + +=item B + +An C method, is a way of explictly saying "I am overriding this +method from my superclass". You can call C within this method, and +it will work as expected. The same thing I be accomplished with a normal +method call and the C pseudo-package, it is really your choice. + +=item B + +The keyword C, much like C, is a no-op outside of the context of +an C method. You can think of C as being the inverse of +C, the details of how C and C work is best described in +the L. + +=item B + +An C method, is a way of explictly saying "I am augmenting this +method from my superclass". Once again, the details of how C and +C work is best described in the L. + =item B This is the C function, and exported here beause I use it @@ -369,6 +395,12 @@ ideas/feature-requests/encouragement =item L +=item L + +This paper (suggested by lbr on #moose) was what lead to the implementation +of the C/C and C/C features. If you really +want to understand this feature, I suggest you read this. + =back =head1 BUGS diff --git a/t/012_super_and_override.t b/t/012_super_and_override.t index a58e3b9..9b5fd9c 100644 --- a/t/012_super_and_override.t +++ b/t/012_super_and_override.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 7; +use Test::More tests => 16; BEGIN { use_ok('Moose'); @@ -35,6 +35,7 @@ BEGIN { extends 'Bar'; + override bar => sub { 'Baz::bar -> ' . super() }; override baz => sub { 'Baz::baz -> ' . super() }; } @@ -44,5 +45,20 @@ isa_ok($baz, 'Bar'); isa_ok($baz, 'Foo'); is($baz->foo(), 'Foo::foo', '... got the right value from &foo'); -is($baz->bar(), 'Bar::bar -> Foo::bar', '... got the right value from &bar'); +is($baz->bar(), 'Baz::bar -> Bar::bar -> Foo::bar', '... got the right value from &bar'); is($baz->baz(), 'Baz::baz -> Foo::baz', '... got the right value from &baz'); + +my $bar = Bar->new(); +isa_ok($bar, 'Bar'); +isa_ok($bar, 'Foo'); + +is($bar->foo(), 'Foo::foo', '... got the right value from &foo'); +is($bar->bar(), 'Bar::bar -> Foo::bar', '... got the right value from &bar'); +is($bar->baz(), 'Foo::baz', '... got the right value from &baz'); + +my $foo = Foo->new(); +isa_ok($foo, 'Foo'); + +is($foo->foo(), 'Foo::foo', '... got the right value from &foo'); +is($foo->bar(), 'Foo::bar', '... got the right value from &bar'); +is($foo->baz(), 'Foo::baz', '... got the right value from &baz'); \ No newline at end of file diff --git a/t/013_inner_and_augment.t b/t/013_inner_and_augment.t index 15a73a5..c1bcaf3 100644 --- a/t/013_inner_and_augment.t +++ b/t/013_inner_and_augment.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 7; +use Test::More tests => 16; BEGIN { use_ok('Moose'); @@ -15,9 +15,9 @@ BEGIN { use warnings; use Moose; - sub foo { 'Foo::foo(' . inner() . ')' } - sub bar { 'Foo::bar(' . inner() . ')' } - sub baz { 'Foo::baz(' . inner() . ')' } + sub foo { 'Foo::foo(' . (inner() || '') . ')' } + sub bar { 'Foo::bar(' . (inner() || '') . ')' } + sub baz { 'Foo::baz(' . (inner() || '') . ')' } package Bar; use strict; @@ -26,7 +26,7 @@ BEGIN { extends 'Foo'; - augment foo => sub { 'Bar::foo(' . inner() . ')' }; + augment foo => sub { 'Bar::foo(' . (inner() || '') . ')' }; augment bar => sub { 'Bar::bar' }; package Baz; @@ -38,6 +38,10 @@ BEGIN { augment foo => sub { 'Baz::foo' }; augment baz => sub { 'Baz::baz' }; + + # this will actually never run, + # because Bar::bar does not call inner() + augment bar => sub { 'Baz::bar' }; } my $baz = Baz->new(); @@ -49,3 +53,17 @@ is($baz->foo(), 'Foo::foo(Bar::foo(Baz::foo))', '... got the right value from &f is($baz->bar(), 'Foo::bar(Bar::bar)', '... got the right value from &bar'); is($baz->baz(), 'Foo::baz(Baz::baz)', '... got the right value from &baz'); +my $bar = Bar->new(); +isa_ok($bar, 'Bar'); +isa_ok($bar, 'Foo'); + +is($bar->foo(), 'Foo::foo(Bar::foo())', '... got the right value from &foo'); +is($bar->bar(), 'Foo::bar(Bar::bar)', '... got the right value from &bar'); +is($bar->baz(), 'Foo::baz()', '... got the right value from &baz'); + +my $foo = Foo->new(); +isa_ok($foo, 'Foo'); + +is($foo->foo(), 'Foo::foo()', '... got the right value from &foo'); +is($foo->bar(), 'Foo::bar()', '... got the right value from &bar'); +is($foo->baz(), 'Foo::baz()', '... got the right value from &baz');