File Coverage

blib/lib/AI/Categorizer/Collection/InMemory.pm
Criterion Covered Total %
statement 31 31 100.0
branch 3 4 75.0
condition n/a
subroutine 8 8 100.0
pod 4 4 100.0
total 46 47 97.8


line stmt bran cond sub pod time code
1             package AI::Categorizer::Collection::InMemory;
2 8     8   5178 use strict;
  8         16  
  8         296  
3              
4 8     8   44 use AI::Categorizer::Collection;
  8         15  
  8         179  
5 8     8   39 use base qw(AI::Categorizer::Collection);
  8         16  
  8         727  
6              
7 8     8   50 use Params::Validate qw(:types);
  8         19  
  8         3968  
8              
9             __PACKAGE__->valid_params
10             (
11             data => { type => HASHREF },
12             );
13              
14             sub new {
15 6     6 1 3451 my $self = shift()->SUPER::new(@_);
16            
17 6         17 while (my ($name, $params) = each %{$self->{data}}) {
  30         122  
18 24         38 foreach (@{$params->{categories}}) {
  24         69  
19 24 50       56 next if ref $_;
20 24         112 $_ = AI::Categorizer::Category->by_name(name => $_);
21             }
22             }
23              
24 6         21 return $self;
25             }
26              
27             sub next {
28 28     28 1 496 my $self = shift;
29 28 100       43 my ($name, $params) = each %{$self->{data}} or return;
  28         132  
30 23         118 return AI::Categorizer::Document->new(name => $name, %$params);
31             }
32              
33             sub rewind {
34 1     1 1 385 my $self = shift;
35 1         15 scalar keys %{$self->{data}};
  1         3  
36 1         3 return;
37             }
38              
39             sub count_documents {
40 2     2 1 25 my $self = shift;
41 2         3 return scalar keys %{$self->{data}};
  2         7  
42             }
43              
44             1;