Sequence.pm

filter: Statementstmt 77.7% 7 / 9 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 83.3% 10 / 12 CC 1 SCAR 0.9
CC
1
Cov
78%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« Sequence/Analyser/OL/Numbered.pm ↑ Summary Sequence/Analyser.pm »
1 package List::Analyse::Sequence;
2  
3 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 3 ▶use Module::Pluggable (
Subroutine BEGIN: called CC=1 SCAR=2.6
7 0 search => [ "List::Analyse::Sequence::Analyser" ],
8 sub_name => 'analysers',
9 0 );
10 use List::MoreUtils qw(part);
11  
12 our $VERSION = '0.01';
13  
14 sub new {
15 my $class = shift;
16 my $self = bless {}, $class;
17  
18 return $self;
19 }
20  
21 sub use_these_analysers {
22 my $self = shift;
23  
24 # Module::Pluggable does not give us the option of postponing
25 # the require stage until we actually request the plugin be used.
26 eval " CORE::require $_ " or warn $@ for @_;
27 $self->{analysers} = [map {$_->new} @_];
28 }
29  
30 sub analyse {
31 my $self = shift;
32 my @data = @_;
33  
34 $self->add( $_ ) for @data;
35 }
36  
37 sub add {
38 my $self = shift;
39 my $datum = shift;
40  
41 $self->{discard} ||= [];
42  
43 my ($discarded_analysers, $remaining_analysers)
44 = part { $_->analyse( $datum ) ? 1 : 0 } @{ $self->{analysers} };
45  
46 $discarded_analysers ||= []; $remaining_analysers ||= [];
47  
48 $self->{analysers} = $remaining_analysers;
49 push @{ $self->{discard} }, @$discarded_analysers;
50 }
51  
52 sub result {
53 my $self = shift;
54  
55 # Some analysers may be lazy or may need to wait.
56 $_->done for @{$self->{analysers}};
57  
58 return ($self->{analysers}, $self->{discard}) if wantarray;
59 return $self->{analysers};
60 }
61  
62 1;
63 __END__
« Sequence/Analyser/OL/Numbered.pm ↑ Summary Sequence/Analyser.pm »