Last active
December 15, 2015 11:09
-
-
Save hisaichi5518/5251060 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; | |
| package Parent { | |
| use Mouse; | |
| no Mouse; | |
| my $added; | |
| sub BUILD { | |
| my ($self) = @_; | |
| if (!$added->{$self->meta->name}) { | |
| $self->meta->add_around_method_modifier(as_string => sub { | |
| my $orig = shift; | |
| my $result = $orig->(@_); | |
| return 'extended_'.$result; | |
| }); | |
| $added->{$self->meta->name}++; | |
| } | |
| } | |
| sub as_string { | |
| return "parent"; | |
| } | |
| say Parent->new->as_string; #=> extended_parent | |
| } | |
| package Child { | |
| use Mouse; | |
| extends 'Parent'; | |
| no Mouse; | |
| sub as_string { | |
| return 'child'; | |
| } | |
| say Child->new->as_string; #=> extended_child | |
| say Child->new->as_string; #=> extended_child | |
| say Child->new->as_string; #=> extended_child | |
| say Child->new->as_string; #=> extended_child | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment