NAME

Reflex::Callback::Method - Callback adapter for class and object methods

VERSION

version 0.071

SYNOPSIS

Used within Reflex:

package MethodHandler;
use Moose;
extends 'Reflex::Base';
use Reflex::Callbacks qw(cb_method);
use ExampleHelpers qw(eg_say);

has ticker => (
	isa     => 'Maybe[Reflex::Interval]',
	is      => 'rw',
);

sub BUILD {
	my $self = shift;
	$self->ticker(
		Reflex::Interval->new(
			interval    => 1 + rand(),
			auto_repeat => 1,
			on_tick     => cb_method($self, "callback"),
		)
	);
}

sub callback {
	eg_say("method callback triggered");
}

MethodHandler->new()->run_all();

Low-level usage:

{
	package Object;
	use Moose;

	sub callback {
		my ($self, $arg) = @_;
		print "$self says: hello, $arg->{name}\n";
	}
}

my $object = Object->new();

my $cb = Reflex::Callback::Method->new(
	object      => $object,
	method_name => "callback"
);

$cb->deliver(greet => { name => "world" });

DESCRIPTION

Reflex::Callback::Method maps the generic Reflex::Callback interface to object and class method callbacks. Reflex::Callbacks' cb_method() function simplifies callback creation. cb_object(), also supplied by Reflex::Callbacks, is shorthand for setting several callbacks at once on a single object or class. Other syntactic sweeteners are in development.

new

Reflex::Callback::Method's constructor takes two named parameters. "object" and "method_name" define the object and method that will be invoked to handle the callback.

Despite its name, "object" may also handle class names. In these cases, "method_name" will be invoked as a class method rather than on a particular instance of the class.

deliver

Reflex::Callback::Method's deliver() method invokes the object (or class) and method as defined during the callback's construction. deliver() takes two positional parameters: an event name (which is not currently used for method callbacks), and a hashref of named parameters to be passed to the callback.

deliver() returns whatever the coderef does.

SEE ALSO

Reflex Reflex::Callback Reflex::Callbacks

"ACKNOWLEDGEMENTS" in Reflex "ASSISTANCE" in Reflex "AUTHORS" in Reflex "BUGS" in Reflex "BUGS" in Reflex "CONTRIBUTORS" in Reflex "COPYRIGHT" in Reflex "LICENSE" in Reflex "TODO" in Reflex