File Coverage

blib/lib/POE/Framework/MIDI/Ruleset.pm
Criterion Covered Total %
statement 12 28 42.8
branch 0 8 0.0
condition n/a
subroutine 4 6 66.6
pod 1 2 50.0
total 17 44 38.6


line stmt bran cond sub pod time code
1             # $Id: Ruleset.pm,v 1.1.1.1 2004/11/22 17:52:11 root Exp $
2              
3             package POE::Framework::MIDI::Ruleset;
4 2     2   232071 use strict;
  2         6  
  2         79  
5 2     2   11 use vars qw($VERSION); $VERSION = '0.02';
  2         3  
  2         102  
6 2     2   11 use base 'POE::Framework::MIDI::Rule';
  2         4  
  2         740  
7 2     2   11 use POE::Framework::MIDI::Rule;
  2         2  
  2         543  
8              
9             # no support for partially matching rules yet...
10             sub test {
11 0 0   0 1   my ($self, $thing_to_test) = @_
12             or die __PACKAGE__ . '::test() needs something to test, and rule to test against';
13              
14             # We should probably start using bar and phrase objects (??)
15             # otherwise this could test a bar against a phrase-based
16             # ruleset.
17             #
18             # Eventually this should also be extended to allow for partially
19             # matching rules.
20 0           my $matches_all;
21              
22             # Commented-out just to show the code below.
23             # for ( @{$self->{cfg}->{rules}} ) {
24             # my $res = $_->test($thing_to_test);
25             # $matches_all = $res == 1 ? 1 : undef;
26             # }
27             # return $matches_all;
28              
29             # How about a simple average of the running tally of individual
30             # rule matchings, where a rule test returns 1 for full 100%
31             # match, zero for no match at all, and some decimal for partial.
32 0           my $average = 0;
33 0           my @matches = ();
34              
35             # Sum and keep track of the individual rule matchings.
36 0           for (@{ $self->{cfg}{rules} }) {
  0            
37 0           my $res = $_->test($thing_to_test);
38 0           push @matches, $res;
39 0           $average += $res;
40             }
41              
42             # Average the combined rule matchings if there are any.
43 0           $average /= @{ $self->{cfg}{rules} }
  0            
44 0 0         if @{ $self->{cfg}{rules} };
45              
46             # Return the average number of matches in a scalar context,
47             # and the actual rule matches in array context.
48 0 0         return wantarray ? @matches : $average;
49             }
50              
51             sub rules {
52 0     0 0   my $self = shift;
53 0 0         wantarray ? return @{$self->{cfg}->{rules}} : return $self->{cfg}->{rules};
  0            
54             }
55              
56             1;
57              
58             __END__