ontoken()
void ontoken ( str token, ref handler )
- token expects a valid token string (i.e. T_ACTION_ACCEPT)
- handler expects a reference to a subroutine
Handlers are registered via ontoken()
. Typically, handlers are simply passed
a closure as ontoken()
expects a reference to the handler.
Example 1 - registering a closure as a handler
ontoken('T_ACTION_ACCEPT', sub {
# the accept token
my $token = shift;
# the position of the token in the rule
my $tpos = shift;
# do stuff here
});
Example 2 - registering a referenced handler
sub myHandler {
my $token = shift;
my $tpos = shift;
# do stuff here
}
ontoken('T_ACTION_ACCEPT', \&myHandler);