Skip to content

Instantly share code, notes, and snippets.

@sng2c
Created May 30, 2012 02:23
Show Gist options
  • Save sng2c/2832954 to your computer and use it in GitHub Desktop.
Save sng2c/2832954 to your computer and use it in GitHub Desktop.
moose monkey patch2
package Dog;
#use Any::Moose;
use Moose;
has 'name'=>(is=>'rw');
sub bark{
my $self = shift;
print $self->word() x 2;
print "\n";
}
sub word{
my $self = shift;
return $self->name()."멍";
}
package main;
my $meta = Dog->meta;
#$meta->add_override_method_modifier('word',sub{return '냐옹'});
undef(*Dog::word);
*Dog::word = sub{
my $self = shift;
return $self->name()."녕"
};
my $d = Dog->new(name=>'똥구');
$d->bark();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment