MooseX-POE-0.215/0000755000175000001440000000000011746020426012773 5ustar torstenusersMooseX-POE-0.215/LICENSE0000644000175000001440000004400311746020426014001 0ustar torstenusersThis software is copyright (c) 2010 by Chris Prather, Ash Berlin, Chris Williams, Yuval Kogman, Torsten Raudssus. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. Terms of the Perl programming language system itself a) the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version, or b) the "Artistic License" --- The GNU General Public License, Version 1, February 1989 --- This software is Copyright (c) 2010 by Chris Prather, Ash Berlin, Chris Williams, Yuval Kogman, Torsten Raudssus. This is free software, licensed under: The GNU General Public License, Version 1, February 1989 GNU GENERAL PUBLIC LICENSE Version 1, February 1989 Copyright (C) 1989 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The license agreements of most software companies try to keep users at the mercy of those companies. By contrast, our General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. The General Public License applies to the Free Software Foundation's software and to any other program whose authors commit to using it. You can use it for your programs, too. When we speak of free software, we are referring to freedom, not price. Specifically, the General Public License is designed to make sure that you have the freedom to give away or sell copies of free software, that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of a such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must tell them their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any work containing the Program or a portion of it, either verbatim or with modifications. Each licensee is addressed as "you". 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this General Public License and to the absence of any warranty; and give any other recipients of the Program a copy of this General Public License along with the Program. You may charge a fee for the physical act of transferring a copy. 2. You may modify your copy or copies of the Program or any portion of it, and copy and distribute such modifications under the terms of Paragraph 1 above, provided that you also do the following: a) cause the modified files to carry prominent notices stating that you changed the files and the date of any change; and b) cause the whole of any work that you distribute or publish, that in whole or in part contains the Program or any part thereof, either with or without modifications, to be licensed at no charge to all third parties under the terms of this General Public License (except that you may choose to grant warranty protection to some or all third parties, at your option). c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the simplest and most usual way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this General Public License. d) You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. Mere aggregation of another independent work with the Program (or its derivative) on a volume of a storage or distribution medium does not bring the other work under the scope of these terms. 3. You may copy and distribute the Program (or a portion or derivative of it, under Paragraph 2) in object code or executable form under the terms of Paragraphs 1 and 2 above provided that you also do one of the following: a) accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Paragraphs 1 and 2 above; or, b) accompany it with a written offer, valid for at least three years, to give any third party free (except for a nominal charge for the cost of distribution) a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Paragraphs 1 and 2 above; or, c) accompany it with the information you received as to where the corresponding source code may be obtained. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form alone.) Source code for a work means the preferred form of the work for making modifications to it. For an executable file, complete source code means all the source code for all modules it contains; but, as a special exception, it need not include source code for modules which are standard libraries that accompany the operating system on which the executable file runs, or for standard header files or definitions files that accompany that operating system. 4. You may not copy, modify, sublicense, distribute or transfer the Program except as expressly provided under this General Public License. Any attempt otherwise to copy, modify, sublicense, distribute or transfer the Program is void, and will automatically terminate your rights to use the Program under this License. However, parties who have received copies, or rights to use copies, from you under this General Public License will not have their licenses terminated so long as such parties remain in full compliance. 5. By copying, distributing or modifying the Program (or any work based on the Program) you indicate your acceptance of this license to do so, and all its terms and conditions. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. 7. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of the license which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the license, you may choose any version ever published by the Free Software Foundation. 8. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Appendix: How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to humanity, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19xx name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (a program to direct compilers to make passes at assemblers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice That's all there is to it! --- The Artistic License 1.0 --- This software is Copyright (c) 2010 by Chris Prather, Ash Berlin, Chris Williams, Yuval Kogman, Torsten Raudssus. This is free software, licensed under: The Artistic License 1.0 The Artistic License Preamble The intent of this document is to state the conditions under which a Package may be copied, such that the Copyright Holder maintains some semblance of artistic control over the development of the package, while giving the users of the package the right to use and distribute the Package in a more-or-less customary fashion, plus the right to make reasonable modifications. Definitions: - "Package" refers to the collection of files distributed by the Copyright Holder, and derivatives of that collection of files created through textual modification. - "Standard Version" refers to such a Package if it has not been modified, or has been modified in accordance with the wishes of the Copyright Holder. - "Copyright Holder" is whoever is named in the copyright or copyrights for the package. - "You" is you, if you're thinking about copying or distributing this Package. - "Reasonable copying fee" is whatever you can justify on the basis of media cost, duplication charges, time of people involved, and so on. (You will not be required to justify it to the Copyright Holder, but only to the computing community at large as a market that must bear the fee.) - "Freely Available" means that no fee is charged for the item itself, though there may be fees involved in handling the item. It also means that recipients of the item may redistribute it under the same conditions they received it. 1. You may make and give away verbatim copies of the source form of the Standard Version of this Package without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers. 2. You may apply bug fixes, portability fixes and other modifications derived from the Public Domain or from the Copyright Holder. A Package modified in such a way shall still be considered the Standard Version. 3. You may otherwise modify your copy of this Package in any way, provided that you insert a prominent notice in each changed file stating how and when you changed that file, and provided that you do at least ONE of the following: a) place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or placing the modifications on a major archive site such as ftp.uu.net, or by allowing the Copyright Holder to include your modifications in the Standard Version of the Package. b) use the modified Package only within your corporation or organization. c) rename any non-standard executables so the names do not conflict with standard executables, which must also be provided, and provide a separate manual page for each non-standard executable that clearly documents how it differs from the Standard Version. d) make other distribution arrangements with the Copyright Holder. 4. You may distribute the programs of this Package in object code or executable form, provided that you do at least ONE of the following: a) distribute a Standard Version of the executables and library files, together with instructions (in the manual page or equivalent) on where to get the Standard Version. b) accompany the distribution with the machine-readable source of the Package with your modifications. c) accompany any non-standard executables with their corresponding Standard Version executables, giving the non-standard executables non-standard names, and clearly documenting the differences in manual pages (or equivalent), together with instructions on where to get the Standard Version. d) make other distribution arrangements with the Copyright Holder. 5. You may charge a reasonable copying fee for any distribution of this Package. You may charge any fee you choose for support of this Package. You may not charge a fee for this Package itself. However, you may distribute this Package in aggregate with other (possibly commercial) programs as part of a larger (possibly commercial) software distribution provided that you do not advertise this Package as a product of your own. 6. The scripts and library files supplied as input to or produced as output from the programs of this Package do not automatically fall under the copyright of this Package, but belong to whomever generated them, and may be sold commercially, and may be aggregated with this Package. 7. C or perl subroutines supplied by you and linked into this Package shall not be considered part of this Package. 8. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 9. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. The End MooseX-POE-0.215/t/0000755000175000001440000000000011746020426013236 5ustar torstenusersMooseX-POE-0.215/t/12_more_roles.t0000644000175000001440000000070511746020426016075 0ustar torstenusers#!/usr/bin/perl use strict; use warnings; use Test::More tests => 1; { package Getty; use Moose::Role; } { package Pants; use MooseX::POE::Role; event 'wear' => sub { ::pass("I AM BEING WORN!"); }; } { package Clocks; use MooseX::POE; with 'Pants', 'Getty'; sub bork { my ($self) = @_; ::pass('bork'); $self->yield('wear'); } } my $c = Clocks->new; $c->bork; POE::Kernel->run; MooseX-POE-0.215/t/10_immutability.t0000644000175000001440000000165111746020426016437 0ustar torstenusersuse strict; use warnings; use Test::More tests => 2; { package mxpoe; use MooseX::POE; use Test::More; sub START { my ( $kernel, $self ) = @_[ KERNEL, OBJECT ]; diag "Starting .... \n" if $ENV{TEST_VERBOSE}; $kernel->yield('counter_event'); return; } event 'counter_event' => sub { my ( $kernel, $self ) = @_[ KERNEL, OBJECT ]; pass('Got a counter event'); return; }; no MooseX::POE; __PACKAGE__->meta->make_immutable; } { package mxpoet; use MooseX::POE; use Test::More; extends 'mxpoe'; sub START { my ( $kernel, $self ) = @_[ KERNEL, OBJECT ]; diag "Starting EXTENSION .... \n" if $ENV{TEST_VERBOSE}; $kernel->yield('counter_event'); return; } no MooseX::POE; } package main; use strict; use warnings; use POE; my $mxpoe = mxpoet->new(); $poe_kernel->run(); exit 0; MooseX-POE-0.215/t/release-pod-syntax.t0000644000175000001440000000045011746020426017146 0ustar torstenusers#!perl BEGIN { unless ($ENV{RELEASE_TESTING}) { require Test::More; Test::More::plan(skip_all => 'these tests are for release candidate testing'); } } use Test::More; eval "use Test::Pod 1.41"; plan skip_all => "Test::Pod 1.41 required for testing POD" if $@; all_pod_files_ok(); MooseX-POE-0.215/t/14_bug_double_build.t0000644000175000001440000000067711746020426017227 0ustar torstenusers#!/usr/bin/perl use strict; use warnings; use Test::More; my $cnt = 0; my $cnt_start = 0; { package Test::MooseX::POE::DoubleBuild; use MooseX::POE; sub START { $cnt_start++; } sub BUILD { $cnt++; } } Test::MooseX::POE::DoubleBuild->new; is($cnt, 1, 'BUILD called once'); is($cnt_start, 0, 'START not called'); POE::Kernel->run; is($cnt, 1, 'BUILD still called once'); is($cnt_start, 1, 'START called once'); done_testing(); MooseX-POE-0.215/t/08_moosex_declare.t0000644000175000001440000000141011746020426016717 0ustar torstenusers#!/usr/bin/env perl use strict; use warnings; use Test::More; use Test::Moose; BEGIN { eval "use MooseX::Declare;"; plan skip_all => "MooseX::Declare not installed; skipping" if $@; } plan tests => 6; role Rollo { use MooseX::POE::Role qw(event); sub foo { ::pass('foo!')} event yarr => sub { ::pass("yarr!") } } does_ok(Rollo->meta, "MooseX::POE::Meta::Role"); class App with Rollo { use MooseX::POE::SweetArgs qw(event); sub START { my ($self) = @_; ::pass('START'); $self->foo(); $self->yield('next'); } event next => sub { my ($self) = @_; ::pass('next'); $self->yield("yarr"); }; sub STOP { ::pass('STOP') } } my $obj = App->new; POE::Kernel->run; MooseX-POE-0.215/t/04_with.t0000644000175000001440000000132011746020426014675 0ustar torstenusers#!/usr/bin/env perl use strict; use warnings; use Test::More tests => 7; use Test::Moose; { package Rollo; use MooseX::POE::Role; sub foo { ::pass('foo!')} event yarr => sub { ::pass("yarr!"); shift->yield('matey'); }; event matey => sub { ::pass("matey!") }; } { package App; use MooseX::POE; with qw(Rollo); sub START { my ($self) = $_[OBJECT]; ::pass('START'); $self->foo(); $self->yield('next'); } event next => sub { my ($self) = $_[OBJECT]; ::pass('next'); $self->yield("yarr"); }; sub STOP { ::pass('STOP') } } my $obj = App->new; does_ok($obj, 'Rollo'); POE::Kernel->run; MooseX-POE-0.215/t/05_daemonize.t0000644000175000001440000000074711746020426015712 0ustar torstenusers#!/usr/bin/env perl use strict; use warnings; use Test::More; eval "use MooseX::Daemonize"; plan skip_all => "MooseX::Daemonize not installed; skipping" if $@; plan tests => 3; { package App; use MooseX::POE; with qw(MooseX::Daemonize); sub START { my ($self) = $_[OBJECT]; ::pass('START'); $self->yield('next'); } event next => sub { ::pass('next') }; sub STOP { ::pass('STOP') } } App->new; POE::Kernel->run; MooseX-POE-0.215/t/04_with_override.t0000644000175000001440000000074211746020426016603 0ustar torstenusersuse strict; use warnings; use Test::More skip_all => 'Moose upstream needs to sort out composition'; use Test::More tests => 2; { package Rollo; use MooseX::POE::Role; event foo => sub { ::fail('not overridden'); }; } { package Foo; use MooseX::POE; with 'Rollo'; sub START { ::pass('START'); $_[KERNEL]->yield('foo'); } event foo => sub { ::pass('overridden foo'); }; } Foo->new; POE::Kernel->run; MooseX-POE-0.215/t/02_poe_forkbomb.t0000644000175000001440000000630411746020426016373 0ustar torstenusers#!/usr/bin/env perl use strict; use warnings; use Test::More 'no_plan'; my $count = 0; my $max_sessions = 30; my $half_sessions = int( $max_sessions / 2 ); my $fork_ran_at_least_once = 0; my %english = ( lose => 'is losing', gain => 'is gaining', create => 'has created' ); # silence the copious diag's this test produces :) sub _diag { diag( @_ ) if $ENV{TEST_VERBOSE}; } # this is based on the forkbomb.perl example that comes with POE # please check it out for better documentation { package ForkBomber; use MooseX::POE; has id => ( isa => 'Str', is => 'ro', default => sub { $count++ }, ); sub START { $_[0]->yield('fork'); $poe_kernel->sig( 'INT', 'signal_handler' ); $poe_kernel->sig( 'ZOMBIE', 'signal_handler' ); ::pass( 'Started ' . $_[0]->id ); } sub STOP { ::pass( 'stopped ' . $_[OBJECT]->id ); } sub CHILD { my ( $kernel, $self, $direction, $child, $return ) = @_[ KERNEL, OBJECT, ARG0, ARG1, ARG2 ]; ::_diag printf( "%4d %s child %s%s\n", $self->id, $english{$direction}, $kernel->call( $child, 'fetch_id' ), ( $direction eq 'create' ? " (child returned: " . ( defined $return ? $return : "UNDEF" ) . ")" : '' ) ); } sub PARENT { my ( $kernel, $self, $old_parent, $new_parent ) = @_[ KERNEL, OBJECT, ARG0, ARG1 ]; ::_diag printf( "%4d parent is changing from %d to %d\n", $self->id, $poe_kernel->call( $old_parent, 'fetch_id' ), $poe_kernel->call( $new_parent, 'fetch_id' ) ); } event signal_handler => sub { my ( $self, $signal_name ) = @_[ OBJECT, ARG0 ]; ::_diag printf( "%4d has received SIG%s\n", $self->id, $signal_name ); # tell Kernel that this wasn't handled return 0; }; event fork => sub { $fork_ran_at_least_once++; my ( $kernel, $self ) = @_[ KERNEL, OBJECT ]; if ( $count < $max_sessions ) { if ( rand() < 0.5 ) { ::_diag $self->id . " is starting a new child..."; ForkBomber->new; } # tails == don't spawn else { ::_diag $self->id . " is just spinning its wheels this time..."; } if ( ( $count < $half_sessions ) || ( rand() < 0.05 ) ) { $kernel->yield('fork'); } else { ::_diag $self->id . " has decided to die. Bye!"; if ( $self->id != 1 ) { $kernel->yield('_stop'); } } } else { ::_diag $self->id . " notes that the session limit is met. Bye!"; # Please see the two NOTEs above. if ( $self->id != 1 ) { $kernel->yield('_stop'); } } }; event fetch_id => sub { return $_[OBJECT]->id; } } ForkBomber->new; POE::Kernel->run; # A.k.a. 'the we actualy did something test' ok($fork_ran_at_least_once, "We had at least one fork"); __END__ MooseX-POE-0.215/t/15_timers.t0000644000175000001440000000236011746020426015234 0ustar torstenusers#!/usr/bin/perl use strict; use warnings; use Test::More; my $right_cnt = 0; my $inside_cnt = 0; my $outside_cnt = 0; my $wrong_cnt = 0; { package Test::MooseX::POE::Timers::Doer; use MooseX::POE; event 'tick' => sub { my ( $self ) = @_; $right_cnt++; $self->inside_self_delay; }; event 'inside_self_delay_tick' => sub { my ( $self ) = @_; $inside_cnt++; }; event 'outside_self_delay_tick' => sub { my ( $self ) = @_; $outside_cnt++; }; sub inside_self_delay { my ( $self ) = @_; $self->delay( 'inside_self_delay_tick' => 1 ); } sub outside_self_delay { my ( $self ) = @_; $self->delay( 'outside_self_delay_tick' => 1 ); } } { package Test::MooseX::POE::Timers::SomeoneElse; use MooseX::POE; sub START { my ( $self ) = @_; my $doer = Test::MooseX::POE::Timers::Doer->new(); $doer->delay( 'tick' => 1 ); $doer->outside_self_delay; } event 'tick' => sub { $wrong_cnt++; }; } Test::MooseX::POE::Timers::SomeoneElse->new; POE::Kernel->run; is($inside_cnt, 1, 'right self_tick is called by $self inside the session'); is($outside_cnt, 1, 'right self_tick is called by $self outside the session'); is($right_cnt, 1, 'right tick is called'); is($wrong_cnt, 0, 'wrong tick isnt called'); done_testing(); MooseX-POE-0.215/t/03_extend.t0000644000175000001440000000153311746020426015216 0ustar torstenusers#!/usr/bin/env perl use strict; use warnings; use Test::More tests => 6; my ($base_start_called, $extended_start_called); { package Base; use MooseX::POE; sub START { # Do this rather than embedd ::ok(1) here so ath get proper failing reports ::pass('Base Start'); $base_start_called = 1; }; sub on_foo { ::pass('on_foo'); $_[KERNEL]->yield('bar'); } } { package Extended; use MooseX::POE; extends 'Base'; sub START { ::pass('Extended after Start'); $extended_start_called = 1; $_[KERNEL]->yield('foo'); }; sub on_bar { ::pass('on_bar'); } } my $foo = Extended->new(); POE::Kernel->run(); # If the test count for this test is wrong, on_foo probably isn't getting set # as an event properly ok($base_start_called, "Base START called"); ok($extended_start_called,"Extended START called"); MooseX-POE-0.215/t/01_basic.t0000644000175000001440000000266511746020426015015 0ustar torstenusers#!/usr/bin/env perl use strict; use warnings; use Test::More; my $mem_cycle = eval { require Test::Memory::Cycle } || 0; my $num_objs = 10; plan tests => 10*$num_objs + $mem_cycle *2; { package Counter; use MooseX::POE; has count => ( isa => 'Int', is => 'rw', lazy => 1, default => sub { 1 }, ); has foo => ( is => 'rw' ); sub START { my ($self, $kernel, $session) = @_[OBJECT, KERNEL, SESSION]; ::pass('Starting '); ::isa_ok($kernel, "POE::Kernel", "kernel in START"); ::isa_ok($session, "POE::Session", "session in START"); ::is($self->foo, 1, "foo attribute has correct value"); $self->yield('dec'); } event inc => sub { my ($self) = $_[OBJECT]; ::pass( $self . ':' . $self->count ); $self->count( $self->count + 1 ); return if 3 < $self->count; $self->yield('inc'); }; sub on_dec { my ($self) = $_[OBJECT]; ::pass( $self . ':' . $self->count ); $self->count($self->count - 1 ); $self->yield('inc'); } sub STOP { ::pass('Stopping'); } no MooseX::POE; } my @objs = map { Counter->new(foo => 1) } ( 1 .. $num_objs );# .. 10 ); Test::Memory::Cycle::memory_cycle_ok(\@objs, "no memory cycles") if $mem_cycle; POE::Kernel->run(); Test::Memory::Cycle::memory_cycle_ok(\@objs, "no memory cycles") if $mem_cycle; MooseX-POE-0.215/t/09_extend.t0000644000175000001440000000164411746020426015227 0ustar torstenusers#!/usr/bin/env perl use strict; use warnings; use Test::More tests => 6; my ($base_start_called, $extended_start_called); { package Base; use MooseX::POE; sub START { # Do this rather than embedd ::ok(1) here so ath get proper failing reports ::pass('Base Start'); $base_start_called = 1; }; sub on_foo { ::pass('on_foo'); $_[KERNEL]->yield('bar'); } } { package Extended; use MooseX::POE; extends 'Base'; sub START { ::pass('Extended after Start'); $extended_start_called = 1; $_[KERNEL]->yield('foo'); }; sub on_bar { ::pass('on_bar'); } sub on_foo { ::pass('on_foo'); $_[KERNEL]->yield('bar'); } } my $foo = Extended->new(); POE::Kernel->run(); # If the test count for this test is wrong, on_foo probably isn't getting set # as an event properly ok($base_start_called, "Base START called"); ok($extended_start_called,"Extended START called"); MooseX-POE-0.215/t/07_aliased_assert.t0000644000175000001440000000324311746020426016716 0ustar torstenusers#!/usr/bin/env perl use strict; use warnings; use Test::More tests => 8; use Test::Fatal; { sub POE::Kernel::ASSERT_DEFAULT () { 1 } package Aliased; use MooseX::POE; with qw/MooseX::POE::Aliased/; has foo => ( is => 'rw', isa => 'Str', default => '' ); has bar => ( is => 'rw', isa => 'Int', default => 0 ); event 'ping' => sub { my $self = shift; ::pass( "received ping" ); # tell the master to send us another event! $self->alias( 'foobar' ); $poe_kernel->post( 'master', 'test_changed' ); }; event 'test_changed' => sub { my $self = shift; ::pass( "received test_changed" ); # send an event to the new alias $poe_kernel->post( 'foobar', 'ping2' ); ::is( $poe_kernel->alias_resolve( 'tester' ), undef, 'Old alias is really gone' ); }; event 'ping2' => sub { my $self = shift; ::pass( "received ping2" ); # remove our alias $self->alias( undef ); }; sub STARTALL { my $self = shift; # test sending an event to the other aliased session return unless defined $self->alias and $self->alias eq 'master'; $poe_kernel->post( 'tester', 'ping' ); } no MooseX::POE; } is( exception { Aliased->new( alias => 'tester' ) }, undef, 'can create Aliased with ASSERT_DEFAULT' ); is( exception { Aliased->new( alias => 'master' ) }, undef, 'can create Aliased with ASSERT_DEFAULT' ); is( exception { Aliased->new( alias => undef ) }, undef, 'can create no Aliased with ASSERT_DEFAULT' ); is( exception {POE::Kernel->run }, undef, 'The entire thing works :)' ); MooseX-POE-0.215/t/04_with_before_fixed.t0000644000175000001440000000100111746020426017372 0ustar torstenusersuse strict; use warnings; use Test::More tests => 3; { package Rollo; use MooseX::POE::Role; before foo => sub { ::pass('before foo'); }; } { package App; use MooseX::POE; sub START { ::pass('START'); $_[KERNEL]->yield('foo'); } event foo => sub { ::pass('foo'); print "BAR\n"; }; # notice how it passes if we place it here # while in 04_with_before.t it fails... :( with 'Rollo'; } App->new; POE::Kernel->run; MooseX-POE-0.215/t/06_sweet.t0000644000175000001440000000104011746020426015052 0ustar torstenusers#!/usr/bin/env perl use strict; use warnings; use Test::More tests => 3; { package Counter; use MooseX::POE::SweetArgs; has count => (is => 'rw', default => 1); sub START { my ($self) = @_; $self->yield(add => 5); } event add => sub { my ($self, $n) = @_; ::is(scalar @_, 2, 'correct number of args'); ::is($n, 5, 'got the right value'); $self->count( $self->count + $n ); }; no MooseX::POE::SweetArgs; } my $counter = Counter->new; POE::Kernel->run; is($counter->count, 6, 'correct final count'); MooseX-POE-0.215/t/11_regular_moose.t0000644000175000001440000000036311746020426016571 0ustar torstenusers#!/usr/bin/env perl use strict; use warnings; use Test::More tests => 1; { package Foo; use MooseX::POE; package Bar; use Moose; has a => ( is => 'ro' ); } ok(!exists Bar->new( a => 1 )->{session_id}, 'no session_id'); MooseX-POE-0.215/t/13_method_modifiers.t0000644000175000001440000000134311746020426017250 0ustar torstenusers#!/usr/bin/env perl use strict; use warnings; use Test::More tests => 6; { package Base; use MooseX::POE; sub START { ::pass('Base Start'); } event hello => sub { ::pass('hello'); $_[KERNEL]->yield('goodbye'); }; } { package Extended; use MooseX::POE; extends 'Base'; sub START { ::pass('Extended after Start'); $_[KERNEL]->yield( 'hello' => 'world' ); } before 'hello' => sub { ::is( $_[ARG0], 'world', 'before saw world' ); }; after 'hello' => sub { ::is( $_[ARG0], 'world', 'after saw world' ); }; event goodbye => sub { ::pass('goodbye'); }; } my $foo = Extended->new(); POE::Kernel->run(); MooseX-POE-0.215/t/04_with_before.t0000644000175000001440000000075511746020426016232 0ustar torstenusersuse strict; use warnings; use Test::More skip_all => 'Moose upstream needs to sort out composition'; use Test::More tests => 3; { package Rollo; use MooseX::POE::Role; before foo => sub { ::pass('before foo'); }; } { package App; use MooseX::POE; with 'Rollo'; sub START { ::pass('START'); $_[KERNEL]->yield('foo'); } event foo => sub { ::pass('foo'); print "BAR\n"; }; } App->new; POE::Kernel->run; MooseX-POE-0.215/t/07_aliased.t0000644000175000001440000000305011746020426015331 0ustar torstenusers#!/usr/bin/env perl use strict; use warnings; use Test::More tests => 6; use Test::Fatal; use POE; my @log; { package Foo; use MooseX::POE; with qw(MooseX::POE::Aliased); event foo => sub { push @log, [ @_[ ARG0 .. $#_ ] ]; }; } { package ImmutableFoo; use MooseX::POE; with qw(MooseX::POE::Aliased); event foo => sub { push @log, [ @_[ ARG0 .. $#_ ] ]; }; __PACKAGE__->meta->make_immutable( inline_constructor => 0 ); } my $foo = Foo->new( alias => "blah" ); POE::Session->create( inline_states => { _start => sub { $_[KERNEL]->yield("blah"); }, blah => sub { $_[KERNEL]->post( blah => foo => "this" ); $foo->alias("bar"); $_[KERNEL]->post( bar => foo => "that" ); }, } ); POE::Kernel->run; is( scalar(@log), 2, "two events" ); is_deeply( $log[0], ["this"], "first event under alias 'blah'" ); is_deeply( $log[1], ["that"], "second event under alias 'bar'" ); @log = (); $foo = ImmutableFoo->new( alias => "blah" ); POE::Session->create( inline_states => { _start => sub { $_[KERNEL]->yield("blah"); }, blah => sub { $_[KERNEL]->post( blah => foo => "this" ); $foo->alias("bar"); $_[KERNEL]->post( bar => foo => "that" ); }, } ); POE::Kernel->run; is( scalar(@log), 2, "two events" ); is_deeply( $log[0], ["this"], "first event under alias 'blah'" ); is_deeply( $log[1], ["that"], "second event under alias 'bar'" ); MooseX-POE-0.215/Changes0000644000175000001440000000673011746020426014274 0ustar torstenusersRevision history for MooseX-POE 0.215 2012-04-25 18:06:29 Europe/Berlin 0.214 2011-05-03 00:30:50 Europe/Berlin + Bumped versions for being more modern ;) (Getty) 0.213 2011-04-21 18:09:51 Europe/Berlin - Fix for a regression introduced with the removal of MooseX::POE::Meta::Trait::Constructor (BinGOs) 0.212 2011-04-02 20:53:13 Europe/Berlin - Fix for double BUILD (doy) 0.211 2010-12-05 22:17:17 America/New_York + Switched to Test::Fatal (perigrin) 0.210 2010-11-04 21:48:59 Europe/Berlin + Switched to Dist::Zilla for the author (Getty) 0.209 2010-09-26 + Remove useless call to ->_meta_instance (autarch) 0.208 2010-08-10 + Added new timer features (Getty) - Remove AutoInstall reference in Makefile.PL (Getty) 0.206 2010-07-27 - Avoid warnings with Moose 1.09 (Dave Rolsky) - fix CHILD and PARENT methods (xsawyerx) - various doc/example/test fixes (Avar, perigrin, Getty) 0.205 2009-06-26 - Fix inheritance of events (BinGOs) - Add tests (BinGOs) - Make sure that SENDER in START methods is correct (BinGOs) 0.204 2009-06-12 - remove auto_install at nothingmuch's request (perigrin) 0.203 2009-05-30 + Add stubbed documentation for metaclasses (perigrin) + Clean up aliased test to set inline_constructor => 0 (perigrin) + Update Makefile.PL to include AutoManifest and Repository (perigrin) + Clean out Object Deferred since it's been broken and nobody noticed (perigrin) 0.202 2009-05-11 + Change alias_method to add_method as that's not been deprecated (perigrin) + Clean up the SYNOPSIS a bit, the name attribute was useless. + Changes to keep constructor inlining working with latest Moose & Class::MOP. This module will still work with any Moose from 0.74 on up. 0.201 2009-04-02 + Document the hell out of MooseX::Declare weirdness (perigrin) + Update the rest of the documentation including authors and whatnot (perigrin) 0.200 2009-04-02 + Fairly substantial re-write of the internals (ash) + Made everything a Metaclass Role / Trait. This will break backwards compatibility with the previous method of using MooseX::POE::SweetArgs. (ash) + Now compatible with MooseX::Declare ... in theory ... with tests (ash) + Add example from the POE Cookbook (LordVorp) 0.100 2009-01-11 + Change to Moose::Exporter 0.090 2008-11-08 + add MANIFEST.SKIP - Remove OSX Files 0.080 2008-11-07 + add MooseX::POE::SweetArgs metaclass (hdp) + Sessions are no longer leaked because they are only referenced by ID (nothingmuch) + Add MooseX::POE::Role (nothingmuch) + Add MooseX::POE::Aliased role (nothingmuch) 0.070 2008-02-03 + attributes can now be weak_ref=>1 (rjbs) 0.060 2008-01-25 + START now get all the POE arguments again like they used to. (ash) 0.050 2008-01-22 + startup calls STARTALL, which calls all STARTS (like BUILDALL, etc.) (rjbs) + fix to the fix for MooseX::Daemonize skipping (Dave Rolsky) + fixing MooseX::Object::Deferred so that it brings in the right metaclass -- this feature is alpha and has 0 tests YMMV 0.0.4 2008-01-17 (functionally the same as 0.03) + Fix test to skip if MooseX::Daemonize not installed 0.0.3 2008-01-15 + fix Synopsis code to close bug #31432 (sproingie) 0.0.2 2007-10-23 + fix POD + fix tests 0.0.1 2007-10-11 16:58:27 America/New_York + Initial release. MooseX-POE-0.215/META.yml0000644000175000001440000001130411746020426014243 0ustar torstenusers--- abstract: 'The Illicit Love Child of Moose and POE' author: - 'Chris Prather ' - 'Ash Berlin ' - 'Chris Williams ' - 'Yuval (nothingmuch) Kogman' - 'Torsten Raudssus L' build_requires: Test::Fatal: 0.003 Test::More: 0.90 configure_requires: ExtUtils::MakeMaker: 6.30 dynamic_config: 0 generated_by: 'Dist::Zilla version 4.300014, CPAN::Meta::Converter version 2.120630' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 name: MooseX-POE no_index: directory: - ex requires: Moose: 2.0002 POE: 1.310 resources: homepage: https://github.com/perigrin/moosex-poe repository: git://github.com/perigrin/moosex-poe.git version: 0.215 x_Dist_Zilla: plugins: - class: Dist::Zilla::Plugin::Prereqs config: Dist::Zilla::Plugin::Prereqs: phase: runtime type: requires name: Prereqs version: 4.300014 - class: Dist::Zilla::Plugin::Prereqs config: Dist::Zilla::Plugin::Prereqs: phase: test type: requires name: TestRequires version: 4.300014 - class: Dist::Zilla::Plugin::GatherDir name: '@Basic/GatherDir' version: 4.300014 - class: Dist::Zilla::Plugin::PruneCruft name: '@Basic/PruneCruft' version: 4.300014 - class: Dist::Zilla::Plugin::ManifestSkip name: '@Basic/ManifestSkip' version: 4.300014 - class: Dist::Zilla::Plugin::MetaYAML name: '@Basic/MetaYAML' version: 4.300014 - class: Dist::Zilla::Plugin::License name: '@Basic/License' version: 4.300014 - class: Dist::Zilla::Plugin::Readme name: '@Basic/Readme' version: 4.300014 - class: Dist::Zilla::Plugin::ExtraTests name: '@Basic/ExtraTests' version: 4.300014 - class: Dist::Zilla::Plugin::ExecDir name: '@Basic/ExecDir' version: 4.300014 - class: Dist::Zilla::Plugin::ShareDir name: '@Basic/ShareDir' version: 4.300014 - class: Dist::Zilla::Plugin::MakeMaker name: '@Basic/MakeMaker' version: 4.300014 - class: Dist::Zilla::Plugin::Manifest name: '@Basic/Manifest' version: 4.300014 - class: Dist::Zilla::Plugin::TestRelease name: '@Basic/TestRelease' version: 4.300014 - class: Dist::Zilla::Plugin::ConfirmRelease name: '@Basic/ConfirmRelease' version: 4.300014 - class: Dist::Zilla::Plugin::UploadToCPAN name: '@Basic/UploadToCPAN' version: 4.300014 - class: Dist::Zilla::Plugin::Git::NextVersion name: Git::NextVersion version: 1.112510 - class: Dist::Zilla::Plugin::PkgVersion name: PkgVersion version: 4.300014 - class: Dist::Zilla::Plugin::MetaConfig name: MetaConfig version: 4.300014 - class: Dist::Zilla::Plugin::MetaJSON name: MetaJSON version: 4.300014 - class: Dist::Zilla::Plugin::NextRelease name: NextRelease version: 4.300014 - class: Dist::Zilla::Plugin::PodSyntaxTests name: PodSyntaxTests version: 4.300014 - class: Dist::Zilla::Plugin::GithubMeta name: GithubMeta version: 0.26 - class: Dist::Zilla::Plugin::PodWeaver name: PodWeaver version: 3.101641 - class: Dist::Zilla::Plugin::Repository name: Repository version: 0.18 - class: Dist::Zilla::Plugin::MetaNoIndex name: MetaNoIndex version: 4.300014 - class: Dist::Zilla::Plugin::Git::Check name: '@Git/Check' version: 1.112510 - class: Dist::Zilla::Plugin::Git::Commit name: '@Git/Commit' version: 1.112510 - class: Dist::Zilla::Plugin::Git::Tag name: '@Git/Tag' version: 1.112510 - class: Dist::Zilla::Plugin::Git::Push name: '@Git/Push' version: 1.112510 - class: Dist::Zilla::Plugin::FinderCode name: ':InstallModules' version: 4.300014 - class: Dist::Zilla::Plugin::FinderCode name: ':IncModules' version: 4.300014 - class: Dist::Zilla::Plugin::FinderCode name: ':TestFiles' version: 4.300014 - class: Dist::Zilla::Plugin::FinderCode name: ':ExecFiles' version: 4.300014 - class: Dist::Zilla::Plugin::FinderCode name: ':ShareFiles' version: 4.300014 - class: Dist::Zilla::Plugin::FinderCode name: ':MainModule' version: 4.300014 zilla: class: Dist::Zilla::Dist::Builder config: is_trial: 0 version: 4.300014 MooseX-POE-0.215/README0000644000175000001440000000055411746020426013657 0ustar torstenusers This archive contains the distribution MooseX-POE, version 0.215: The Illicit Love Child of Moose and POE This software is copyright (c) 2010 by Chris Prather, Ash Berlin, Chris Williams, Yuval Kogman, Torsten Raudssus. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. MooseX-POE-0.215/dist.ini0000644000175000001440000000131211746020426014434 0ustar torstenusersname = MooseX-POE author = Chris Prather author = Ash Berlin author = Chris Williams author = Yuval (nothingmuch) Kogman author = Torsten Raudssus L license = Perl_5 copyright_holder = Chris Prather, Ash Berlin, Chris Williams, Yuval Kogman, Torsten Raudssus copyright_year = 2010 [Prereqs] Moose = 2.0002 POE = 1.310 [Prereqs / TestRequires] Test::More = 0.90 Test::Fatal = 0.003 [@Basic] [Git::NextVersion] version_regexp = ^(.+)$ [PkgVersion] [MetaConfig] [MetaJSON] [NextRelease] [PodSyntaxTests] [GithubMeta] [PodWeaver] [Repository] [MetaNoIndex] directory = ex [@Git] tag_format = %v MooseX-POE-0.215/META.json0000644000175000001440000001644711746020426014430 0ustar torstenusers{ "abstract" : "The Illicit Love Child of Moose and POE", "author" : [ "Chris Prather ", "Ash Berlin ", "Chris Williams ", "Yuval (nothingmuch) Kogman", "Torsten Raudssus L" ], "dynamic_config" : 0, "generated_by" : "Dist::Zilla version 4.300014, CPAN::Meta::Converter version 2.120630", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "MooseX-POE", "no_index" : { "directory" : [ "ex" ] }, "prereqs" : { "configure" : { "requires" : { "ExtUtils::MakeMaker" : "6.30" } }, "runtime" : { "requires" : { "Moose" : "2.0002", "POE" : "1.310" } }, "test" : { "requires" : { "Test::Fatal" : "0.003", "Test::More" : "0.90" } } }, "release_status" : "stable", "resources" : { "homepage" : "https://github.com/perigrin/moosex-poe", "repository" : { "type" : "git", "url" : "git://github.com/perigrin/moosex-poe.git", "web" : "http://github.com/perigrin/moosex-poe" } }, "version" : "0.215", "x_Dist_Zilla" : { "plugins" : [ { "class" : "Dist::Zilla::Plugin::Prereqs", "config" : { "Dist::Zilla::Plugin::Prereqs" : { "phase" : "runtime", "type" : "requires" } }, "name" : "Prereqs", "version" : "4.300014" }, { "class" : "Dist::Zilla::Plugin::Prereqs", "config" : { "Dist::Zilla::Plugin::Prereqs" : { "phase" : "test", "type" : "requires" } }, "name" : "TestRequires", "version" : "4.300014" }, { "class" : "Dist::Zilla::Plugin::GatherDir", "name" : "@Basic/GatherDir", "version" : "4.300014" }, { "class" : "Dist::Zilla::Plugin::PruneCruft", "name" : "@Basic/PruneCruft", "version" : "4.300014" }, { "class" : "Dist::Zilla::Plugin::ManifestSkip", "name" : "@Basic/ManifestSkip", "version" : "4.300014" }, { "class" : "Dist::Zilla::Plugin::MetaYAML", "name" : "@Basic/MetaYAML", "version" : "4.300014" }, { "class" : "Dist::Zilla::Plugin::License", "name" : "@Basic/License", "version" : "4.300014" }, { "class" : "Dist::Zilla::Plugin::Readme", "name" : "@Basic/Readme", "version" : "4.300014" }, { "class" : "Dist::Zilla::Plugin::ExtraTests", "name" : "@Basic/ExtraTests", "version" : "4.300014" }, { "class" : "Dist::Zilla::Plugin::ExecDir", "name" : "@Basic/ExecDir", "version" : "4.300014" }, { "class" : "Dist::Zilla::Plugin::ShareDir", "name" : "@Basic/ShareDir", "version" : "4.300014" }, { "class" : "Dist::Zilla::Plugin::MakeMaker", "name" : "@Basic/MakeMaker", "version" : "4.300014" }, { "class" : "Dist::Zilla::Plugin::Manifest", "name" : "@Basic/Manifest", "version" : "4.300014" }, { "class" : "Dist::Zilla::Plugin::TestRelease", "name" : "@Basic/TestRelease", "version" : "4.300014" }, { "class" : "Dist::Zilla::Plugin::ConfirmRelease", "name" : "@Basic/ConfirmRelease", "version" : "4.300014" }, { "class" : "Dist::Zilla::Plugin::UploadToCPAN", "name" : "@Basic/UploadToCPAN", "version" : "4.300014" }, { "class" : "Dist::Zilla::Plugin::Git::NextVersion", "name" : "Git::NextVersion", "version" : "1.112510" }, { "class" : "Dist::Zilla::Plugin::PkgVersion", "name" : "PkgVersion", "version" : "4.300014" }, { "class" : "Dist::Zilla::Plugin::MetaConfig", "name" : "MetaConfig", "version" : "4.300014" }, { "class" : "Dist::Zilla::Plugin::MetaJSON", "name" : "MetaJSON", "version" : "4.300014" }, { "class" : "Dist::Zilla::Plugin::NextRelease", "name" : "NextRelease", "version" : "4.300014" }, { "class" : "Dist::Zilla::Plugin::PodSyntaxTests", "name" : "PodSyntaxTests", "version" : "4.300014" }, { "class" : "Dist::Zilla::Plugin::GithubMeta", "name" : "GithubMeta", "version" : "0.26" }, { "class" : "Dist::Zilla::Plugin::PodWeaver", "name" : "PodWeaver", "version" : "3.101641" }, { "class" : "Dist::Zilla::Plugin::Repository", "name" : "Repository", "version" : "0.18" }, { "class" : "Dist::Zilla::Plugin::MetaNoIndex", "name" : "MetaNoIndex", "version" : "4.300014" }, { "class" : "Dist::Zilla::Plugin::Git::Check", "name" : "@Git/Check", "version" : "1.112510" }, { "class" : "Dist::Zilla::Plugin::Git::Commit", "name" : "@Git/Commit", "version" : "1.112510" }, { "class" : "Dist::Zilla::Plugin::Git::Tag", "name" : "@Git/Tag", "version" : "1.112510" }, { "class" : "Dist::Zilla::Plugin::Git::Push", "name" : "@Git/Push", "version" : "1.112510" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":InstallModules", "version" : "4.300014" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":IncModules", "version" : "4.300014" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":TestFiles", "version" : "4.300014" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":ExecFiles", "version" : "4.300014" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":ShareFiles", "version" : "4.300014" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":MainModule", "version" : "4.300014" } ], "zilla" : { "class" : "Dist::Zilla::Dist::Builder", "config" : { "is_trial" : "0" }, "version" : "4.300014" } } } MooseX-POE-0.215/lib/0000755000175000001440000000000011746020426013541 5ustar torstenusersMooseX-POE-0.215/lib/MooseX/0000755000175000001440000000000011746020426014753 5ustar torstenusersMooseX-POE-0.215/lib/MooseX/POE/0000755000175000001440000000000011746020426015376 5ustar torstenusersMooseX-POE-0.215/lib/MooseX/POE/Role.pm0000644000175000001440000000342711746020426016643 0ustar torstenuserspackage MooseX::POE::Role; { $MooseX::POE::Role::VERSION = '0.215'; } # ABSTRACT: Eventful roles use MooseX::POE::Meta::Role; use Moose::Exporter; my ( $import, $unimport, $init_meta ) = Moose::Exporter->setup_import_methods( with_caller => [qw(event)], also => 'Moose::Role', install => [qw(import unimport)], role_metaroles => { role => ['MooseX::POE::Meta::Role'], }, ); sub init_meta { my ( $class, %args ) = @_; my $for = $args{for_class}; eval qq{package $for; use POE; }; Moose::Role->init_meta( for_class => $for ); goto $init_meta; } sub event { my ( $caller, $name, $method ) = @_; my $class = Moose::Meta::Class->initialize($caller); $class->add_state_method( $name => $method ); } 1; =pod =head1 NAME MooseX::POE::Role - Eventful roles =head1 VERSION version 0.215 =head1 SYNOPSIS package Counter; use MooseX::POE::Role; ... package RealCounter; with qw(Counter); =head1 DESCRIPTION This is what L is to Moose but with L. =head1 METHODS =head2 event $name $subref Create an event handler named $name. =head1 KEYWORDS =for :list * L * L =head1 AUTHORS =over 4 =item * Chris Prather =item * Ash Berlin =item * Chris Williams =item * Yuval (nothingmuch) Kogman =item * Torsten Raudssus L =back =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2010 by Chris Prather, Ash Berlin, Chris Williams, Yuval Kogman, Torsten Raudssus. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut __END__ MooseX-POE-0.215/lib/MooseX/POE/Aliased.pm0000644000175000001440000000477411746020426017312 0ustar torstenuserspackage MooseX::POE::Aliased; { $MooseX::POE::Aliased::VERSION = '0.215'; } # ABSTRACT: A sane alias attribute for your MooseX::POE objects. use MooseX::POE::Role; use overload (); use POE; has alias => ( isa => "Maybe[Str]", is => "rw", builder => "_build_alias", clearer => "clear_alias", predicate => "has_alias", trigger => sub { my ( $self, $alias ) = @_; # we cannot set the alias UNTIL we construct the object! # or ASSERT_DEFAULT will complain... return unless defined $self->get_session_id; $self->call( _update_alias => $alias ); } ); before 'STARTALL' => sub { my ($self) = @_; $self->call( _update_alias => $self->alias ) if $self->has_alias; }; sub _build_alias { my $self = shift; overload::StrVal($self); } event _update_alias => sub { my ( $kernel, $self, $alias ) = @_[KERNEL, OBJECT, ARG0]; # we need to remove the prev alias like this because we don't know the # previous value. $kernel->alias_remove($_) for $kernel->alias_list( $self->get_session_id ); $kernel->alias_set($alias) if defined $alias; return; }; __PACKAGE__; =pod =head1 NAME MooseX::POE::Aliased - A sane alias attribute for your MooseX::POE objects. =head1 VERSION version 0.215 =head1 SYNOPSIS use MooseX::POE; with qw(MooseX::POE::Aliased); my $obj = Foo->new( alias => "blah" ); $obj->alias("arf"); # previous one is removed, new one is set $obj->alias(undef); # no alias set =head1 DESCRIPTION This role provides an C attribute for your L objects. The attribute can be set, causing the current alias to be cleared and the new value to be set. =head1 METHODS =head2 alias The alias to set for the session. Defaults to the C of the object. If the value is set at runtime the alias will be updated in the L. A value of C inhibits aliasing. =head1 ATTRIBUTES =head1 AUTHORS =over 4 =item * Chris Prather =item * Ash Berlin =item * Chris Williams =item * Yuval (nothingmuch) Kogman =item * Torsten Raudssus L =back =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2010 by Chris Prather, Ash Berlin, Chris Williams, Yuval Kogman, Torsten Raudssus. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut __END__ MooseX-POE-0.215/lib/MooseX/POE/Meta/0000755000175000001440000000000011746020426016264 5ustar torstenusersMooseX-POE-0.215/lib/MooseX/POE/Meta/Role.pm0000644000175000001440000000232411746020426017524 0ustar torstenuserspackage MooseX::POE::Meta::Role; { $MooseX::POE::Meta::Role::VERSION = '0.215'; } # ABSTRACT: Pay no attention to this. use Moose::Role; with qw(MooseX::POE::Meta::Trait); around default_events => sub { my ( $orig, $self ) = @_; my $events = $orig->($self); push @$events, grep { s/^on_(\w+)/$1/; } $self->get_method_list; return $events; }; around get_state_method_name => sub { my ( $orig, $self, $name ) = @_; return 'on_' . $name if $self->has_method( 'on_' . $name ); return $orig->( $self, $name ); }; no Moose::Role; 1; __END__ =pod =head1 NAME MooseX::POE::Meta::Role - Pay no attention to this. =head1 VERSION version 0.215 =head1 AUTHORS =over 4 =item * Chris Prather =item * Ash Berlin =item * Chris Williams =item * Yuval (nothingmuch) Kogman =item * Torsten Raudssus L =back =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2010 by Chris Prather, Ash Berlin, Chris Williams, Yuval Kogman, Torsten Raudssus. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut MooseX-POE-0.215/lib/MooseX/POE/Meta/Trait/0000755000175000001440000000000011746020426017347 5ustar torstenusersMooseX-POE-0.215/lib/MooseX/POE/Meta/Trait/Class.pm0000644000175000001440000000436311746020426020760 0ustar torstenuserspackage MooseX::POE::Meta::Trait::Class; { $MooseX::POE::Meta::Trait::Class::VERSION = '0.215'; } # ABSTRACT: No achmed inside use Moose::Role; with qw(MooseX::POE::Meta::Trait); # TODO: subclass events to be a hashref that maps the event to the method # so we can support on_ events around default_events => sub { my ( $next, $self ) = @_; my $events = $next->($self); push @$events, grep { s/^on_(\w+)/$1/; } $self->get_method_list; return $events; }; around add_role => sub { my ( $next, $self, $role ) = @_; $next->( $self, $role ); if ( $role->meta->can('does_role') && $role->meta->does_role("MooseX::POE::Meta::Trait") ) { $self->add_event( $role->get_events ); } }; around get_state_method_name => sub { my ( $next, $self, $name ) = @_; return 'on_' . $name if $self->has_method( 'on_' . $name ); return $next->( $self, $name ); }; sub get_all_events { my ($self) = @_; my $wanted_role = 'MooseX::POE::Meta::Trait'; # This horrible grep can be removed once Moose gets more metacircular. # Currently Moose::Meta::Class->meta isn't a MMC. It should be, and it # should also be a Moose::Object so does works on it. my %events = map { my $m = $_; map { $_ => $m->get_state_method_name($_) } $m->get_events } grep { $_->meta->can('does_role') && $_->meta->does_role($wanted_role) } map { $_->meta } $self->linearized_isa; return %events; } no Moose::Role; 1; =pod =head1 NAME MooseX::POE::Meta::Trait::Class - No achmed inside =head1 VERSION version 0.215 =head1 METHODS =head2 get_all_events =head1 METHODS =head1 DEPENDENCIES Moose::Role =head1 AUTHORS =over 4 =item * Chris Prather =item * Ash Berlin =item * Chris Williams =item * Yuval (nothingmuch) Kogman =item * Torsten Raudssus L =back =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2010 by Chris Prather, Ash Berlin, Chris Williams, Yuval Kogman, Torsten Raudssus. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut __END__ MooseX-POE-0.215/lib/MooseX/POE/Meta/Trait/Object.pm0000644000175000001440000001271411746020426021120 0ustar torstenuserspackage MooseX::POE::Meta::Trait::Object; { $MooseX::POE::Meta::Trait::Object::VERSION = '0.215'; } # ABSTRACT: The base class role for MooseX::POE use Moose::Role; use POE::Session; sub BUILD { my $self = shift; my $session = POE::Session->create( inline_states => { _start => sub { POE::Kernel->yield('STARTALL', \$_[5] ) }, }, object_states => [ $self => { $self->meta->get_all_events, STARTALL => 'STARTALL', _stop => 'STOPALL', _child => 'CHILD', _parent => 'PARENT', _call_kernel_with_my_session => '_call_kernel_with_my_session', }, ], args => [$self], heap => ( $self->{heap} ||= {} ), ); $self->{session_id} = $session->ID; } sub get_session_id { my ($self) = @_; return $self->meta->get_meta_instance->get_session_id($self); } sub yield { my $self = shift; POE::Kernel->post( $self->get_session_id, @_ ) } sub call { my $self = shift; POE::Kernel->call( $self->get_session_id, @_ ) } sub _call_kernel_with_my_session { my ( $self, $function, @args ) = @_[ OBJECT, ARG0..$#_ ]; POE::Kernel->$function( @args ); } sub delay { my $self = shift; $self->call( _call_kernel_with_my_session => 'delay' => @_ ) } sub alarm { my $self = shift; $self->call( _call_kernel_with_my_session => 'alarm', @_ ) } sub alarm_add { my $self = shift; $self->call( _call_kernel_with_my_session => 'alarm_add', @_ ) } sub delay_add { my $self = shift; $self->call( _call_kernel_with_my_session => 'delay_add', @_ ) } sub alarm_set { my $self = shift; $self->call( _call_kernel_with_my_session => 'alarm_set', @_ ) } sub alarm_adjust { my $self = shift; $self->call( _call_kernel_with_my_session => 'alarm_adjust', @_ ) } sub alarm_remove { my $self = shift; $self->call( _call_kernel_with_my_session => 'alarm_remove', @_ ) } sub alarm_remove_all { my $self = shift; $self->call( _call_kernel_with_my_session => 'alarm_remove_all', @_ ) } sub delay_set { my $self = shift; $self->call( _call_kernel_with_my_session => 'delay_set', @_ ) } sub delay_adjust { my $self = shift; $self->call( _call_kernel_with_my_session => 'delay_adjust', @_ ) } sub STARTALL { my ( $self, @params ) = @_; $params[4] = pop @params; foreach my $method ( reverse $self->meta->find_all_methods_by_name('START') ) { $method->{code}->( $self, @params ); } } sub STOPALL { my ( $self, $params ) = @_; foreach my $method ( reverse $self->meta->find_all_methods_by_name('STOP') ) { $method->{code}->( $self, $params ); } } sub START { } sub STOP { } sub CHILD { } sub PARENT { } # __PACKAGE__->meta->add_method( _stop => sub { POE::Kernel->call('STOP') } ); __PACKAGE__->meta->add_method( _default => __PACKAGE__->meta->get_method('DEFAULT') ) if __PACKAGE__->meta->has_method('DEFAULT'); __PACKAGE__->meta->add_method( _child => __PACKAGE__->meta->get_method('CHILD') ) if __PACKAGE__->meta->has_method('CHILD'); __PACKAGE__->meta->add_method( _parent => __PACKAGE__->meta->get_method('PARENT') ) if __PACKAGE__->meta->has_method('PARENT'); no Moose::Role; 1; =pod =head1 NAME MooseX::POE::Meta::Trait::Object - The base class role for MooseX::POE =head1 VERSION version 0.215 =head1 SYNOPSIS package Counter; use MooseX::Poe; has name => ( isa => 'Str', is => 'rw', default => sub { 'Foo ' }, ); has count => ( isa => 'Int', is => 'rw', lazy => 1, default => sub { 0 }, ); sub START { my ($self) = @_; $self->yield('increment'); } sub increment { my ($self) = @_; $self->count( $self->count + 1 ); $self->yield('increment') unless $self->count > 3; } no MooseX::Poe; =head1 DESCRIPTION MooseX::POE::Meta::TraitObject is a role that is applied to the object base classe (usually Moose::Object) that implements a POE::Session. =head1 METHODS =head2 get_session_id Get the internal POE Session ID, this is useful to hand to other POE aware functions. =head2 yield =head2 call =head2 delay =head2 alarm =head2 alarm_add =head2 delay_add =head2 alarm_set =head2 alarm_adjust =head2 alarm_remove =head2 alarm_remove_all =head2 delay_set =head2 delay_adjust A cheap alias for the same POE::Kernel function which will gurantee posting to the object's session. =head2 STARTALL Along similar lines to Moose's C method which calls all the C methods, this function will call all the C methods in your inheritance hierarchy automatically when POE first runs your session. (This corresponds to the C<_start> event from POE.) =head2 STOPALL Along similar lines to C, but for C instead. =head2 START =head2 STOP =head2 DEFAULT =head2 CHILD =head2 PARENT =head1 DEFAULT METHODS =head1 PREDEFINED EVENTS =head1 AUTHORS =over 4 =item * Chris Prather =item * Ash Berlin =item * Chris Williams =item * Yuval (nothingmuch) Kogman =item * Torsten Raudssus L =back =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2010 by Chris Prather, Ash Berlin, Chris Williams, Yuval Kogman, Torsten Raudssus. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut __END__ MooseX-POE-0.215/lib/MooseX/POE/Meta/Trait/SweetArgs.pm0000644000175000001440000000240411746020426021611 0ustar torstenuserspackage MooseX::POE::Meta::Trait::SweetArgs; { $MooseX::POE::Meta::Trait::SweetArgs::VERSION = '0.215'; } # ABSTRACT: Yes, its a trap... i mean trait use Moose::Role; around add_state_method => sub { my $orig = shift; my ($self, $name, $method) = @_; $orig->($self, $name, sub { $method->(@_[POE::Session::OBJECT(), POE::Session::ARG0()..$#_]) }); }; no Moose::Role; 1; =pod =head1 NAME MooseX::POE::Meta::Trait::SweetArgs - Yes, its a trap... i mean trait =head1 VERSION version 0.215 =head1 SYNOPSIS use MooseX::POE::Meta::Trait::SweetArgs; =head1 DESCRIPTION The MooseX::POE::Meta::Trait::SweetArgs class implements ... =head1 SUBROUTINES / METHODS There are no public methods. =head1 AUTHORS =over 4 =item * Chris Prather =item * Ash Berlin =item * Chris Williams =item * Yuval (nothingmuch) Kogman =item * Torsten Raudssus L =back =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2010 by Chris Prather, Ash Berlin, Chris Williams, Yuval Kogman, Torsten Raudssus. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut __END__ MooseX-POE-0.215/lib/MooseX/POE/Meta/Trait/Instance.pm0000644000175000001440000000433511746020426021456 0ustar torstenuserspackage MooseX::POE::Meta::Trait::Instance; { $MooseX::POE::Meta::Trait::Instance::VERSION = '0.215'; } # ABSTRACT: A Instance Metaclass for MooseX::POE use Moose::Role; use POE; use Scalar::Util (); sub get_session_id { my ( $self, $instance ) = @_; return $instance->{session_id}; } sub get_slot_value { my ( $self, $instance, $slot_name ) = @_; return $instance->{heap}{$slot_name}; } sub set_slot_value { my ( $self, $instance, $slot_name, $value ) = @_; $instance->{heap}{$slot_name} = $value; } sub is_slot_initialized { my ( $self, $instance, $slot_name, $value ) = @_; exists $instance->{heap}{$slot_name} ? 1 : 0; } sub weaken_slot_value { my ( $self, $instance, $slot_name ) = @_; Scalar::Util::weaken( $instance->{heap}{$slot_name} ); } sub inline_slot_access { my ( $self, $instance, $slot_name ) = @_; sprintf '%s->{heap}{%s}', $instance, $slot_name; } no POE; no Moose::Role; 1; =pod =head1 NAME MooseX::POE::Meta::Trait::Instance - A Instance Metaclass for MooseX::POE =head1 VERSION version 0.215 =head1 SYNOPSIS Moose::Util::MetaRole::apply_metaclass_roles( for_class => $for_class, metaclass_roles => [ 'MooseX::POE::Meta::Trait::Class' ], instance_metaclass_roles => [ 'MooseX::POE::Meta::Trait::Instance', ], ); =head1 DESCRIPTION A metaclass for MooseX::POE. This module is only of use to developers so there is no user documentation provided. =head1 METHODS =head2 create_instance =head2 get_slot_value =head2 inline_slot_access =head2 is_slot_initialized =head2 set_slot_value =head2 weaken_slot_value =head2 get_session_id =head1 METHODS =head1 AUTHORS =over 4 =item * Chris Prather =item * Ash Berlin =item * Chris Williams =item * Yuval (nothingmuch) Kogman =item * Torsten Raudssus L =back =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2010 by Chris Prather, Ash Berlin, Chris Williams, Yuval Kogman, Torsten Raudssus. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut __END__ MooseX-POE-0.215/lib/MooseX/POE/Meta/Method/0000755000175000001440000000000011746020426017504 5ustar torstenusersMooseX-POE-0.215/lib/MooseX/POE/Meta/Method/State.pm0000644000175000001440000000161311746020426021123 0ustar torstenuserspackage MooseX::POE::Meta::Method::State; { $MooseX::POE::Meta::Method::State::VERSION = '0.215'; } # ABSTRACT: Dont look into this, its boring use strict; use Moose; extends qw(Moose::Meta::Method); no Moose; 1; =pod =head1 NAME MooseX::POE::Meta::Method::State - Dont look into this, its boring =head1 VERSION version 0.215 =head1 AUTHORS =over 4 =item * Chris Prather =item * Ash Berlin =item * Chris Williams =item * Yuval (nothingmuch) Kogman =item * Torsten Raudssus L =back =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2010 by Chris Prather, Ash Berlin, Chris Williams, Yuval Kogman, Torsten Raudssus. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut __END__ MooseX-POE-0.215/lib/MooseX/POE/Meta/Trait.pm0000644000175000001440000000335411746020426017712 0ustar torstenuserspackage MooseX::POE::Meta::Trait; { $MooseX::POE::Meta::Trait::VERSION = '0.215'; } # ABSTRACT: There be dragons here. use Moose::Role; use MooseX::POE::Meta::Method::State; has events => ( reader => 'get_events', traits => ['Array'], isa => 'ArrayRef', auto_deref => 1, lazy_build => 1, builder => 'default_events', handles => { 'add_event' => ['push'] }, ); sub default_events { return []; } sub get_state_method_name { my ( $self, $name ) = @_; return $name if $self->has_method($name); return undef; } sub add_state_method { my ( $self, $name, $method ) = @_; if ( $self->has_method($name) ) { my $full_name = $self->get_method($name)->fully_qualified_name; confess "Cannot add a state method ($name) if a local method ($full_name) is already present"; } $self->add_event($name); $self->add_method( $name => $method ); } after add_role => sub { my ( $self, $role ) = @_; if ( $role->isa("MooseX::POE::Meta::Role") ) { $self->add_event( $role->get_events ); } }; 1; __END__ =pod =head1 NAME MooseX::POE::Meta::Trait - There be dragons here. =head1 VERSION version 0.215 =head1 AUTHORS =over 4 =item * Chris Prather =item * Ash Berlin =item * Chris Williams =item * Yuval (nothingmuch) Kogman =item * Torsten Raudssus L =back =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2010 by Chris Prather, Ash Berlin, Chris Williams, Yuval Kogman, Torsten Raudssus. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut MooseX-POE-0.215/lib/MooseX/POE/SweetArgs.pm0000644000175000001440000000376511746020426017653 0ustar torstenuserspackage MooseX::POE::SweetArgs; { $MooseX::POE::SweetArgs::VERSION = '0.215'; } # ABSTRACT: sugar around MooseX::POE event arguments use Moose (); use MooseX::POE; use Moose::Exporter; Moose::Exporter->setup_import_methods( also => 'MooseX::POE', ); sub init_meta { my ($class, %args) = @_; MooseX::POE->import({ into => $args{for_class} }); Moose::Util::MetaRole::apply_metaroles( for => $args{for_class}, class_metaroles => { class => ['MooseX::POE::Meta::Trait::SweetArgs'], }, ); } 1; =pod =head1 NAME MooseX::POE::SweetArgs - sugar around MooseX::POE event arguments =head1 VERSION version 0.215 =head1 SYNOPSIS package Thing; use MooseX::POE::SweetArgs; # declare events like usual event on_success => sub { # unpack args like a Perl sub, not a POE event my ($self, $foo, $bar) = @_; ... POE::Kernel->yield('foo'); ... }; =head1 DESCRIPTION Normally, when using MooseX::POE, subs declared as events need to use POE macros for unpacking C<@_>, e.g.: my ($self, $foo, $bar) = @_[OBJECT, ARG0..$#_]; Using MooseX::POE::SweetArgs as a metaclass lets you avoid this, and just use C<@_> as normal: my ($self, $foo, $bar) = @_; Since the POE kernel is a singleton, you can access it using class methods, as shown in the synopsis. In all other respects, this behaves exactly like MooseX::POE =for :list * L =head1 AUTHORS =over 4 =item * Chris Prather =item * Ash Berlin =item * Chris Williams =item * Yuval (nothingmuch) Kogman =item * Torsten Raudssus L =back =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2010 by Chris Prather, Ash Berlin, Chris Williams, Yuval Kogman, Torsten Raudssus. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut __END__ MooseX-POE-0.215/lib/MooseX/POE.pm0000644000175000001440000001211211746020426015731 0ustar torstenuserspackage MooseX::POE; { $MooseX::POE::VERSION = '0.215'; } # ABSTRACT: The Illicit Love Child of Moose and POE use Moose (); use Moose::Exporter; my ( $import, $unimport, $init_meta ) = Moose::Exporter->setup_import_methods( with_caller => [qw(event)], also => 'Moose', install => [qw(import unimport)], class_metaroles => { class => ['MooseX::POE::Meta::Trait::Class'], instance => ['MooseX::POE::Meta::Trait::Instance'], }, base_class_roles => ['MooseX::POE::Meta::Trait::Object'], ); sub init_meta { my ( $class, %args ) = @_; my $for = $args{for_class}; eval qq{package $for; use POE; }; Moose->init_meta( for_class => $for ); goto $init_meta; } sub event { my ( $caller, $name, $method ) = @_; my $class = Moose::Meta::Class->initialize($caller); $class->add_state_method( $name => $method ); } 1; =pod =head1 NAME MooseX::POE - The Illicit Love Child of Moose and POE =head1 VERSION version 0.215 =head1 SYNOPSIS package Counter; use MooseX::POE; has count => ( isa => 'Int', is => 'rw', lazy => 1, default => sub { 0 }, ); sub START { my ($self) = @_; $self->yield('increment'); } event increment => sub { my ($self) = @_; print "Count is now " . $self->count . "\n"; $self->count( $self->count + 1 ); $self->yield('increment') unless $self->count > 3; }; no MooseX::POE; Counter->new(); POE::Kernel->run(); or with L: class Counter { use MooseX::POE::SweetArgs qw(event); has count => ( isa => 'Int', is => 'rw', lazy => 1, default => sub { 0 }, ); sub START { my ($self) = @_; $self->yield('increment') } event increment => sub { my ($self) = @_; print "Count is now " . $self->count . "\n"; $self->count( $self->count + 1 ); $self->yield('increment') unless $self->count > 3; } } Counter->new(); POE::Kernel->run(); =head1 DESCRIPTION MooseX::POE is a L wrapper around a L. =head1 METHODS =head2 event $name $subref Create an event handler named $name. =head2 get_session_id Get the internal POE Session ID, this is useful to hand to other POE aware functions. =head2 yield =head2 call =head2 delay =head2 alarm =head2 alarm_add =head2 delay_add =head2 alarm_set =head2 alarm_adjust =head2 alarm_remove =head2 alarm_remove_all =head2 delay_set =head2 delay_adjust A cheap alias for the same POE::Kernel function which will gurantee posting to the object's session. =head2 STARTALL =head2 STOPALL =head1 KEYWORDS =head1 METHODS Default POE-related methods are provided by L which is applied to your base class (which is usually L) when you use this module. See that module for the documentation for. Below is a list of methods on that class so you know what to look for: =head1 NOTES ON USAGE WITH L L support is still "experimental". Meaning that I don't use it, I don't have any code that uses it, and thus I can't adequately say that it won't cause monkeys to fly out of any orifices on your body beyond what the tests and the SYNOPSIS cover. That said there are a few caveats that have turned up during testing. 1. The C keyword doesn't seem to work as expected. This is an integration issue that is being resolved but I want to wait for L to gain some more polish on their slurpy arguments. 2. MooseX::POE attempts to re-export L, which L has already exported in a custom fashion. This means that you'll get a keyword clash between the features that L handles for you and the features that Moose handles. To work around this you'll need to write: use MooseX::POE qw(event); # or use MooseX::POE::SweetArgs qw(event); # or use MooseX::POE::Role qw(event); to keep MooseX::POE from exporting the sugar that L doesn't like. This is fixed in the Git version of L but that version (as of this writing) is not on the CPAN. =head1 SEE ALSO =for :list * L * L =head1 AUTHORS =over 4 =item * Chris Prather =item * Ash Berlin =item * Chris Williams =item * Yuval (nothingmuch) Kogman =item * Torsten Raudssus L =back =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2010 by Chris Prather, Ash Berlin, Chris Williams, Yuval Kogman, Torsten Raudssus. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut __END__ MooseX-POE-0.215/Makefile.PL0000644000175000001440000000233011746020426014743 0ustar torstenusers use strict; use warnings; use ExtUtils::MakeMaker 6.30; my %WriteMakefileArgs = ( "ABSTRACT" => "The Illicit Love Child of Moose and POE", "AUTHOR" => "Chris Prather , Ash Berlin , Chris Williams , Yuval (nothingmuch) Kogman, Torsten Raudssus L", "BUILD_REQUIRES" => { "Test::Fatal" => "0.003", "Test::More" => "0.90" }, "CONFIGURE_REQUIRES" => { "ExtUtils::MakeMaker" => "6.30" }, "DISTNAME" => "MooseX-POE", "EXE_FILES" => [], "LICENSE" => "perl", "NAME" => "MooseX::POE", "PREREQ_PM" => { "Moose" => "2.0002", "POE" => "1.310" }, "VERSION" => "0.215", "test" => { "TESTS" => "t/*.t" } ); unless ( eval { ExtUtils::MakeMaker->VERSION(6.56) } ) { my $br = delete $WriteMakefileArgs{BUILD_REQUIRES}; my $pp = $WriteMakefileArgs{PREREQ_PM}; for my $mod ( keys %$br ) { if ( exists $pp->{$mod} ) { $pp->{$mod} = $br->{$mod} if $br->{$mod} > $pp->{$mod}; } else { $pp->{$mod} = $br->{$mod}; } } } delete $WriteMakefileArgs{CONFIGURE_REQUIRES} unless eval { ExtUtils::MakeMaker->VERSION(6.52) }; WriteMakefile(%WriteMakefileArgs); MooseX-POE-0.215/bench/0000755000175000001440000000000011746020426014052 5ustar torstenusersMooseX-POE-0.215/bench/moose.forkbomb.pl0000644000175000001440000000555611746020426017344 0ustar torstenusers#!/usr/bin/env perl -l use strict; my $count = 0; my $max_sessions = 800; my $half_sessions = int( $max_sessions / 2 ); my %english = ( lose => 'is losing', gain => 'is gaining', create => 'has created' ); # this is based on the forkbomb.perl example that comes with POE # please check it out for better documentation { package ForkBomber; use MooseX::POE; has id => ( isa => 'Str', is => 'ro', default => sub { $count++ }, ); sub START { $_[0]->yield('fork'); $poe_kernel->sig( 'INT', 'on_signal_handler' ); $poe_kernel->sig( 'ZOMBIE', 'on_signal_handler' ); print 'Started ' . $_[0]->id; } sub STOP { print 'stopped ' . $_[OBJECT]->id; } sub CHILD { my ( $kernel, $self, $direction, $child, $return ) = @_[ KERNEL, OBJECT, ARG0, ARG1, ARG2 ]; print printf( "%4d %s child %s%s\n", $self->id, $english{$direction}, $kernel->call( $child, 'on_fetch_id' ), ( ( $direction eq 'create' ) ? (" (child returned: $return)") : '' ) ); } sub PARENT { my ( $kernel, $self, $old_parent, $new_parent ) = @_[ KERNEL, OBJECT, ARG0, ARG1 ]; print printf( "%4d parent is changing from %d to %d\n", $self->id, $poe_kernel->call( $old_parent, 'on_fetch_id' ), $poe_kernel->call( $new_parent, 'on_fetch_id' ) ); } event signal_handler => sub { my ( $self, $signal_name ) = @_[ OBJECT, ARG0 ]; print printf( "%4d has received SIG%s\n", $self->id, $signal_name ); # tell Kernel that this wasn't handled return 0; }; event fork => sub { my ( $kernel, $self ) = @_[ KERNEL, OBJECT ]; if ( $count < $max_sessions ) { if ( rand() < 0.5 ) { print $self->id . " is starting a new child..."; ForkBomber->new; } # tails == don't spawn else { print $self->id . " is just spinning its wheels this time..."; } if ( ( $count < $half_sessions ) || ( rand() < 0.05 ) ) { $poe_kernel->yield('fork'); } else { print $self->id . " has decided to die. Bye!"; if ( $self->id != 1 ) { $poe_kernel->yield('_stop'); } } } else { print $self->id . " notes that the session limit is met. Bye!"; # Please see the two NOTEs above. if ( $self->id != 1 ) { $poe_kernel->yield('_stop'); } } }; event fetch_id => sub { return $_[OBJECT]->id; } } ForkBomber->new; POE::Kernel->run; __END__ MooseX-POE-0.215/bench/forkbomb.perl0000644000175000001440000001400711746020426016541 0ustar torstenusers#!/usr/bin/perl -w -I.. # $Id: forkbomb.perl 1746 2005-01-28 22:57:30Z rcaputo $ # This is another of the earlier test programs. It creates a single # session whose job is to create more of itself. There is a built-in # limit of 200 sessions, after which they all politely stop. # This program's main purpose in life is to test POE's parent/child # relationships, signal propagation and garbage collection. use strict; use lib '../lib'; sub POE::Kernel::ASSERT_DEFAULT () { 1 } use POE; #============================================================================== # These subs implement the guts of a forkbomb session. Its only # mission in life is to spawn more of itself until it dies. my $count = 0; # session counter for limiting runtime #------------------------------------------------------------------------------ # This sub handles POE's standard _start event. It initializes the # session. sub _start { my ($kernel, $heap) = @_[KERNEL, HEAP]; # assign the next count to this session $heap->{'id'} = ++$count; printf "%4d has started.\n", $heap->{'id'}; # register signal handlers $kernel->sig('INT', 'signal_handler'); $kernel->sig('ZOMBIE', 'signal_handler'); # start forking $kernel->yield('fork'); # return something interesting return "i am $heap->{'id'}"; } #------------------------------------------------------------------------------ # This sub handles POE's standard _stop event. It acknowledges that # the session is stopped. sub _stop { printf "%4d has stopped.\n", $_[HEAP]->{'id'}; } #------------------------------------------------------------------------------ # This sub handles POE's standard _child event. It acknowledges that # the session is gaining or losing a child session. my %english = ( lose => 'is losing', gain => 'is gaining', create => 'has created' ); sub _child { my ($kernel, $heap, $direction, $child, $return) = @_[KERNEL, HEAP, ARG0, ARG1, ARG2]; printf( "%4d %s child %s%s\n", $heap->{'id'}, $english{$direction}, $kernel->call($child, 'fetch_id'), (($direction eq 'create') ? (" (child returned: $return)") : '') ); } #------------------------------------------------------------------------------ # This sub handles POE's standard _parent event. It acknowledges that # the child session's parent is changing. sub _parent { my ($kernel, $heap, $old_parent, $new_parent) = @_[KERNEL, HEAP, ARG0, ARG1]; printf( "%4d parent is changing from %d to %d\n", $heap->{'id'}, $kernel->call($old_parent, 'fetch_id'), $kernel->call($new_parent, 'fetch_id') ); } #------------------------------------------------------------------------------ # This sub acknowledges receipt of signals. It's registered as the # handler for SIGINT and SIGZOMBIE. It returns 0 to tell the kernel # that the signals were not handled. This causes the kernel to stop # the session for certain "terminal" signals (such as SIGINT). sub signal_handler { my ($heap, $signal_name) = @_[HEAP, ARG0]; printf( "%4d has received SIG%s\n", $heap->{'id'}, $signal_name); # tell Kernel that this wasn't handled return 0; } #------------------------------------------------------------------------------ # This is the main part of the test. This state uses the yield() # function to loop until certain conditions are met. my $max_sessions = 800; my $half_sessions = int($max_sessions / 2); sub fork { my ($kernel, $heap) = @_[KERNEL, HEAP]; # Only consider continuing if the maximum number of sessions has not # yet been reached. if ($count < $max_sessions) { # flip a coin; heads == spawn if (rand() < 0.5) { printf "%4d is starting a new child...\n", $heap->{'id'}; &create_new_forkbomber(); } # tails == don't spawn else { printf "%4d is just spinning its wheels this time...\n", $heap->{'id'}; } # Randomly decide to die (or not) if half the sessions have been # reached. if (($count < $half_sessions) || (rand() < 0.05)) { $kernel->yield('fork'); } else { printf "%4d has decided to die. Bye!\n", $heap->{'id'}; # NOTE: Child sessions will keep a parent session alive. # Because of this, the program forces a stop by sending itself a # _stop event. This normally isn't necessary. # NOTE: The main session (#1) is allowed to linger. This # prevents strange things from happening when it exits # prematurely. if ($heap->{'id'} != 1) { $kernel->yield('_stop'); } } } else { printf "%4d notes that the session limit is met. Bye!\n", $heap->{'id'}; # Please see the two NOTEs above. if ($heap->{'id'} != 1) { $kernel->yield('_stop'); } } } #------------------------------------------------------------------------------ # This is a helper event handler. It is called directly by parents # and children to help identify the sessions being given or taken # away. It is just a public interface to the session's numeric ID. sub fetch_id { return $_[HEAP]->{'id'}; } #============================================================================== # This is a helper function that creates a new forkbomber session. sub create_new_forkbomber { POE::Session->create( inline_states => { '_start' => \&_start, '_stop' => \&_stop, '_child' => \&_child, '_parent' => \&_parent, 'signal_handler' => \&signal_handler, 'fork' => \&fork, 'fetch_id' => \&fetch_id, } ); } #============================================================================== # Create the initial forkbomber session, and run the kernel. &create_new_forkbomber(); $poe_kernel->run(); exit; MooseX-POE-0.215/ex/0000755000175000001440000000000011746020426013407 5ustar torstenusersMooseX-POE-0.215/ex/serial_watcher.pl0000644000175000001440000000554111746020426016745 0ustar torstenusers#!/usr/bin/perl # written by Rob Bloodgood aka LordVorp on irc.perl.org # based upon http://poe.perl.org/?POE_Cookbook/Serial_Ports package SerialWatcher; use MooseX::POE::SweetArgs; use Symbol qw(gensym); use Device::SerialPort; use POE::Filter::Line; use POE::Wheel::ReadWrite; use POE::Wheel::ReadLine; has port_handle => ( is => 'ro', isa => 'GlobRef', lazy => 1, default => sub { gensym() } ); has port => ( is => 'ro', isa => 'Device::SerialPort', lazy_build => 1, ); sub _build_port { my ($self) = @_; my $port = tie( *{ $self->port_handle }, "Device::SerialPort", "/dev/ttyS1" ) or die "can't open port: $!"; $port->datatype('raw'); $port->baudrate(9600); $port->databits(8); $port->parity("none"); $port->stopbits(1); $port->handshake("rts"); $port->write_settings(); $port; } has device => ( is => 'ro', isa => 'POE::Wheel::ReadWrite', lazy_build => 1, ); # instantiates the wheel that talks to the device sub _build_device { my ($self) = @_; my $filter = POE::Filter::Line->new( InputLiteral => "\x0D\x0A", # Received line endings. OutputLiteral => "\x0D", # Sent line endings. ); $self->port; # initalize the port and port_handle here so we can use the handle below POE::Wheel::ReadWrite->new( Handle => $self->port_handle, Filter => $filter, InputEvent => "got_port", ErrorEvent => "got_error", ); } has console => ( is => 'ro', isa => 'POE::Wheel::ReadLine', lazy_build => 1, ); # and the wheel that talks to the console sub _build_console { my ($self) = @_; POE::Wheel::ReadLine->new( InputEvent => "got_console" ); } sub START { my $self = shift; # make sure our wheels are started up *in the session* $self->device; $self->console; } event got_port => sub { # wheel gave us some data: my ( $self, $data ) = @_; # [OBJECT, ARG0]; $self->console->put($data); }; event got_console => sub { my ( $self, $input ) = @_; # [OBJECT, ARG0]; if ( defined $input ) { $self->console->addhistory($input); $self->device->put($input); $self->console->get("Ready: "); # Clearing $! after $serial_device->put() seems to work around # an issue in Device::SerialPort 1.000_002. $! = 0; return; } # clearer's are created by lazy_build $self->console->put("Bye!"); $self->clear_device; $self->clear_console; }; event got_error => sub { my ( $self, @args) = @_; # [OBJECT, ARG0...$#_ ]; $self->console->put("$args[0] error $args[1]: $args[2]"); $self->console->put("Bye!"); $self->clear_device; $self->clear_console; }; no MooseX::POE; package main; SerialWatcher->new(); POE::Kernel->run(); MooseX-POE-0.215/ex/candygram.pl0000644000175000001440000000711211746020426015712 0ustar torstenusers#!/usr/bin/env perl -l # This is a little test program to see if we could implement # http://candygram.sourceforge.net/node6.html on MooseX::POE # using MX::Poe objects (aka POE::Sessions) to replace threads # Here is the relevant code from Canygram # # # >>> import candygram as cg # >>> import time # >>> def proc_func(): # ... r = cg.Receiver() # ... r.addHandler('land shark', shut_door, cg.Message) # ... r.addHandler('candygram', open_door, cg.Message) # ... for message in r: # ... print message # ... # >>> def shut_door(name): # ... return 'Go Away ' + name # ... # >>> def open_door(name): # ... return 'Hello ' + name # ... # >>> proc = cg.spawn(proc_func) # >>> proc.send('land shark') # >>> proc.send('candygram') # >>> # Give the proc a chance to print its messages before termination: # ... time.sleep(1) # # here is our version # sub main { sub proc_func { my $r = $_[0]->receiver; $r->add_handler( 'land_shark', \&shut_door ); $r->add_handler( 'candygram', \&open_door ); while (<$r>) { print; } } sub shut_door { return 'Go away ' . $_[1]; } sub open_door { return 'Hello ' . $_[1]; } my $proc = Candygram->spawn( \&proc_func ); $proc->send('land_shark'); $proc->send('candygram'); POE::Kernel->run; # we have to run the kernel manually } # # Implementation # { package Candygram; sub spawn { my ( $self, $func ) = splice @_, 0, 2; return Proc->new( func => $func, args => \@_ ); } } # # the Receiver object does all the real work # { package Receiver; use Moose; use overload '<>' => \&receive; has mailbox => ( isa => 'ArrayRef', is => 'ro', auto_deref => 1, default => sub { [] }, ); has handlers => ( isa => 'HashRef', is => 'ro', default => sub { {} }, ); sub add_handler { my ( $self, $state, $code ) = @_; return if exists $self->handlers->{$state}; $self->handlers->{$state} = $code; } # This could be cleaned up a bunch by MooseX::AttributeHelpers on the # attributes above, but I didn't wan't to have a dependency # for a example script sub receive { my $self = shift; my ( $state, $args ); return unless scalar @{ $self->mailbox }; for ( 0 .. $#{ $self->mailbox } ) { my $state = $self->mailbox->[$_]->[0]; next unless $state; next unless exists $self->handlers->{$state}; ( $state, $args ) = @{ splice @{ $self->mailbox }, $_, 1 }; if ( $state && $args ) { my $res = $self->handlers->{$state}->(@$args); return $res; } } return; } } { package Proc; use MooseX::POE; has func => ( isa => 'CodeRef', is => 'ro', default => sub { sub { } }, ); has args => ( isa => 'ArrayRef', is => 'ro', auto_deref => 1, default => sub { [] }, ); has receiver => ( is => 'ro', default => sub { Receiver->new() }, ); sub START { my ($self) = @_; $self->yield('loop'); } sub on_loop { my ($self) = @_; my $func = $self->func; $self->$func( $self->args ); } sub send { my ( $self, $message ) = @_; push @{ $self->receiver->mailbox }, [ $message, \@_ ]; $self->yield('loop'); } } main(); MooseX-POE-0.215/ex/tbray/0000755000175000001440000000000011746020426014530 5ustar torstenusersMooseX-POE-0.215/ex/tbray/tbray_baseline.pl0000644000175000001440000000060111746020426020045 0ustar torstenusers#!/usr/bin/env perl -l # # http://www.tbray.org/ongoing/When/200x/2007/09/20/Wide-Finder # # # requires the data at http://www.tbray.org/tmp/o10k.ap # my $rx = qr|GET /ongoing/When/\d\d\dx/(\d\d\d\d/\d\d/\d\d/[^ .]+)|o; my %count; while (<>) { next unless $_ =~ $rx; $count{$1}++; } print "$count{$_}: $_" for ( sort { $count{$b} <=> $count{$a} } keys %count )[ 0 .. 9 ]; MooseX-POE-0.215/ex/tbray/tbray_coro_workers.pl0000644000175000001440000000652011746020426021007 0ustar torstenusers#!/usr/bin/env perl -l ### ### THIS SCRIPT DOES NOT WORK ### ### I suspect that Coro and MX::Workers won't play nice, but ### it will have to wait till later for me to debug it ### # # http://www.tbray.org/ongoing/When/200x/2007/09/20/Wide-Finder # # # Rather than Erlang (as was in here before) this is more based on the # Scala version of this code at # http://www.martin-probst.com/2007/09/24/wide-finder-in-scala/ # # # requires the data at http://www.tbray.org/tmp/o10k.ap # $|++; sub main { die 'no file' unless -e 'ex/tbray.data.big'; Slurp->new( filename => 'ex/tbray.data.big' ); } { package Slurp; use MooseX::Coro; use IO::File; use Coro; has filename => ( isa => 'Str', is => 'ro', ); has count => ( isa => 'HashRef', is => 'rw', default => sub { {} }, ); has file => ( isa => 'IO::File', is => 'ro', lazy => 1, default => sub { IO::File->new( $_[0]->filename, 'r' ); }, ); has counter => ( reader => 'c', default => sub { Count->new( sender => $_[0] ) }, handles => { counter => 'yield' }, ); sub START { $_[0]->yield('loop'); } event loop => sub { my ($self) = @_; my $file = $self->file; while ( not eof $file ) { my @chunk; for ( 0 .. ( 600000 / 8 ) ) { $_ = <$file>; push @chunk, $_; } $self->counter( 'loop', $self, \@chunk ); } $self->yield('tally'); }; event inc => sub { my ( $self, $chunk ) = @_; my $count = $self->count; $count->{$_} += $chunk->{$_} for ( keys %$chunk ); $_[0]->count($count); }; event tally => sub { my $count = $_[0]->count; print "$count->{$_}: $_" for sort { $count->{$b} <=> $count->{$a} } keys %$count; $_[0]->yield('STOP'); }; __PACKAGE__->meta->make_immutable; } { package Count; use MooseX::Coro; use JSON::Any qw(XS); with qw(MooseX::Workers); sub BUILD { POE::Kernel->run } has sender => ( reader => 's', required => 1, handles => { sender => 'yield' }, ); event loop => sub { my ( $self, $chunk ) = @_; my $count = {}; my $rx = qr|GET /ongoing/When/\d\d\dx/(\d\d\d\d/\d\d/\d\d/[^ .]+)|o; $self->spawn( sub { for my $line (@$chunk) { $count->{$1}++ if $line =~ $rx; } print JSON::Any->encode($count); } ); }; sub worker_stdout { my ( $self, $out ) = @_; warn $out; my $count = JSON::Any->decode($out); $self->sender_return( 'inc', $count ); } sub worker_manager_start { warn 'started worker manager' } sub worker_manager_stop { warn 'stopped worker manager' } sub max_workers_reached { warn 'maximum worker count reached' } sub worker_stderr { shift; warn 'STDERR: ' . join ' ', @_; } sub worker_error { shift; warn join ' ', @_; } sub worker_done { shift; warn 'DONE: ' . join ' ', @_; } sub worker_started { shift; warn 'STARTED: ' . join ' ', @_; } sub sig_child { shift; warn join ' ', @_; } __PACKAGE__->meta->make_immutable; } main(); MooseX-POE-0.215/ex/tbray/tbray_coro_fork.pl0000644000175000001440000000540511746020426020255 0ustar torstenusers#!/usr/bin/env perl -l # # http://www.tbray.org/ongoing/When/200x/2007/09/20/Wide-Finder # # # Rather than Erlang (as was in here before) this is more based on the # Scala version of this code at # http://www.martin-probst.com/2007/09/24/wide-finder-in-scala/ # # # requires the data at http://www.tbray.org/tmp/o10k.ap # $|++; sub main { die 'no file' unless -e 'ex/tbray.data.big'; Slurp->new( filename => 'ex/tbray.data.big' ); } { package Slurp; use MooseX::Coro; use IO::File; use Coro; has filename => ( isa => 'Str', is => 'ro', ); has count => ( isa => 'HashRef', is => 'rw', default => sub { {} }, ); has file => ( isa => 'IO::File', is => 'ro', lazy => 1, default => sub { IO::File->new( $_[0]->filename, 'r' ); }, ); sub START { $_[0]->yield('loop'); } event loop => sub { my ($self) = @_; my $file = $self->file; my $counter = Count->new; while ( not eof $file ) { my @chunk; for ( 0 .. ( 600000 / 2 ) ) { $_ = <$file>; push @chunk, $_; } $counter->yield( 'loop', $self, \@chunk ); } $self->yield('tally'); }; event inc => sub { my ( $self, $chunk ) = @_; my $count = $self->count; $count->{$_} += $chunk->{$_} for ( keys %$chunk ); $_[0]->count($count); }; event tally => sub { my $count = $_[0]->count; print "$count->{$_}: $_" for sort { $count->{$b} <=> $count->{$a} } keys %$count; $_[0]->yield('STOP'); }; __PACKAGE__->meta->make_immutable; } { package Count; use MooseX::Coro; use Coro::Util; use Coro::Semaphore; has cpulock => ( is => 'ro', default => sub { new Coro::Semaphore 2; }, handles => [qw(guard)], ); my $rx = qr|GET /ongoing/When/\d\d\dx/(\d\d\d\d/\d\d/\d\d/[^ .]+)|o; event loop => sub { my ( $self, $sender, $chunk ) = @_; my $guard = $self->guard; ### This doesn't return until after we have exited ### this is probably a priority issue but I can't seem to sort it ### Coro is a PITA my $count = Coro::Util::fork_eval { my %count; for my $line (@$chunk) { next unless $line; $count{$1}++ if $line =~ $rx; } warn 'returning ' . scalar keys %count; return \%count; }; warn "Here!"; $sender->yield( 'inc', $count ); }; event run => sub { my ( $self, $chunk ) = @_; }; __PACKAGE__->meta->make_immutable; } main(); MooseX-POE-0.215/ex/tbray/widefinder.pl0000755000175000001440000000276111746020426017216 0ustar torstenusers#!/usr/bin/perl -sw use strict; require 5.000_10; # useage perl -s widefinder.pl -J=2 filename # based on a version by Eric Wong - public domain # originally found at http://normalperson.com/widefinder # control the number of child processes here # this should be one less than the number of cores use vars qw( $J $children %nr ); use constant J => $J || 1; use constant PROCS => J - 1; use IPC::Open3; use Storable qw(nstore_fd fd_retrieve); use POSIX ':sys_wait_h'; my $rx = qr{GET /ongoing/When/\d{3}x/(\d{4}/\d\d/\d\d/[^ .]+)}; # $SIG{CHLD} = \&reaper; # $SIG{PIPE} = 'IGNORE'; $|++; sub child { my %tmp; while (<>) { $_ =~ $rx; $tmp{$1}++; } nstore_fd( \%tmp, \*STDOUT ); exit 0; } sub pre_fork { my $children = {}; for ( 0 .. PROCS ) { my $pid = open3( my $in, my $out, my $err, '-' ); unless ($pid) { child() } else { $children->{$pid} = { in => $in, out => $out, err => $err }; } } return $children; } my $children = pre_fork; open my $data, '<', shift; while (<$data>) { my ($pid) = ( keys %$children )[ $. % J ]; #warn "Printing to $pid"; my $child = $children->{$pid}; print { $child->{in} } $_; } for ( keys %$children ) { warn "sending end"; close $children->{$_}->{in}; my $tmp = fd_retrieve($children->{$_}->{out}); $nr{$_} += $tmp->{$_} for keys %$tmp; } print "$nr{$_}: $_\n" for ( ( sort { $nr{$b} <=> $nr{$a} } keys %nr )[ 0 .. 9 ] ); MooseX-POE-0.215/ex/tbray/wf_mmap.pl0000755000175000001440000000305011746020426016514 0ustar torstenusers#!/usr/bin/env perl -s ## wf.pl -- an implementation of the "wide finder" benchmark. ## Sean O'Rourke, 2007, public domain. ## ## Usage: perl -s wf.pl -J=$N $LOGFILE ## where $N is the number of processes, and $LOGFILE is the target. ## ## This code depends on Sys::Mmap, which is available on CPAN. use Sys::Mmap; use strict qw(subs refs); #$J ||= 0; my $file = shift; open IN, $file or die $!; my $str; mmap $str, 0, PROT_READ, MAP_SHARED, IN; my %h; my $n = 0; unless ($J) { ## serial $h{$1}++ while $str =~ m{GET /ongoing/When/\d\d\dx/(\d\d\d\d/\d\d/\d\d/[^ .]+) }g; } else { $|=1; ## parallel -- ugh. my $size = -s IN; my $nperj = int(($size + $J - 1) / $J); my @fhs; use Storable qw(store_fd fd_retrieve); for my $i (0..$J-1) { my $pid = open my $fh, "-|"; die unless defined $pid; if ($pid) { push @fhs, $fh; } else { pos($str) = $i ? rindex($str, "\n", $nperj * $i) || 0 : 0; my $end = ($i+1) * $nperj; $h{$1}++ while pos($str) < $end && $str =~ m{GET /ongoing/When/\d\d\dx/(\d\d\d\d/\d\d/\d\d/[^ .]+) }g; store_fd \%h, \*STDOUT or die "$i can't store!\n"; exit 0; } } for (0..$#fhs) { my $h = fd_retrieve $fhs[$_] or die "I can't load $_\n"; while (my ($k, $v) = each %$h) { $h{$k} += $v; } close $fhs[$_] or warn "$_ exited weirdly."; } } for (sort { $h{$b} <=> $h{$a} } keys %h) { print "$h{$_}\t$_\n"; last if ++$n >= 10; } MooseX-POE-0.215/ex/tbray/tbray_poe_workers.pl0000644000175000001440000000500611746020426020626 0ustar torstenusers#!/usr/bin/env perl -l # # http://www.tbray.org/ongoing/When/200x/2007/09/20/Wide-Finder # # # Rather than Erlang (as was in here before) this is more based on the # Scala version of this code at # http://www.martin-probst.com/2007/09/24/wide-finder-in-scala/ # # # requires the data at http://www.tbray.org/tmp/o10k.ap # use POE qw(Loop::Kqueue); { package Slurp; use MooseX::POE; use IO::File; has filename => ( is => 'ro', ); has count => ( is => 'rw', default => sub { {} }, ); has _counter => ( is => 'ro', lazy => 1, default => sub { Count->new }, handles => { counter => 'yield', } ); has file => ( is => 'ro', lazy => 1, default => sub { IO::File->new( $_[0]->filename, 'r' ); }, ); sub START { shift->yield('loop'); } event loop => sub { my ($self) = @_; my $file = $self->file; if ( not eof $file ) { my @chunk; for ( 0 .. CHUNK_SIZE ) { $_ = <$file>; push @chunk, $_; } $self->counter( 'loop', \@chunk ); return; } $self->yield('tally'); }; event inc => sub { my $chunk = $_[ARG0]; my $count = $_[0]->count; for ( keys %$chunk ) { $count->{$_} += $chunk->{$_}; } $_[0]->count($count); }; event tally => sub { my $count = $_[OBJECT]->count; print "$count->{$_}: $_" for sort { $count->{$b} <=> $count->{$a} } keys %$count; }; } { package Count; use MooseX::POE; use JSON::Any qw(XS); with qw(MooseX::Workers); my $rx = qr|GET /ongoing/When/\d\d\dx/(\d\d\d\d/\d\d/\d\d/[^ .]+)|o; event loop => sub { my ( $self, $sender, $chunk ) = @_[ OBJECT, SENDER, ARG0 ]; $self->spawn( sub { my $count = {}; for my $line (@$chunk) { $count->{$1}++ if $line =~ $rx; } print JSON::Any->encode( { sender => $sender->ID, count => $count } ); } ); POE::Kernel->post( $sender => 'loop' ); }; sub worker_stdout { my ( $self, $out ) = @_; my $msg = JSON::Any->decode($out); POE::Kernel->post( $msg->{sender} => 'inc' => $msg->{count} ); } } die 'no file' unless -e 'ex/tbray.data.big'; Slurp->new( filename => 'ex/tbray.data.big' ); POE::Kernel->run(); MooseX-POE-0.215/ex/tbray/tbray_coro.pl0000644000175000001440000000407511746020426017236 0ustar torstenusers#!/usr/bin/env perl -l # # http://www.tbray.org/ongoing/When/200x/2007/09/20/Wide-Finder # # # Rather than Erlang (as was in here before) this is more based on the # Scala version of this code at # http://www.martin-probst.com/2007/09/24/wide-finder-in-scala/ # # # requires the data at http://www.tbray.org/tmp/o10k.ap # $|++; sub main { die 'no file' unless -e 'ex/tbray.data.big'; Slurp->new( filename => 'ex/tbray.data.big' ); } { package Slurp; use MooseX::Coro; use IO::File; use Coro; has filename => ( isa => 'Str', is => 'ro', ); has count => ( isa => 'HashRef', is => 'rw', default => sub { {} }, ); has file => ( isa => 'IO::File', is => 'ro', lazy => 1, default => sub { IO::File->new( $_[0]->filename, 'r' ); }, ); sub START { $_[0]->yield('loop'); } event loop => sub { my ($self) = @_; my $file = $self->file; my $counter = Count->new; while ( not eof $file ) { my @chunk; push @chunk, <$file> for ( 0 .. 1 ); $counter->yield( 'loop', $self, \@chunk ); } $self->yield('tally'); }; event inc => sub { my ( $self, $chunk ) = @_; my $count = $self->count; $count->{$_} += $chunk->{$_} for ( keys %$chunk ); $_[0]->count($count); }; event tally => sub { my $count = $_[0]->count; print "$count->{$_}: $_" for sort { $count->{$b} <=> $count->{$a} } keys %$count; $_[0]->yield('STOP'); }; __PACKAGE__->meta->make_immutable; } { package Count; use MooseX::Coro; event loop => sub { my ( $self, $sender, $chunk ) = @_; my $count = {}; my $rx = qr|GET /ongoing/When/\d\d\dx/(\d\d\d\d/\d\d/\d\d/[^ .]+)|o; for my $line (@$chunk) { $count->{$1}++ if $line =~ $rx; } $sender->yield( 'inc', $count ); }; __PACKAGE__->meta->make_immutable; } main(); MooseX-POE-0.215/ex/tbray/tbray_poe.pl0000644000175000001440000000362511746020426017057 0ustar torstenusers#!/usr/bin/env perl -l # # http://www.tbray.org/ongoing/When/200x/2007/09/20/Wide-Finder # # # Rather than Erlang (as was in here before) this is more based on the # Scala version of this code at # http://www.martin-probst.com/2007/09/24/wide-finder-in-scala/ # # # requires the data at http://www.tbray.org/tmp/o10k.ap # $|++; sub main { die 'no file' unless -e 'ex/tbray.data'; Slurp->new( filename => 'ex/tbray.data' ); POE::Kernel->run(); } { package Slurp; use MooseX::POE; use IO::File; has filename => ( isa => 'Str', is => 'ro', ); has count => ( isa => 'HashRef', is => 'rw', default => sub { {} }, ); my $file; sub START { $file ||= IO::File->new( $_[0]->filename, 'r' ); shift->yield('loop'); } event loop => sub { my ($self) = @_; if ( not eof $file ) { my @chunk; push @chunk, <$file> for ( 0 .. 1 ); Count->new->yield( 'loop', \@chunk ); return; } $self->yield('tally'); }; event inc => sub { my $chunk = $_[ARG0]; my $count = $_[0]->count; for ( keys %$chunk ) { $count->{$_} += $chunk->{$_}; } $_[0]->count($count); }; event tally => sub { my $count = $_[OBJECT]->count; print "$count->{$_}: $_" for sort { $count->{$b} <=> $count->{$a} } keys %$count; }; } { package Count; use MooseX::POE; event loop => sub { my ( $self, $sender, $chunk ) = @_[ OBJECT, SENDER, ARG0 ]; my $count = {}; for my $line (@$chunk) { $count->{$1}++ if $line =~ qr|GET /ongoing/When/\d\d\dx/(\d\d\d\d/\d\d/\d\d/[^ .]+)|o; } POE::Kernel->post( $sender => 'inc', $count ); POE::Kernel->post( $sender => 'loop' ); }; } main(); MooseX-POE-0.215/README.md0000644000175000001440000001173711746020426014263 0ustar torstenusers# NAME MooseX::POE - The Illicit Love Child of Moose and POE # VERSION This document describes MooseX::POE version 0.205 # SYNOPSIS package Counter; use MooseX::POE; has count => ( isa => 'Int', is => 'rw', lazy => 1, default => sub { 0 }, ); sub START { my ($self) = @_; $self->yield('increment'); } event increment => sub { my ($self) = @_; print "Count is now " . $self->count . "\n"; $self->count( $self->count + 1 ); $self->yield('increment') unless $self->count > 3; }; no MooseX::POE; Counter->new(); POE::Kernel->run(); or with L: class Counter { use MooseX::POE::SweetArgs qw(event); has count => ( isa => 'Int', is => 'rw', lazy => 1, default => sub { 0 }, ); sub START { my ($self) = @_; $self->yield('increment') } event increment => sub { my ($self) = @_; print "Count is now " . $self->count . "\n"; $self->count( $self->count + 1 ); $self->yield('increment') unless $self->count > 3; } } Counter->new(); POE::Kernel->run(); # DESCRIPTION MooseX::POE is a Moose wrapper around a POE::Session. # KEYWORDS - event $name $subref Create an event handler named $name. # METHODS Default POE-related methods are provided by L which is applied to your base class (which is usually L) when you use this module. See that module for the documentation for. Below is a list of methods on that class so you know what to look for: - get_session_id - yield - call - STARTALL - STOPALL # NOTES ON USAGE WITH L L support is still "experimental". Meaning that I don't use it, I don't have any code that uses it, and thus I can't adequately say that it won't cause monkeys to fly out of any orifices on your body beyond what the tests and the SYNOPSIS cover. That said there are a few caveats that have turned up during testing. 1. The `method` keyword doesn't seem to work as expected. This is an integration issue that is being resolved but I want to wait for L to gain some more polish on their slurpy arguments. 2. MooseX::POE attempts to re-export L, which L has already exported in a custom fashion. This means that you'll get a keyword clash between the features that L handles for you and the features that Moose handles. To work around this you'll need to write: use MooseX::POE qw(event); # or use MooseX::POE::SweetArgs qw(event); # or use MooseX::POE::Role qw(event); to keep MooseX::POE from exporting the sugar that L doesn't like. This is fixed in the Git version of L but that version (as of this writing) is not on the CPAN. # DEPENDENCIES L L # AUTHOR Chris Prather `` Ash Berlin `` Chris Williams ` Yuval (nothingmuch) Kogman # LICENCE AND COPYRIGHT Copyright (c) 2007-2009, Chris Prather ``, Ash Berlin ``, Chris Williams `, Yuval (nothingmuch) Kogman. Some rights reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See [perlartistic](http://search.cpan.org/perldoc?perlartistic). # DISCLAIMER OF WARRANTY BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.MooseX-POE-0.215/MANIFEST0000644000175000001440000000206211746020426014124 0ustar torstenusersChanges LICENSE MANIFEST META.json META.yml Makefile.PL README README.md bench/forkbomb.perl bench/moose.forkbomb.pl dist.ini ex/candygram.pl ex/serial_watcher.pl ex/tbray/tbray_baseline.pl ex/tbray/tbray_coro.pl ex/tbray/tbray_coro_fork.pl ex/tbray/tbray_coro_workers.pl ex/tbray/tbray_poe.pl ex/tbray/tbray_poe_workers.pl ex/tbray/wf_mmap.pl ex/tbray/widefinder.pl lib/MooseX/POE.pm lib/MooseX/POE/Aliased.pm lib/MooseX/POE/Meta/Method/State.pm lib/MooseX/POE/Meta/Role.pm lib/MooseX/POE/Meta/Trait.pm lib/MooseX/POE/Meta/Trait/Class.pm lib/MooseX/POE/Meta/Trait/Instance.pm lib/MooseX/POE/Meta/Trait/Object.pm lib/MooseX/POE/Meta/Trait/SweetArgs.pm lib/MooseX/POE/Role.pm lib/MooseX/POE/SweetArgs.pm t/01_basic.t t/02_poe_forkbomb.t t/03_extend.t t/04_with.t t/04_with_before.t t/04_with_before_fixed.t t/04_with_override.t t/05_daemonize.t t/06_sweet.t t/07_aliased.t t/07_aliased_assert.t t/08_moosex_declare.t t/09_extend.t t/10_immutability.t t/11_regular_moose.t t/12_more_roles.t t/13_method_modifiers.t t/14_bug_double_build.t t/15_timers.t t/release-pod-syntax.t