| 1 | package Message::Passing::Filter::Delay; | ||
| 2 | 2 | ▶ | use Moo; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 3 | 2 | ▶ | use MooX::Types::MooseLike::Base qw( :all ); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 2 | ▶ | use AnyEvent; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 2 | ▶ | use Scalar::Util qw/ weaken /; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | 2 | ▶ | use namespace::clean -except => 'meta'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | |||
| 8 | 2 | with qw/ | |
| 9 | Message::Passing::Role::Input | ||
| 10 | Message::Passing::Role::Output | ||
| 11 | /; | ||
| 12 | |||
| 13 | 2 | has delay_for => ( | |
| 14 | isa => Num, | ||
| 15 | is => 'ro', | ||
| 16 | required => 1, | ||
| 17 | ); | ||
| 18 | |||
| 19 | sub consume { | ||
| 20 | 1 | ▶ | my ($self, $message) = @_; |
|
Subroutine
consume: called CC=1 SCAR=0.0
Pod
documented
| |||
| 21 | 1 | weaken($self); | |
| 22 | 1 | my $t; $t = AnyEvent->timer( | |
| 23 | after => $self->delay_for, | ||
| 24 | cb => sub { | ||
| 25 | 1 | ▶ | undef $t; |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 26 | 1 | $self->output_to->consume($message); | |
| 27 | }, | ||
| 28 | 1 | ); | |
| 29 | } | ||
| 30 | |||
| 31 | |||
| 32 | 2 | 1; | |
| 33 | |||
| 34 | =head1 NAME | ||
| 35 | |||
| 36 | Message::Passing::Filter::Delay - Delay messages for some time. | ||
| 37 | |||
| 38 | =head1 DESCRIPTION | ||
| 39 | |||
| 40 | This filter passes all incoming messages through with no changes, however | ||
| 41 | not immediately - they are delayed . | ||
| 42 | |||
| 43 | You would normally never want to use this, but it can be useful for | ||
| 44 | testing occasionally, or avoiding race conditions. | ||
| 45 | |||
| 46 | =head1 ATTRIBUTES | ||
| 47 | |||
| 48 | =head2 delay_for | ||
| 49 | |||
| 50 | Floating point number, indicating how many seconds to delay messages for. | ||
| 51 | |||
| 52 | =head1 METHODS | ||
| 53 | |||
| 54 | =head2 consume ($msg) | ||
| 55 | |||
| 56 | Sets up a timed callback in the event loop, which passes the message | ||
| 57 | to the output (and deletes itself) once the timeout has expired | ||
| 58 | |||
| 59 | =head1 SPONSORSHIP | ||
| 60 | |||
| 61 | This module exists due to the wonderful people at Suretec Systems Ltd. | ||
| 62 | <http://www.suretecsystems.com/> who sponsored its development for its | ||
| 63 | VoIP division called SureVoIP <http://www.surevoip.co.uk/> for use with | ||
| 64 | the SureVoIP API - | ||
| 65 | <http://www.surevoip.co.uk/support/wiki/api_documentation> | ||
| 66 | |||
| 67 | =head1 AUTHOR, COPYRIGHT AND LICENSE | ||
| 68 | |||
| 69 | See L<Message::Passing>. | ||
| 70 | |||
| 71 | =cut | ||