Created
March 27, 2013 02:10
-
-
Save mackee/5250996 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use warnings; | |
use utf8; | |
use 5.10.1; | |
=pod | |
=head2 やりたいこと | |
Parentを継承したオブジェクトのas_stringの返り値にprefixを付けたい | |
(おかしなことをやっているのは承知の上) | |
=head2 やってみたこと | |
親でaroundを定義してみた。 | |
結果: 継承された時点でaroundがなくなっていた | |
=cut | |
package Parent { | |
use Mouse; | |
around 'as_string' => sub { | |
my $orig = shift; | |
my $result = $orig->(@_); | |
return 'extended_'.$result; | |
}; | |
no Mouse; | |
sub as_string { | |
return "parent"; | |
} | |
say Parent->as_string; #=> extended_parent | |
} | |
package Child { | |
use Mouse; | |
extends 'Parent'; | |
no Mouse; | |
sub as_string { | |
return 'child'; | |
} | |
say Child->as_string; #=> child | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment