File Coverage

blib/lib/SyslogScan/Volume.pm
Criterion Covered Total %
statement 3 38 7.8
branch 0 4 0.0
condition n/a
subroutine 1 11 9.0
pod 0 10 0.0
total 4 63 6.3


line stmt bran cond sub pod time code
1             package SyslogScan::Volume;
2              
3             # For documentation, see the SyslogScan::Usage module
4              
5             $VERSION = 0.20;
6 0     0 0   sub Version { $VERSION };
7              
8 3     3   17 use strict;
  3         6  
  3         1467  
9              
10             # index values; we use array instead of hash for efficiency
11             my $MESSAGES = 0;
12             my $BYTES = 1;
13              
14             sub new
15             {
16 0     0 0   my $type = shift;
17 0           my $self = [0,0]; # Messages, Bytes
18 0           bless ($self,$type);
19 0           return $self;
20             }
21              
22             sub addSize
23             {
24 0     0 0   my $self = shift;
25 0           my $size = shift;
26            
27 0           $$self[$MESSAGES]++;
28 0           $$self[$BYTES] += $size;
29             }
30              
31             sub addVolume
32             {
33 0     0 0   my $self = shift;
34 0           my $other = shift;
35              
36 0           $$self[$MESSAGES] += $$other[$MESSAGES];
37 0           $$self[$BYTES] += $$other[$BYTES];
38             }
39              
40             sub dump
41             {
42 0     0 0   my $self = shift;
43 0           return $$self[$MESSAGES].','.$$self[$BYTES];
44             }
45              
46             sub getMessageCount
47             {
48 0     0 0   my $self = shift;
49 0           return $$self[$MESSAGES];
50             }
51              
52             sub getByteCount
53             {
54 0     0 0   my $self = shift;
55 0           return $$self[$BYTES];
56             }
57              
58             sub persist
59             {
60 0     0 0   my $self = shift;
61 0           my $outFH = shift;
62              
63 0           print $outFH $$self[$MESSAGES].','.$$self[$BYTES], "\n";
64             }
65              
66             sub restore
67             {
68 0     0 0   my $type = shift;
69 0           my $inFH = shift;
70              
71 0 0         defined($inFH) or die("no filehandle defined");
72              
73 0           my $volumeLine = <$inFH>;
74 0 0         if (! ($volumeLine =~ /^(\d+)\,(\d+)$/))
75             {
76 0           die "illegal volume line: $volumeLine";
77             }
78            
79 0           my $self = [$1, $2]; # messages, bytes
80 0           bless ($self,$type);
81 0           return $self;
82             }
83              
84             sub deepCopy
85             {
86 0     0 0   my $self = shift;
87              
88 0           my $copy = [$$self[$MESSAGES],$$self[$BYTES]];
89 0           bless($copy,ref($self));
90 0           return $copy;
91             }
92              
93             1;
94              
95             __END__