Permalink
Newer
Older
100644 120 lines (85 sloc) 2.05 KB
1
Documenting Reflex syntax evolution.
2
3
=head1 Gathering callbacks.
4
6
Has the cb() member.
7
BUILD
8
Maps constructor parameters to callbacks.
9
Maps callback types to watchers:
10
discrete callbacks = discrete watchers
11
role callbacks = role watchers
12
no callbacks = unwatched (promise?)
14
=head1 Reflex::Role::Reactive::BUILD calls cb_gather()
15
16
emit() syntax is preserved.
17
1. Role::Reactive handles it normally.
18
2. Local delivery is through the callback object.
19
20
$self->emit( event => \%args );
21
22
=head1 Callback constructor parameter.
23
24
=cut
25
26
my $timer = Reflex::Interval->new(
27
interval => 5,
28
auto_repeat => 1,
29
on_tick => cb_coderef(\&subroutine),
30
);
31
32
my $timer = Reflex::Interval->new(
33
interval => 5,
34
auto_repeat => 1,
35
on_tick => cb_method($self, "method"),
36
);
37
38
my $timer = Reflex::Interval->new(
39
interval => 5,
40
auto_repeat => 1,
41
on_tick => cb_method("class", "method"),
42
);
43
44
=head1 Role constructor parameter.
45
46
=cut
47
48
my $timer = Reflex::Interval->new(
49
interval => 5,
50
auto_repeat => 1,
51
cb_role($self, "rolename"),
52
);
53
54
=head1 Promise.
55
56
=cut
57
58
my $timer = Reflex::Interval->new(
59
interval => 5,
60
auto_repeat => 1,
61
# cb_promise
62
);
63
64
while (my $event = $timer->next()) {
72
my $timer = Reflex::Interval->new(
73
interval => 5,
74
auto_repeat => 1,
75
promise => 1,
76
);
77
78
$self->watch(
79
watcher => $timer,
80
event => "tick",
81
callback => ANY_RCB_EXCEPT_PROMISE,
82
);
83
84
=head1 Promise Again
85
86
The current syntax is too verbose.
87
88
$watcher has no purpose except to call watch().
90
Perhaps $watcher could be replaced by a Promise class that watches
91
and then returns events? Similar to PromiseThing in
92
eg-25-rcb-promise.pl?
93
94
=cut
95
96
#!/usr/bin/env perl
97
98
use warnings;
99
use strict;
100
101
use lib qw(../lib);
102
104
use Reflex::Callbacks qw(cb_promise);
105
use ExampleHelpers qw(eg_say);
106
107
my $watcher = Reflex::Base->new();
110
my $timer = Reflex::Interval->new(
111
interval => 1,
112
auto_repeat => 1,
113
);
114
115
$watcher->watch($timer, cb_promise(\$promise));
117
while (my $event = $promise->next()) {
118
eg_say("next() returned an event (@$event)");