Fetching contributors…
Cannot retrieve contributors at this time
56 lines (41 sloc) 1.2 KB
#!/usr/bin/env perl
# vim: ts=2 sw=2 noexpandtab
# This example illustrates explicit callbacks via object methods. A
# ThingWithCallbacks will call methods on objects defined in this
# file.
# Reflex::Callbacks and the Reflex::Callback helper classes will
# abstract callbacks to fulfill a number of goals. The goals are
# detailed in docs/TODO.otl and summarized in eg/
use warnings;
use strict;
use lib qw(t/lib);
use Test::More tests => 2;
# Create a thing that will invoke callbacks. This syntax uses
# explicitly specified cb_method() callbacks. There is no
# nonambiguous implicit syntax at this time. Suggestions are welcome.
package Object;
use Moose;
use Reflex::Callbacks qw(cb_method);
use ThingWithCallbacks;
has callback_thing => ( is => 'rw', isa => 'ThingWithCallbacks' );
sub BUILD {
my $self = shift;
on_event => cb_method($self, "handle_event")
sub handle_event {
my ($self, $arg) = @_;
Test::More::pass("object handled event");
sub run_thing {
my $self = shift;
my $o = Object->new();
pass("object ran to completion");