Created
April 16, 2014 13:43
-
-
Save breezhang/10877493 to your computer and use it in GitHub Desktop.
perl Hook aop attribute demo. less Mosss .............
This file contains 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 main; | |
use strict; | |
use warnings; | |
use constant DEBUG => 1; | |
use Attribute::Handlers; | |
use Data::Dumper::Concise; | |
use Hook::LexWrap; | |
sub _log : ATTR(CODE) { | |
if (DEBUG) { | |
wrap $_[1], pre => sub { print "before"; }, | |
post => sub { print "after"; }; | |
#my $name = *{$sym}{NAME};#*{$sym}{NAME}; | |
#no warnings 'redefine'; | |
#*{$sym} = sub { | |
# #log_message("Entering sub $pkg\:\:$name"); | |
# my @ret = $code->(@_); | |
# #log_message("Leaving sub $pkg\:\:$name"); | |
# return @ret; | |
}; | |
}; | |
#}; | |
sub do_something : _log("helloworld") { | |
print "I'm doing something.\n"; | |
} | |
; | |
do_something ("helloworld"); | |
sub foobar{ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment