blib/lib/Event/Distributor/Action.pm

filter: Statementstmt 100% 24 / 24 Branchbran 100% 4 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 100% 2 / 2 totaltotal 100% 37 / 37 SCAR 11.0
CC
3
Cov
100%
subscribe
2.0
fire
2.0
BEGIN
1.0
CRAP 3.0
« blib/lib/Event/Distributor/Query.pm ↑ Summary blib/lib/Event/Distributor/Signal.pm »
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 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use base qw( Event::Distributor::_Event );
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 3 our $VERSION = '0.04';
13  
14 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 3 ▶use Future;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 =head1 NAME
19  
20 C<Event::Distributor::Action> - an event that requires one subscriber
21  
22 =head1 DESCRIPTION
23  
24 This subclass of L<Event::Distributor::_Event> 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 ▶ my $self = shift;
Subroutine subscribe: called CC=2 SCAR=6.9
Pod documented
33 3 ▶ $self->subscribers and croak "Too many subscribers";
Branch: 1 branch
BranchTrueFalseTotal
$self->subscribers and croak("Too many subscribers") 1 2 3
34  
35 2 $self->SUPER::subscribe( @_ );
36 }
37  
38 sub fire
39 {
40 2 ▶ my $self = shift;
Subroutine fire: called CC=2 SCAR=6.9
Pod documented
41 2 my ( $dist, @args ) = @_;
42  
43 2 ▶ my @subs = $self->subscribers or
Branch: 1 branch
BranchTrueFalseTotal
my(@subs) = $self->subscribers or return "Future"->fail("No subscribers") 1 1 2
44 return Future->fail( "No subscribers" );
45  
46 1 Future->call( $subs[0], $dist, @args );
47 }
48  
49 =head1 AUTHOR
50  
51 Paul Evans <leonerd@leonerd.org.uk>
52  
53 =cut
54  
55 3 0x55AA;
« blib/lib/Event/Distributor/Query.pm ↑ Summary blib/lib/Event/Distributor/Signal.pm »