def makebold(fn):
def wrapped():
return "" + fn() + ""
return wrapped
def makeitalic(fn):
def wrapped():
return "" + fn() + ""
return wrapped
@makebold
@makeitalic
def hello():
return "hello world"
print hello() ## returns hello world
####
use strict;
use warnings;
use Data::Dumper qw'Dumper';
use Attribute::Handlers;
use feature 'say';
sub wrap {
my ($glob,$c_wrapper) = @_;
no warnings 'redefine';
*$glob = $c_wrapper;
}
sub BOLD :ATTR {
my ($pkg,$glob,$ref) = @_;
wrap $glob => sub { "" . $ref->() . "" };
}
sub ITALIC :ATTR {
my ($pkg,$glob,$ref) = @_;
wrap $glob => sub { "" . $ref->() . ""};
}
sub hello :ITALIC :BOLD {
return "hello world";
}
say hello();
__END__
hello World