| 1 | # | ||
| 2 | # This file is part of POE-Component-SpreadClient | ||
| 3 | # | ||
| 4 | # This software is copyright (c) 2014 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 | $POE::Driver::SpreadClient::VERSION = '1.003'; | ||
| 12 | our $AUTHORITY = 'cpan:APOCAL'; | ||
| 13 | |||
| 14 | # ABSTRACT: Implements the Spread driver for POE | ||
| 15 | |||
| 16 | # Import some stuff | ||
| 17 | 0 | ▶ | use Spread; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 18 | |||
| 19 | # magic number taken from Spread's MAX_READS | ||
| 20 | my $MAX_READS = 256; | ||
| 21 | |||
| 22 | sub new { | ||
| 23 | my $type = shift; | ||
| 24 | my $mbox = shift; | ||
| 25 | my $self = bless \$mbox, $type; | ||
| 26 | return $self; | ||
| 27 | } | ||
| 28 | |||
| 29 | sub get { | ||
| 30 | my $self = shift; | ||
| 31 | |||
| 32 | my $reads_performed = 1; | ||
| 33 | my @buf; | ||
| 34 | |||
| 35 | # read once: | ||
| 36 | push @buf, [ Spread::receive( $$self ) ]; | ||
| 37 | |||
| 38 | # Spread::poll returns 0 if no messages pending; | ||
| 39 | while( Spread::poll( $$self ) and ++$reads_performed <= $MAX_READS ) { | ||
| 40 | push @buf, [ Spread::receive( $$self ) ]; | ||
| 41 | } | ||
| 42 | |||
| 43 | return [ @buf ]; | ||
| 44 | } | ||
| 45 | |||
| 46 | 1; | ||
| 47 | |||
| 48 | __END__ | ||