Hook::Filter 0.02 review
DownloadHook::Filter is a runtime filtering layer on top of subroutine calls. SYNOPSIS Imagine you have a big program using a logging l
|
|
Hook::Filter is a runtime filtering layer on top of subroutine calls.
SYNOPSIS
Imagine you have a big program using a logging library that exports 3 functions called mydebug, myinfo and mywarn. Those functions generate far too much log, so you want to skip calling them except in some specific circumstances.
In your main program, write:
use Hook::Filter hook => ["mydebug","myinfo","mywarn"];
In all modules making use of the logging library, write:
use Hook::Filter;
Then create a file called ./hook_filter.rules. This file contains boolean expressions that specify when calls to the filtered subroutines should be allowed:
# allow calls to 'mydebug' only inside package 'My::Filthy:Attempt'
is_sub('mydebug') && from_pkg('My::Filthy::Attempt')
# allow all calls to 'myinfo' except from inside packages under the namespace My::Test::
is_sub('myinfo') && !from_pkg(/^My::Test/)
# allow calls to 'mywarn' from function 'do_stuff' in package 'main'
# whose third argument is a message that does not match the string 'invalid login name'
is_sub('mywarn') && from_sub('do_stuff') && from_pkg('main') && !has_arg(3,/invalid login name/)
# all other calls to 'myinfo', 'mydebug' or 'mywarn' will be skipped
SYNOPSIS, Log::Dispatch
Your program uses Log::Dispatch. You want to enable Hook::Filter on top of the methods log and log_to from Log::Dispatch everywhere at once. And you want to use the filter rules located in /etc/myconf/filter_rules.conf. Easy: in main, write:
use Hook::Filter rules => '/etc/myconf/filter_rules.conf', hook => ['Log::Dispatch::log','Log::Dispatch::log_to'];
Requirements:
Perl
Hook::Filter 0.02 keywords