Skip to content

Instantly share code, notes, and snippets.

@nekoya
Created October 20, 2009 08:18
Show Gist options
  • Select an option

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

Select an option

Save nekoya/214105 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'),
around => [ 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