NAME

Runops::Hook - Hook the runloop to a C or Perl callback

SYNOPSIS

use Runops::Hook;

Runops::Hook::set_hook(sub {
	my ( $hook, $op, $arity, @args ) = @_;
	# $hook is the hook coderef
	# $op is the B::OP object representing PL_op
	# $arity is a value describing what to expect in @args
	# @args are the arguments to the operator passed by scalar reference
});

Runops::Hook::enable();

# code from here on is traced

Runops::Hook::disable(); # tracing stops just after entersub for 'disable' itself

If you are concerned about your callback's performance you can register a C callback too.

# in MyHook.xs
bool
my_hook (pTHX) {
	/* you can play with PL_op here */

	/* returning a true value will skip the pp_addr call,
	 * letting the hook override the whole runloop */

	return 0; /* resume the loop normally */
}

MODULE = MyHook PACKAGE MyHook
BOOT:
	Runops_Hook_set_hook(my_hook);
	Runops_Hook_enable();

STATUS

This is still very much experimental and in need of usability improvements, docs, tests, etc.

It's released for amusement/embarrassment purposes only ;-)

HOOKS

The runloop has a global boolean, Runops_Hook_enabled. When unset, the runloop works like the normal Perl run loop.

When the flag is enabled and Runops_Hook_threshold is 0 (the default) then the hook will be called on every loop iteration.

If Runops_Hook_threshold is set to a non zero value then the hook will only be called when an op counter PL_op has reached the threshold.

AUTHOR

Chia-Liang Kao <clkao@clkao.org>

Yuval Kogman <nothingmuch@woobling.org>

COPYRIGHT

Copyright (c) 2008 Chia-Liang Kao, Yuval Kogman. All rights
reserved. This program is free software; you can redistribute
it and/or modify it under the same terms as Perl itself.