Commit afd7c10c1b56d8c88a38864670c311cda3733623
- Diff rendering mode:
- inline
- side by side
eg/eg-14-synopsis.pl
(13 / 13)
|   | |||
| 5 | 5 | use lib qw(../lib); | |
| 6 | 6 | ||
| 7 | 7 | { | |
| 8 | package App; | ||
| 9 | use Moose; | ||
| 10 | extends 'Reflex::Object'; | ||
| 11 | use Reflex::Timer; | ||
| 8 | package App; | ||
| 9 | use Moose; | ||
| 10 | extends 'Reflex::Object'; | ||
| 11 | use Reflex::Timer; | ||
| 12 | 12 | ||
| 13 | has ticker => ( | ||
| 14 | isa => 'Reflex::Timer', | ||
| 15 | is => 'rw', | ||
| 16 | setup => { interval => 1, auto_repeat => 1 }, | ||
| 17 | traits => [ 'Reflex::Trait::Observer' ], | ||
| 18 | ); | ||
| 13 | has ticker => ( | ||
| 14 | isa => 'Reflex::Timer', | ||
| 15 | is => 'rw', | ||
| 16 | setup => { interval => 1, auto_repeat => 1 }, | ||
| 17 | traits => [ 'Reflex::Trait::Observer' ], | ||
| 18 | ); | ||
| 19 | 19 | ||
| 20 | sub on_ticker_tick { | ||
| 21 | print "tick at ", scalar(localtime), "...\n"; | ||
| 22 | } | ||
| 20 | sub on_ticker_tick { | ||
| 21 | print "tick at ", scalar(localtime), "...\n"; | ||
| 22 | } | ||
| 23 | 23 | } | |
| 24 | 24 | ||
| 25 | 25 | exit App->new()->run_all(); |
|   | |||
| 5 | 5 | use lib qw(../lib); | |
| 6 | 6 | ||
| 7 | 7 | { | |
| 8 | package App; | ||
| 9 | use Moose; | ||
| 10 | extends 'Reflex::Timer'; | ||
| 8 | package App; | ||
| 9 | use Moose; | ||
| 10 | extends 'Reflex::Timer'; | ||
| 11 | 11 | ||
| 12 | sub on_my_tick { | ||
| 13 | print "tick at ", scalar(localtime), "...\n"; | ||
| 14 | } | ||
| 12 | sub on_my_tick { | ||
| 13 | print "tick at ", scalar(localtime), "...\n"; | ||
| 14 | } | ||
| 15 | 15 | } | |
| 16 | 16 | ||
| 17 | 17 | exit App->new(interval => 1, auto_repeat => 1)->run_all(); |
|   | |||
| 7 | 7 | use lib qw(../lib); | |
| 8 | 8 | ||
| 9 | 9 | { | |
| 10 | package App; | ||
| 11 | use Reflex::Timer; | ||
| 12 | use base qw(Reflex::Timer); | ||
| 10 | package App; | ||
| 11 | use Reflex::Timer; | ||
| 12 | use base qw(Reflex::Timer); | ||
| 13 | 13 | ||
| 14 | sub on_my_tick { | ||
| 15 | print "tick at ", scalar(localtime), "...\n"; | ||
| 16 | } | ||
| 14 | sub on_my_tick { | ||
| 15 | print "tick at ", scalar(localtime), "...\n"; | ||
| 16 | } | ||
| 17 | 17 | } | |
| 18 | 18 | ||
| 19 | 19 | exit App->new(interval => 1, auto_repeat => 1)->run_all(); |
eg/eg-18-synopsis-no-moose.pl
(18 / 18)
|   | |||
| 7 | 7 | use lib qw(../lib); | |
| 8 | 8 | ||
| 9 | 9 | { | |
| 10 | package App; | ||
| 11 | use Reflex::Object; | ||
| 12 | use Reflex::Timer; | ||
| 13 | use base qw(Reflex::Object); | ||
| 10 | package App; | ||
| 11 | use Reflex::Object; | ||
| 12 | use Reflex::Timer; | ||
| 13 | use base qw(Reflex::Object); | ||
| 14 | 14 | ||
| 15 | sub BUILD { | ||
| 16 | my $self = shift; | ||
| 15 | sub BUILD { | ||
| 16 | my $self = shift; | ||
| 17 | 17 | ||
| 18 | $self->{ticker} = Reflex::Timer->new( | ||
| 19 | interval => 1, | ||
| 20 | auto_repeat => 1, | ||
| 21 | ); | ||
| 18 | $self->{ticker} = Reflex::Timer->new( | ||
| 19 | interval => 1, | ||
| 20 | auto_repeat => 1, | ||
| 21 | ); | ||
| 22 | 22 | ||
| 23 | $self->observe_role( | ||
| 24 | observed => $self->{ticker}, | ||
| 25 | role => "ticker", | ||
| 26 | ); | ||
| 27 | } | ||
| 23 | $self->observe_role( | ||
| 24 | observed => $self->{ticker}, | ||
| 25 | role => "ticker", | ||
| 26 | ); | ||
| 27 | } | ||
| 28 | 28 | ||
| 29 | sub on_ticker_tick { | ||
| 30 | print "tick at ", scalar(localtime), "...\n"; | ||
| 31 | } | ||
| 29 | sub on_ticker_tick { | ||
| 30 | print "tick at ", scalar(localtime), "...\n"; | ||
| 31 | } | ||
| 32 | 32 | } | |
| 33 | 33 | ||
| 34 | 34 | exit App->new()->run_all(); |
eg/eg-25-rcb-promise.pl
(12 / 12)
|   | |||
| 20 | 20 | # Create a thing that will invoke callbacks. | |
| 21 | 21 | ||
| 22 | 22 | { | |
| 23 | package PromiseThing; | ||
| 24 | use Moose; | ||
| 25 | extends 'Reflex::Object'; | ||
| 26 | use Reflex::Timer; | ||
| 23 | package PromiseThing; | ||
| 24 | use Moose; | ||
| 25 | extends 'Reflex::Object'; | ||
| 26 | use Reflex::Timer; | ||
| 27 | 27 | use Reflex::Callbacks qw(gather_cb); | |
| 28 | 28 | ||
| 29 | has ticker => ( | ||
| 30 | isa => 'Reflex::Timer', | ||
| 31 | is => 'rw', | ||
| 32 | setup => { interval => 1, auto_repeat => 1 }, | ||
| 33 | traits => [ 'Reflex::Trait::Observer' ], | ||
| 34 | ); | ||
| 29 | has ticker => ( | ||
| 30 | isa => 'Reflex::Timer', | ||
| 31 | is => 'rw', | ||
| 32 | setup => { interval => 1, auto_repeat => 1 }, | ||
| 33 | traits => [ 'Reflex::Trait::Observer' ], | ||
| 34 | ); | ||
| 35 | 35 | ||
| 36 | 36 | has cb => ( is => 'rw', isa => 'Reflex::Callbacks' ); | |
| 37 | 37 | ||
| … | … | ||
| 40 | 40 | $self->cb(gather_cb($arg)); | |
| 41 | 41 | } | |
| 42 | 42 | ||
| 43 | sub on_ticker_tick { | ||
| 43 | sub on_ticker_tick { | ||
| 44 | 44 | my $self = shift; | |
| 45 | 45 | $self->cb()->send( event => {} ); | |
| 46 | } | ||
| 46 | } | ||
| 47 | 47 | } | |
| 48 | 48 | ||
| 49 | 49 | use Reflex::Callbacks qw(cb_promise); |
lib/Reflex/POE/Session.pm
(27 / 27)
|   | |||
| 54 | 54 | # Not a complete example. | |
| 55 | 55 | # Please see eg-13-irc-bot.pl in the examples for one. | |
| 56 | 56 | ||
| 57 | has poco_watcher => ( | ||
| 58 | isa => 'Reflex::POE::Session', | ||
| 59 | is => 'rw', | ||
| 60 | traits => ['Reflex::Trait::Observer'], | ||
| 61 | role => 'poco', | ||
| 62 | ); | ||
| 57 | has poco_watcher => ( | ||
| 58 | isa => 'Reflex::POE::Session', | ||
| 59 | is => 'rw', | ||
| 60 | traits => ['Reflex::Trait::Observer'], | ||
| 61 | role => 'poco', | ||
| 62 | ); | ||
| 63 | 63 | ||
| 64 | sub BUILD { | ||
| 65 | my $self = shift; | ||
| 64 | sub BUILD { | ||
| 65 | my $self = shift; | ||
| 66 | 66 | ||
| 67 | $self->component( | ||
| 68 | POE::Component::IRC->spawn( | ||
| 69 | nick => "reflex_$$", | ||
| 70 | ircname => "Reflex Test Bot", | ||
| 71 | server => "10.0.0.25", | ||
| 72 | ) || die "Drat: $!" | ||
| 73 | ); | ||
| 67 | $self->component( | ||
| 68 | POE::Component::IRC->spawn( | ||
| 69 | nick => "reflex_$$", | ||
| 70 | ircname => "Reflex Test Bot", | ||
| 71 | server => "10.0.0.25", | ||
| 72 | ) || die "Drat: $!" | ||
| 73 | ); | ||
| 74 | 74 | ||
| 75 | $self->poco_watcher( | ||
| 76 | Reflex::POE::Session->new( | ||
| 77 | sid => $self->component()->session_id(), | ||
| 78 | ) | ||
| 79 | ); | ||
| 75 | $self->poco_watcher( | ||
| 76 | Reflex::POE::Session->new( | ||
| 77 | sid => $self->component()->session_id(), | ||
| 78 | ) | ||
| 79 | ); | ||
| 80 | 80 | ||
| 81 | $self->run_within_session( | ||
| 82 | sub { | ||
| 83 | $self->component()->yield(register => "all"); | ||
| 84 | $self->component()->yield(connect => {}); | ||
| 85 | } | ||
| 86 | ) | ||
| 87 | } | ||
| 81 | $self->run_within_session( | ||
| 82 | sub { | ||
| 83 | $self->component()->yield(register => "all"); | ||
| 84 | $self->component()->yield(connect => {}); | ||
| 85 | } | ||
| 86 | ) | ||
| 87 | } | ||
| 88 | 88 | ||
| 89 | 89 | TODO - Either complete the example, or find a shorter one. | |
| 90 | 90 |
lib/Reflex/POE/Wheel/Run.pm
(26 / 26)
|   | |||
| 123 | 123 | # Not a complete example. Please see eg-07-wheel-run.pl or even | |
| 124 | 124 | # better eg-08-observer-trait.pl for working examples. | |
| 125 | 125 | ||
| 126 | has child => ( | ||
| 127 | traits => ['Reflex::Trait::Observer'], | ||
| 128 | isa => 'Reflex::POE::Wheel::Run|Undef', | ||
| 129 | is => 'rw', | ||
| 130 | ); | ||
| 126 | has child => ( | ||
| 127 | traits => ['Reflex::Trait::Observer'], | ||
| 128 | isa => 'Reflex::POE::Wheel::Run|Undef', | ||
| 129 | is => 'rw', | ||
| 130 | ); | ||
| 131 | 131 | ||
| 132 | sub BUILD { | ||
| 133 | my $self = shift; | ||
| 134 | $self->child( | ||
| 135 | Reflex::POE::Wheel::Run->new( | ||
| 136 | Program => "$^X -wle 'print qq[pid(\$\$) moo(\$_)] for 1..10; exit'", | ||
| 137 | ) | ||
| 138 | ); | ||
| 139 | } | ||
| 132 | sub BUILD { | ||
| 133 | my $self = shift; | ||
| 134 | $self->child( | ||
| 135 | Reflex::POE::Wheel::Run->new( | ||
| 136 | Program => "$^X -wle 'print qq[pid(\$\$) moo(\$_)] for 1..10; exit'", | ||
| 137 | ) | ||
| 138 | ); | ||
| 139 | } | ||
| 140 | 140 | ||
| 141 | sub on_child_stdout { | ||
| 142 | my ($self, $args) = @_; | ||
| 143 | print "stdout: $args->{output}\n"; | ||
| 144 | } | ||
| 141 | sub on_child_stdout { | ||
| 142 | my ($self, $args) = @_; | ||
| 143 | print "stdout: $args->{output}\n"; | ||
| 144 | } | ||
| 145 | 145 | ||
| 146 | sub on_child_close { | ||
| 147 | my ($self, $args) = @_; | ||
| 148 | print "child closed all output\n"; | ||
| 149 | } | ||
| 146 | sub on_child_close { | ||
| 147 | my ($self, $args) = @_; | ||
| 148 | print "child closed all output\n"; | ||
| 149 | } | ||
| 150 | 150 | ||
| 151 | sub on_child_signal { | ||
| 152 | my ($self, $args) = @_; | ||
| 153 | print "child $args->{pid} exited: $args->{exit}\n"; | ||
| 154 | $self->child(undef); | ||
| 155 | } | ||
| 151 | sub on_child_signal { | ||
| 152 | my ($self, $args) = @_; | ||
| 153 | print "child $args->{pid} exited: $args->{exit}\n"; | ||
| 154 | $self->child(undef); | ||
| 155 | } | ||
| 156 | 156 | ||
| 157 | 157 | TODO - Needs a better example. | |
| 158 | 158 |

