Hook::LexWrap

DESCRIPTION

サブルーチンをレキシカルスコープでラッピング。

SYNOPSYS

use strict;
use warnings;
use Hook::LexWrap;
use Perl6::Say;

sub hello {
    say 'hello, world!';
}

say '-- wraped --';
SCOPED: {
    my $wrapped_hello = wrap 'hello',
        pre => sub { say 'good morning!'; },
        post => sub { say 'good night!'; };

    hello();
}

say;

say '-- normal --';
hello();

実行結果

$ perl hook_lexwrap.pl
-- wraped --
good morning!
hello, world!
good night!

-- normal --
hello, world!

MEMO

ドキュメントをみるともう少し凝ったこともできるよう。