Created
October 20, 2009 10:19
-
-
Save nekoya/214168 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
| package Person; | |
| use Data::Util qw/:all/; | |
| warn "loading Data::Util $Data::Util::VERSION"; | |
| { | |
| no warnings 'redefine'; | |
| my $before = modify_subroutine( | |
| get_code_ref(__PACKAGE__, 'before_chk'), | |
| before => [ sub { eval "use Hoge" } ] | |
| ); | |
| my $after = modify_subroutine( | |
| get_code_ref(__PACKAGE__, 'after_chk'), | |
| after => [ sub { eval "use Hoge" } ] | |
| ); | |
| my $around = modify_subroutine( | |
| get_code_ref(__PACKAGE__, 'around_chk'), | |
| around => [ sub { | |
| my $orig = shift; | |
| my $self = shift; | |
| eval "use Hoge"; | |
| $self->$orig(@_); | |
| } ] | |
| ); | |
| install_subroutine(__PACKAGE__, 'before_chk' => $before); | |
| install_subroutine(__PACKAGE__, 'after_chk' => $after); | |
| install_subroutine(__PACKAGE__, 'around_chk' => $around); | |
| } | |
| sub new { bless {}, shift } | |
| sub before_chk { 'before checked' } | |
| sub after_chk { 'after checked' } | |
| sub around_chk { 'around checked' } | |
| package main; | |
| use strict; | |
| use warnings; | |
| use Test::More tests => 4; | |
| my $pp = Person->new; | |
| is $pp->before_chk, 'before checked', 'before check done'; | |
| is $pp->after_chk, 'after checked', 'after check done'; | |
| is $pp->around_chk, 'around checked', 'around check done'; | |
| ok 1, 'all tests finished'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment