| 1 | # | ||
| 2 | # This file is part of POE-Component-SpreadClient | ||
| 3 | # | ||
| 4 | # This software is copyright (c) 2011 by Apocalypse. | ||
| 5 | # | ||
| 6 | # This is free software; you can redistribute it and/or modify it under | ||
| 7 | # the same terms as the Perl 5 programming language system itself. | ||
| 8 | # | ||
| 9 | 2 | ▶ | use strict; use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 10 | package POE::Driver::SpreadClient; | ||
| 11 | BEGIN { | ||
| 12 | 2 | ▶ | $POE::Driver::SpreadClient::VERSION = '1.002'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 13 | } | ||
| 14 | BEGIN { | ||
| 15 | 2 | ▶ | $POE::Driver::SpreadClient::AUTHORITY = 'cpan:APOCAL'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 16 | } | ||
| 17 | |||
| 18 | # ABSTRACT: Implements the Spread driver for POE | ||
| 19 | |||
| 20 | # Import some stuff | ||
| 21 | 2 | ▶ | use Spread; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 22 | |||
| 23 | use constant MAX_READS => 256; | ||
| 24 | |||
| 25 | sub new { | ||
| 26 | my $type = shift; | ||
| 27 | my $mbox = shift; | ||
| 28 | my $self = bless \$mbox, $type; | ||
| 29 | return $self; | ||
| 30 | } | ||
| 31 | |||
| 32 | sub get { | ||
| 33 | my $self = shift; | ||
| 34 | |||
| 35 | my $reads_performed = 1; | ||
| 36 | my @buf = (); | ||
| 37 | |||
| 38 | # read once: | ||
| 39 | push @buf, [ Spread::receive( $$self ) ]; | ||
| 40 | |||
| 41 | # Spread::poll returns 0 if no messages pending; | ||
| 42 | while( Spread::poll( $$self ) and ++$reads_performed <= MAX_READS ) { | ||
| 43 | push @buf, [ Spread::receive( $$self ) ]; | ||
| 44 | } | ||
| 45 | |||
| 46 | return [ @buf ]; | ||
| 47 | } | ||
| 48 | |||
| 49 | 1; | ||
| 50 | |||
| 51 | |||
| 52 | __END__ | ||