File Coverage

blib/lib/Event/Distributor/Action.pm
Criterion Covered Total %
statement 22 22 100.0
branch 4 4 100.0
condition n/a
subroutine 7 7 100.0
pod 2 2 100.0
total 35 35 100.0


line stmt bran cond sub pod time code
1             # You may distribute under the terms of either the GNU General Public License
2             # or the Artistic License (the same terms as Perl itself)
3             #
4             # (C) Paul Evans, 2015 -- leonerd@leonerd.org.uk
5              
6             package Event::Distributor::Action;
7              
8 3     3   48522 use strict;
  3         7  
  3         82  
9 3     3   13 use warnings;
  3         5  
  3         90  
10 3     3   16 use base qw( Event::Distributor::_Event );
  3         5  
  3         791  
11              
12             our $VERSION = '0.04';
13              
14 3     3   16 use Carp;
  3         4  
  3         199  
15              
16 3     3   13 use Future;
  3         15  
  3         437  
17              
18             =head1 NAME
19              
20             C - an event that requires one subscriber
21              
22             =head1 DESCRIPTION
23              
24             This subclass of L requires exactly one subscriber
25             at the time that it is invoked. It passes on the caller's arguments to the
26             subscriber, and the subscriber's return value back to the caller.
27              
28             =cut
29              
30             sub subscribe
31             {
32 3     3 1 29 my $self = shift;
33 3 100       16 $self->subscribers and croak "Too many subscribers";
34              
35 2         12 $self->SUPER::subscribe( @_ );
36             }
37              
38             sub fire
39             {
40 2     2 1 10 my $self = shift;
41 2         7 my ( $dist, @args ) = @_;
42              
43 2 100       8 my @subs = $self->subscribers or
44             return Future->fail( "No subscribers" );
45              
46 1         10 Future->call( $subs[0], $dist, @args );
47             }
48              
49             =head1 AUTHOR
50              
51             Paul Evans
52              
53             =cut
54              
55             0x55AA;