Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

file 55 lines (41 sloc) 1.225 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
#!/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/eg-20-rcb-callback.pl

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;

$self->callback_thing(
ThingWithCallbacks->new(
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;
$self->callback_thing()->run();
}
}

my $o = Object->new();
$o->run_thing();

pass("object ran to completion");
Something went wrong with that request. Please try again.