File Coverage

blib/lib/App/RecordStream/Clumper/KeyLRU.pm
Criterion Covered Total %
statement 43 52 82.6
branch 2 2 100.0
condition n/a
subroutine 11 14 78.5
pod 0 8 0.0
total 56 76 73.6


line stmt bran cond sub pod time code
1             package App::RecordStream::Clumper::KeyLRU;
2              
3 4     4   24 use strict;
  4         9  
  4         93  
4 4     4   18 use warnings;
  4         7  
  4         82  
5              
6 4     4   18 use App::RecordStream::Clumper::Key;
  4         8  
  4         65  
7 4     4   15 use App::RecordStream::DomainLanguage::Registry;
  4         8  
  4         67  
8 4     4   1318 use App::RecordStream::LRUSheriff;
  4         11  
  4         100  
9              
10 4     4   23 use base 'App::RecordStream::Clumper::Key';
  4         9  
  4         1350  
11              
12             sub new
13             {
14 5     5 0 10 my $class = shift;
15 5         9 my $field = shift;
16 5         10 my $size = shift;
17              
18 5         29 my $this = $class->SUPER::new($field);
19              
20 5         15 $this->{'size'} = $size;
21              
22 5         22 return $this;
23             }
24              
25             sub new_from_valuation
26             {
27 0     0 0 0 my $class = shift;
28 0         0 my $name = shift;
29 0         0 my $valuation = shift;
30 0         0 my $size = shift;
31              
32 0         0 my $this = $class->SUPER::new_from_valuation($name, $valuation);
33              
34 0         0 $this->{'size'} = $size;
35              
36 0         0 return $this;
37             }
38              
39             sub long_usage
40             {
41 0     0 0 0 return <
42             Usage: keylru,,
43             Clump records by the value for a key, limiting number of active clumps to
44             EOF
45             }
46              
47             sub short_usage
48             {
49 0     0 0 0 return "clump records by the value for a key, limiting number of active clumps";
50             }
51              
52             sub argct
53             {
54 5     5 0 14 return 2;
55             }
56              
57             sub key_clumper_begin
58             {
59 11     11 0 39 return App::RecordStream::LRUSheriff->new();
60             }
61              
62             sub key_clumper_push_record
63             {
64 62     62 0 99 my $this = shift;
65 62         90 my $cookie = shift;
66 62         85 my $value = shift;
67 62         102 my $record = shift;
68 62         91 my $next = shift;
69              
70             {
71 62         102 my $next_cookie = $cookie->find($value);
  62         168  
72 62 100       144 if(!defined($next_cookie))
73             {
74 34         92 $cookie->put($value, $next_cookie = $next->key_clumper_callback_begin());
75             }
76              
77 62         180 $next->key_clumper_callback_push_record($next_cookie, $record);
78             }
79              
80 62         172 for my $next_cookie ($cookie->purgenate($this->{'size'}))
81             {
82 13         35 $next->key_clumper_callback_end($next_cookie);
83             }
84             }
85              
86             sub key_clumper_end
87             {
88 11     11 0 21 my $this = shift;
89 11         16 my $cookie = shift;
90 11         19 my $next = shift;
91              
92 11         27 for my $next_cookie ($cookie->purgenate(0))
93             {
94 21         63 $next->key_clumper_callback_end($next_cookie);
95             }
96             }
97              
98             App::RecordStream::Clumper->register_implementation('keylru', __PACKAGE__);
99              
100             App::RecordStream::DomainLanguage::Registry::register_vfn(__PACKAGE__, 'new_from_valuation', 'keylru', 'SCALAR', 'VALUATION', 'SCALAR');
101             App::RecordStream::DomainLanguage::Registry::register_vfn(__PACKAGE__, 'new_from_valuation', 'key', 'SCALAR', 'VALUATION', 'SCALAR');
102              
103             1;