Skip to content

Instantly share code, notes, and snippets.

@mackee
Created March 27, 2013 02:10
Show Gist options
  • Save mackee/5250996 to your computer and use it in GitHub Desktop.
Save mackee/5250996 to your computer and use it in GitHub Desktop.
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