blib/lib/Event/Distributor/Query.pm

filter: Statementstmt 100% 25 / 25 Branchbran 50.0% 1 / 2 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 6 / 6 Podpod 100% 1 / 1 totaltotal 87.1% 34 / 39 SCAR 13.9
CC
4
Cov
90%
fire
4.1
BEGIN
1.0
BEGIN
1.0
CRAP 4.0
« blib/lib/Event/Distributor.pm ↑ Summary blib/lib/Event/Distributor/Action.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, 2014-2015 -- leonerd@leonerd.org.uk
5  
6 package Event::Distributor::Query;
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 Future;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 =head1 NAME
17  
18 C<Event::Distributor::Query> - an event that collects a result
19  
20 =head1 DESCRIPTION
21  
22 This subclass of L<Event::Distributor::_Event> invokes each of its subscribers
23 in turn, yielding either the (first) successful result, or a failure if they
24 all fail.
25  
26 =cut
27  
28 sub fire
29 {
30 2 ▶ my $self = shift;
Subroutine fire: called CC=4 SCAR=14.1
Pod documented
31 2 my ( $dist, @args ) = @_;
32  
33 2 my $await = $self->{await};
34 2 my @f;
35  
36 2 foreach my $sub ( $self->subscribers ) {
37 2 my $f = $sub->( $dist, @args );
38 2 push @f, $f;
39  
40 2 ▶ last if $f->is_ready and !$f->failure;
Branch: 1 branch
BranchTrueFalseTotal
if $f->is_ready and not $f->failure 2 0 2
Condition33%1/3
$f->is_ready and not $f->failure
!ll&&!rl&&r
002
MC/DC0%0/2
$f->is_ready and not $f->failure
$f->is_ready not $f->failure
Truth table33%1/3
A and not(B)
A= $f->is_readyB= not $f->failure
ABresult
0X0
100
111
41 }
42  
43 return Future->needs_any( @f )->then( sub {
44 2 ▶ my @results = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
45 # TODO: conversions?
46 2 Future->done( @results );
47 2 });
48 }
49  
50 =head1 AUTHOR
51  
52 Paul Evans <leonerd@leonerd.org.uk>
53  
54 =cut
55  
56 3 0x55AA
« blib/lib/Event/Distributor.pm ↑ Summary blib/lib/Event/Distributor/Action.pm »