BusyBird/Flow.pm

filter: Statementstmt 98.1% 54 / 55 Branchbran 75.0% 3 / 4 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 19 / 19 Podpod 100% 3 / 3 totaltotal 97.6% 84 / 86 CC 4 SCAR 3.2
CC
4
Cov
97%
__ANON__
3.0
add
2.1
BEGIN
1.0
CRAP 1.4
« BusyBird/Filter.pm ↑ Summary BusyBird.pm »
1 package BusyBird::Flow;
2 12 ▶use v5.8.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 12 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 12 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 12 ▶use Async::Queue;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 12 ▶use BusyBird::Log qw(bblog);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 12 ▶use CPS qw(kforeach);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 12 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 12 ▶use Scalar::Util qw(weaken);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 12 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 230 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
13 230 my ($class) = @_;
14 230 my $self = bless {
15 filters => [],
16 }, $class;
17 230 $self->{queue} = $self->_create_queue();
18 230 return $self;
19 }
20  
21 230 ▶sub _create_queue {
Subroutine _create_queue: called CC=1 SCAR=0.0
22 230 my ($self) = @_;
23 230 weaken $self;
24 183 ▶ return Async::Queue->new(concurrency => 1, worker => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
25 183 my ($data, $done) = @_;
26 89 ▶ kforeach $self->{filters}, sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
27 89 my ($filter, $knext) = @_;
28 89 ▶ try {
Subroutine __ANON__: called CC=1 SCAR=0.0
29 87 ▶ $filter->($data, sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
30 87 my ($result) = @_;
31 87 ▶ if(ref($result) && ref($result) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $result and ref $result eq 'ARRAY') { } 71 16 87
Condition100%3/3
ref $result and ref $result eq "ARRAY"
!ll&&!rl&&r
8871
MC/DC100%2/2
ref $result and ref $result eq "ARRAY"
ref $result ref $result eq "ARRAY"
Truth table100%3/3
A and B
A= ref $resultB= ref $result eq "ARRAY"
ABresult
0X0
100
111
32 71 $data = $result;
33 }else {
34 16 bblog('warn', 'The filter did not return an array-ref. Ignored.');
35 }
36 87 $knext->();
37 89 });
38 2 ▶ }catch {
Subroutine __ANON__: called CC=1 SCAR=0.0
39 2 my ($e) = @_;
40 2 bblog('error', "Filter dies: $e");
41 2 $knext->();
42 89 };
43 183 ▶ }, sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
44 183 $done->($data);
45 183 };
46 230 });
47 }
48  
49 57 ▶sub add {
Subroutine add: called CC=2 SCAR=7.4
Pod documented
50 57 my ($self, $async_filter) = @_;
51 57 ▶ if($self->{queue}->running) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$self{"queue"}->running) 0 57 57
52 0 croak "You cannot add a filter while there is a status running in it."
53 }
54 57 push(@{$self->{filters}}, $async_filter);
55 }
56  
57 183 ▶sub execute {
Subroutine execute: called CC=1 SCAR=0.0
Pod documented
58 183 my ($self, $data, $callback) = @_;
59 183 $self->{queue}->push($data, $callback);
60 }
61  
62  
63 12 1;
64  
65 __END__
« BusyBird/Filter.pm ↑ Summary BusyBird.pm »