File Coverage

blib/lib/Event/Distributor/Action.pm
Criterion Covered Total %
statement 21 21 100.0
branch 4 4 100.0
condition n/a
subroutine 7 7 100.0
pod 2 2 100.0
total 34 34 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-2021 -- leonerd@leonerd.org.uk
5              
6             package Event::Distributor::Action 0.06;
7              
8 3     3   98796 use v5.14;
  3         22  
9 3     3   17 use warnings;
  3         25  
  3         111  
10 3     3   32 use base qw( Event::Distributor::_Event );
  3         7  
  3         730  
11              
12 3     3   24 use Carp;
  3         6  
  3         192  
13              
14 3     3   18 use Future;
  3         5  
  3         549  
15              
16             =head1 NAME
17              
18             C - an event that requires one subscriber
19              
20             =head1 DESCRIPTION
21              
22             This subclass of L requires exactly one subscriber
23             at the time that it is invoked. It passes on the caller's arguments to the
24             subscriber, and the subscriber's return value back to the caller.
25              
26             =cut
27              
28             sub subscribe
29             {
30 3     3 1 125 my $self = shift;
31 3 100       12 $self->subscribers and croak "Too many subscribers";
32              
33 2         12 $self->SUPER::subscribe( @_ );
34             }
35              
36             sub fire
37             {
38 2     2 1 12 my $self = shift;
39 2         5 my ( $dist, @args ) = @_;
40              
41 2 100       8 my @subs = $self->subscribers or
42             return Future->fail( "No subscribers" );
43              
44 1         10 Future->call( $subs[0], $dist, @args );
45             }
46              
47             =head1 AUTHOR
48              
49             Paul Evans
50              
51             =cut
52              
53             0x55AA;