Skip to content

Instantly share code, notes, and snippets.

@nekoya
Created October 18, 2009 05:58
Show Gist options
  • Select an option

  • Save nekoya/212567 to your computer and use it in GitHub Desktop.

Select an option

Save nekoya/212567 to your computer and use it in GitHub Desktop.
package Person;
use Data::Util qw/:all/;
{
my $method = modify_subroutine(
get_code_ref(__PACKAGE__, 'chk'),
after => [ sub { eval "use Hoge" } ]
);
no warnings 'redefine';
install_subroutine(__PACKAGE__, 'chk' => $method);
}
sub new {
bless {}, shift;
}
sub chk {
return 'checked';
}
package main;
use strict;
use warnings;
use Test::More tests => 1;
my $pp = Person->new;
is $pp->chk, 'checked', 'done check';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment