line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package List::Analyse::Sequence; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
85262
|
use warnings; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
71
|
|
4
|
2
|
|
|
2
|
|
12
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
97
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use Module::Pluggable ( |
7
|
0
|
|
|
|
|
|
search => [ "List::Analyse::Sequence::Analyser" ], |
8
|
|
|
|
|
|
|
sub_name => 'analysers', |
9
|
2
|
|
|
2
|
|
6658
|
); |
|
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__ |