Permalink
Browse files

Create Reflex::Role::Interval, and reify it as Reflex::Interval. Need…

…ed to change a lot of code and docs that used Reflex::Timer, which has bee deleted.
  • Loading branch information...
rcaputo committed Jul 11, 2010
1 parent 5cf73d9 commit bbf149dcc5831191165d5ae06bb0e2c2047e2e31
@@ -1,6 +1,6 @@
package AsyncAwhileRole;
use Reflex::Role;
-use Reflex::Timer;
+use Reflex::Interval;
use Reflex::Callbacks qw(cb_method);
attribute_parameter name => "name";
@@ -16,7 +16,7 @@ role {
my $timer_member = "_${role_name}_timer";
- has $timer_member => ( is => 'rw', isa => 'Reflex::Timer' );
+ has $timer_member => ( is => 'rw', isa => 'Reflex::Interval' );
method_emit $cb_done => "done";
@@ -25,7 +25,7 @@ role {
after BUILD => sub {
my $self = shift;
$self->$timer_member(
- Reflex::Timer->new(
+ Reflex::Interval->new(
auto_repeat => 0,
interval => $self->$awhile(),
on_tick => cb_method($self, $cb_done),
View
@@ -240,12 +240,12 @@ renamed AfterAwhileClass, with the new asynchronous role.
As mentioned earlier, most of the work is done in the role itself.
This AsyncAwhileRole replaces the blocking sleep() with a non-blocking
-Reflex::Timer object. Later we'll introduce magic to make it more
+Reflex::Interval object. Later we'll introduce magic to make it more
concise.
package AsyncAwhileRole;
use Reflex::Role;
- use Reflex::Timer;
+ use Reflex::Interval;
use Reflex::Callbacks qw(cb_method);
attribute_parameter name => "name";
@@ -261,7 +261,7 @@ concise.
my $timer_member = "_${role_name}_timer";
- has $timer_member => ( is => 'rw', isa => 'Reflex::Timer' );
+ has $timer_member => ( is => 'rw', isa => 'Reflex::Interval' );
method_emit $cb_done => "done";
@@ -270,7 +270,7 @@ concise.
after BUILD => sub {
my $self = shift;
$self->$timer_member(
- Reflex::Timer->new(
+ Reflex::Interval->new(
auto_repeat => 0,
interval => $self->$awhile(),
on_tick => cb_method($self, $cb_done),
View
@@ -23,19 +23,19 @@ $self->emit( event => \%args );
=cut
-my $timer = Reflex::Timer->new(
+my $timer = Reflex::Interval->new(
interval => 5,
auto_repeat => 1,
on_tick => cb_coderef(\&subroutine),
);
-my $timer = Reflex::Timer->new(
+my $timer = Reflex::Interval->new(
interval => 5,
auto_repeat => 1,
on_tick => cb_method($self, "method"),
);
-my $timer = Reflex::Timer->new(
+my $timer = Reflex::Interval->new(
interval => 5,
auto_repeat => 1,
on_tick => cb_method("class", "method"),
@@ -45,7 +45,7 @@ my $timer = Reflex::Timer->new(
=cut
-my $timer = Reflex::Timer->new(
+my $timer = Reflex::Interval->new(
interval => 5,
auto_repeat => 1,
cb_role($self, "rolename"),
@@ -55,7 +55,7 @@ my $timer = Reflex::Timer->new(
=cut
-my $timer = Reflex::Timer->new(
+my $timer = Reflex::Interval->new(
interval => 5,
auto_repeat => 1,
# cb_promise
@@ -69,7 +69,7 @@ while (my $event = $timer->next()) {
=cut
-my $timer = Reflex::Timer->new(
+my $timer = Reflex::Interval->new(
interval => 5,
auto_repeat => 1,
promise => 1,
@@ -100,14 +100,14 @@ use strict;
use lib qw(../lib);
-use Reflex::Timer;
+use Reflex::Interval;
use Reflex::Callbacks qw(cb_promise);
use ExampleHelpers qw(eg_say);
my $watcher = Reflex::Base->new();
my $promise;
-my $timer = Reflex::Timer->new(
+my $timer = Reflex::Interval->new(
interval => 1,
auto_repeat => 1,
);
View
@@ -6,12 +6,12 @@
# beginning with "on_${role}" in the watcher object are used to handle
# the emitter's events.
#
-# In this test case, the Reflex::Timer object is assigned the role
+# In this test case, the Reflex::Interval object is assigned the role
# "waitron". It emits "tick" events that are handled by the watcher's
# on_waitron_tick() method.
#
# An object may watch another in more than one role. In this test
-# case, the Reflex::Timer is also watched in the "waitroff" role.
+# case, the Reflex::Interval is also watched in the "waitroff" role.
# The on_waitroff_tick() method is also invoked.
use warnings;
@@ -20,29 +20,29 @@
use Test::More tests => 10;
-### Define a class to watch events from a Reflex::Timer.
+### Define a class to watch events from a Reflex::Interval.
{
package Watcher;
use Moose;
extends 'Reflex::Base';
- use Reflex::Timer;
+ use Reflex::Interval;
use Reflex::Callbacks qw(cb_role);
use Test::More;
has timer => (
- isa => 'Maybe[Reflex::Timer]',
+ isa => 'Maybe[Reflex::Interval]',
is => 'rw',
);
sub BUILD {
my $self = $_[0];
$self->timer(
- Reflex::Timer->new(
+ Reflex::Interval->new(
interval => 0.1,
auto_repeat => 1,
cb_role($self, "waitron"),
@@ -10,7 +10,7 @@
package Counter;
use Moose;
extends 'Reflex::Base';
- use Reflex::Timer;
+ use Reflex::Interval;
use Reflex::Trait::Observed;
use Reflex::Trait::EmitsOnChange;
@@ -23,15 +23,15 @@
has ticker => (
traits => ['Reflex::Trait::Observed'],
- isa => 'Reflex::Timer|Undef',
+ isa => 'Maybe[Reflex::Interval]',
is => 'rw',
);
sub BUILD {
my $self = shift;
$self->ticker(
- Reflex::Timer->new(
+ Reflex::Interval->new(
interval => 0.1,
auto_repeat => 1,
)
View
@@ -11,7 +11,7 @@
package Counter;
use Moose;
extends 'Reflex::Base';
- use Reflex::Timer;
+ use Reflex::Interval;
use Reflex::Trait::Observed;
use Reflex::Trait::EmitsOnChange;
@@ -24,10 +24,10 @@
has ticker => (
traits => ['Reflex::Trait::Observed'],
- isa => 'Reflex::Timer',
+ isa => 'Reflex::Interval',
is => 'rw',
setup => sub {
- Reflex::Timer->new( interval => 0.1, auto_repeat => 1 )
+ Reflex::Interval->new( interval => 0.1, auto_repeat => 1 )
},
);
View
@@ -8,10 +8,10 @@
package App;
use Moose;
extends 'Reflex::Base';
- use Reflex::Timer;
+ use Reflex::Interval;
has ticker => (
- isa => 'Reflex::Timer',
+ isa => 'Reflex::Interval',
is => 'rw',
setup => { interval => 1, auto_repeat => 1 },
traits => [ 'Reflex::Trait::Observed' ],
@@ -7,9 +7,9 @@
{
package App;
use Moose;
- extends 'Reflex::Timer';
+ extends 'Reflex::Interval';
- sub on_timer_tick {
+ before on_tick => sub {
print "tick at ", scalar(localtime), "...\n";
}
}
@@ -8,11 +8,16 @@
{
package App;
- use Reflex::Timer;
- use base qw(Reflex::Timer);
+ use Reflex::Interval;
+ use base qw(Reflex::Interval);
- sub on_timer_tick {
+ sub on_tick {
print "tick at ", scalar(localtime), "...\n";
+
+ # Auto-repeat is defined in the callback.
+ # It doesn't work when we override the callback entirely.
+ # TODO - How can this be mitigated? after() in the role?
+ shift()->repeat();
}
}
@@ -9,14 +9,14 @@
{
package App;
use Reflex::Base;
- use Reflex::Timer;
+ use Reflex::Interval;
use Reflex::Callbacks qw(cb_role);
use base qw(Reflex::Base);
sub BUILD {
my $self = shift;
- $self->{ticker} = Reflex::Timer->new(
+ $self->{ticker} = Reflex::Interval->new(
interval => 1,
auto_repeat => 1,
);
@@ -5,11 +5,11 @@
use lib qw(../lib);
-use Reflex::Timer;
+use Reflex::Interval;
use Reflex::Callbacks qw(cb_promise);
use ExampleHelpers qw(eg_say);
-my $timer = Reflex::Timer->new(
+my $timer = Reflex::Interval->new(
interval => 1,
auto_repeat => 1,
);
@@ -5,12 +5,12 @@
use lib qw(../lib);
-use Reflex::Timer;
+use Reflex::Interval;
use ExampleHelpers qw(eg_say);
use ReflexPromise;
my $p = ReflexPromise->new(
- object => Reflex::Timer->new(
+ object => Reflex::Interval->new(
interval => 1,
auto_repeat => 1,
)
View
@@ -9,10 +9,10 @@
use lib qw(../lib);
-use Reflex::Timer;
+use Reflex::Interval;
use ExampleHelpers qw(eg_say);
-my $t = Reflex::Timer->new(
+my $t = Reflex::Interval->new(
interval => 1,
auto_repeat => 1,
);
Oops, something went wrong.

0 comments on commit bbf149d

Please sign in to comment.