Hook::Heckle - create pre and post hooks
use Hook::Heckle; my $notify = sub { my $this = shift; printf "Model is informing observers because '%s' change\n", $this->victim and $_[0]->notify_observers( 'update' ) if $_[1]; @_; }; Hook::Heckle->new( context => 'InputField::String', victim => 'max', pre => sub { $_[0]->{aaa} = 1; }, post => $notify ); Hook::Heckle->new( context => 'InputField::String', victim => 'text', post => $notify );
Creating hooks to subroutines is issued by many other cpan modules. See
Class::Hook
Hook::Scope
Hook::WrapSub
Hook::LexWrap
Hook::PrePostCall
But this didnt kept me from writing a new one. It is a base class and can be inherited.
Any property has a method and parameter to new counterpart.
new
The method or subroutine to hook at.
Package name of the method or subroutine.
Reference to sub which will be called before execution of the victim. First argument will be the Hook::Heckel object and second the original arguments of the victim.
victim
Hook::Heckel
Reference to sub which will be called after execution of the victim. First argument will be the Hook::Heckel object and second the original arguments of the victim.
Array of the result from the victim.
None.
None by default.
Murat Uenalan, <muenalan@cpan.org>
Class::Hook, Hook::Scope, Hook::WrapSub, Hook::LexWrap, Hook::PrePostCall and Class::Maker.
To install Hook::Heckle, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Hook::Heckle
CPAN shell
perl -MCPAN -e shell install Hook::Heckle
For more information on module installation, please visit the detailed CPAN module installation guide.