1package MooseX::POE;
2{
3  $MooseX::POE::VERSION = '0.215';
4}
5# ABSTRACT: The Illicit Love Child of Moose and POE
6
7use Moose ();
8use Moose::Exporter;
9
10my ( $import, $unimport, $init_meta ) = Moose::Exporter->setup_import_methods(
11    with_caller     => [qw(event)],
12    also            => 'Moose',
13    install         => [qw(import unimport)],
14    class_metaroles => {
15        class       => ['MooseX::POE::Meta::Trait::Class'],
16        instance    => ['MooseX::POE::Meta::Trait::Instance'],
17    },
18    base_class_roles => ['MooseX::POE::Meta::Trait::Object'],
19);
20
21sub init_meta {
22    my ( $class, %args ) = @_;
23
24    my $for = $args{for_class};
25    eval qq{package $for; use POE; };
26
27    Moose->init_meta( for_class => $for );
28
29    goto $init_meta;
30}
31
32sub event {
33    my ( $caller, $name, $method ) = @_;
34    my $class = Moose::Meta::Class->initialize($caller);
35    $class->add_state_method( $name => $method );
36}
37
381;
39
40
41=pod
42
43=head1 NAME
44
45MooseX::POE - The Illicit Love Child of Moose and POE
46
47=head1 VERSION
48
49version 0.215
50
51=head1 SYNOPSIS
52
53    package Counter;
54    use MooseX::POE;
55
56    has count => (
57        isa     => 'Int',
58        is      => 'rw',
59        lazy    => 1,
60        default => sub { 0 },
61    );
62
63    sub START {
64        my ($self) = @_;
65        $self->yield('increment');
66    }
67
68    event increment => sub {
69        my ($self) = @_;
70        print "Count is now " . $self->count . "\n";
71        $self->count( $self->count + 1 );
72        $self->yield('increment') unless $self->count > 3;
73    };
74
75    no MooseX::POE;
76
77    Counter->new();
78    POE::Kernel->run();
79
80or with L<MooseX::Declare|MooseX::Declare>:
81
82    class Counter {
83        use MooseX::POE::SweetArgs qw(event);
84
85        has count => (
86            isa     => 'Int',
87            is      => 'rw',
88            lazy    => 1,
89            default => sub { 0 },
90        );
91
92        sub START {
93            my ($self) = @_;
94            $self->yield('increment')
95        }
96
97        event increment => sub {
98            my ($self) = @_;
99            print "Count is now " . $self->count . "\n";
100            $self->count( $self->count + 1 );
101            $self->yield('increment') unless $self->count > 3;
102        }
103    }
104
105    Counter->new();
106    POE::Kernel->run();
107
108=head1 DESCRIPTION
109
110MooseX::POE is a L<Moose> wrapper around a L<POE::Session>.
111
112=head1 METHODS
113
114=head2 event $name $subref
115
116Create an event handler named $name.
117
118=head2 get_session_id
119
120Get the internal POE Session ID, this is useful to hand to other POE aware
121functions.
122
123=head2 yield
124
125=head2 call
126
127=head2 delay
128
129=head2 alarm
130
131=head2 alarm_add
132
133=head2 delay_add
134
135=head2 alarm_set
136
137=head2 alarm_adjust
138
139=head2 alarm_remove
140
141=head2 alarm_remove_all
142
143=head2 delay_set
144
145=head2 delay_adjust
146
147A cheap alias for the same POE::Kernel function which will gurantee posting to the object's session.
148
149=head2 STARTALL
150
151=head2 STOPALL
152
153=head1 KEYWORDS
154
155=head1 METHODS
156
157Default POE-related methods are provided by L<MooseX::POE::Meta::Trait::Object|MooseX::POE::Meta::Trait::Object>
158which is applied to your base class (which is usually L<Moose::Object|Moose::Object>) when
159you use this module. See that module for the documentation for. Below is a list
160of methods on that class so you know what to look for:
161
162=head1 NOTES ON USAGE WITH L<MooseX::Declare>
163
164L<MooseX::Declare|MooseX::Declare> support is still "experimental". Meaning that I don't use it,
165I don't have any code that uses it, and thus I can't adequately say that it
166won't cause monkeys to fly out of any orifices on your body beyond what the
167tests and the SYNOPSIS cover.
168
169That said there are a few caveats that have turned up during testing.
170
1711. The C<method> keyword doesn't seem to work as expected. This is an
172integration issue that is being resolved but I want to wait for
173L<MooseX::Declare|MooseX::Declare> to gain some more polish on their slurpy
174arguments.
175
1762. MooseX::POE attempts to re-export L<Moose>, which
177L<MooseX::Declare> has already exported in a custom fashion.
178This means that you'll get a keyword clash between the features that
179L<MooseX::Declare|MooseX::Declare> handles for you and the features that Moose
180handles. To work around this you'll need to write:
181
182    use MooseX::POE qw(event);
183    # or
184    use MooseX::POE::SweetArgs qw(event);
185    # or
186    use MooseX::POE::Role qw(event);
187
188to keep MooseX::POE from exporting the sugar that
189L<MooseX::Declare|MooseX::Declare> doesn't like. This is fixed in the Git
190version of L<MooseX::Declare|MooseX::Declare> but that version (as of this
191writing) is not on the CPAN.
192
193=head1 SEE ALSO
194
195=for :list * L<Moose|Moose>
196* L<POE|POE>
197
198=head1 AUTHORS
199
200=over 4
201
202=item *
203
204Chris Prather <chris@prather.org>
205
206=item *
207
208Ash Berlin <ash@cpan.org>
209
210=item *
211
212Chris Williams <chris@bingosnet.co.uk>
213
214=item *
215
216Yuval (nothingmuch) Kogman
217
218=item *
219
220Torsten Raudssus <torsten@raudssus.de> L<http://www.raudssus.de/>
221
222=back
223
224=head1 COPYRIGHT AND LICENSE
225
226This software is copyright (c) 2010 by Chris Prather, Ash Berlin, Chris Williams, Yuval Kogman, Torsten Raudssus.
227
228This is free software; you can redistribute it and/or modify it under
229the same terms as the Perl 5 programming language system itself.
230
231=cut
232
233
234__END__
235
236