line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package IO::Buffered::FixedSize; |
2
|
8
|
|
|
8
|
|
40
|
use strict; |
|
8
|
|
|
|
|
41
|
|
|
8
|
|
|
|
|
273
|
|
3
|
8
|
|
|
8
|
|
37
|
use warnings; |
|
8
|
|
|
|
|
39
|
|
|
8
|
|
|
|
|
198
|
|
4
|
8
|
|
|
8
|
|
56
|
use Carp; |
|
8
|
|
|
|
|
13
|
|
|
8
|
|
|
|
|
495
|
|
5
|
|
|
|
|
|
|
|
6
|
8
|
|
|
8
|
|
39
|
use base ("IO::Buffered"); |
|
8
|
|
|
|
|
20
|
|
|
8
|
|
|
|
|
714
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# FIXME: Write documentation |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '1.00'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 NAME |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
IO::Buffered::FixedSize - Fixed size buffering |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 DESCRIPTION |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 SYNOPSIS |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 METHODS |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=over |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=cut |
25
|
|
|
|
|
|
|
|
26
|
8
|
|
|
8
|
|
40
|
use base "Exporter"; |
|
8
|
|
|
|
|
13
|
|
|
8
|
|
|
|
|
4752
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
our @EXPORT_OK = qw(); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=item new() |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=cut |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub new { |
35
|
4
|
|
|
4
|
1
|
10
|
my ($class, $length, %opts) = @_; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# Check if $length is a number |
38
|
4
|
100
|
66
|
|
|
556
|
croak "FixedSize should be a number" if !(defined $length |
39
|
|
|
|
|
|
|
and $length =~ /^\d+$/); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# Check that $regexp is a Regexp or a non empty string |
42
|
1
|
50
|
0
|
|
|
6
|
croak "Option MaxSize should be a positiv integer" if $opts{MaxSize} and !( |
|
|
|
33
|
|
|
|
|
43
|
|
|
|
|
|
|
$opts{MaxSize} =~ /^\d+$/ and $opts{MaxSize} > 0); |
44
|
|
|
|
|
|
|
|
45
|
1
|
|
|
|
|
6
|
my %self = ( |
46
|
|
|
|
|
|
|
buffer => '', |
47
|
|
|
|
|
|
|
length => $length, |
48
|
|
|
|
|
|
|
maxsize => $opts{MaxSize}, |
49
|
|
|
|
|
|
|
); |
50
|
|
|
|
|
|
|
|
51
|
1
|
|
33
|
|
|
19
|
return bless \%self, (ref $class || $class); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=item flush($str, ...) |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=cut |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub flush { |
60
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
61
|
0
|
|
|
|
|
0
|
$self->{buffer} = join ('', @_); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=item buffer() |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=cut |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub buffer { |
69
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
70
|
0
|
|
|
|
|
0
|
return $self->{buffer}; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=item write($str, ...) |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=cut |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub write { |
78
|
2
|
|
|
2
|
1
|
2681
|
my $self = shift; |
79
|
2
|
|
|
|
|
9
|
my $str = join ('', @_); |
80
|
|
|
|
|
|
|
|
81
|
2
|
50
|
|
|
|
7
|
if(my $maxsize = $self->{maxsize}) { |
82
|
0
|
|
|
|
|
0
|
my $length = length($str) + length($self->{buffer}); |
83
|
0
|
0
|
|
|
|
0
|
if($length > $maxsize) { |
84
|
0
|
|
|
|
|
0
|
croak "Buffer overrun"; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
2
|
|
|
|
|
7
|
$self->{buffer} .= $str; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=item read() |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=cut |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub read { |
96
|
4
|
|
|
4
|
1
|
10
|
my ($self) = (@_); |
97
|
4
|
|
|
|
|
7
|
my $length = $self->{length}; |
98
|
|
|
|
|
|
|
|
99
|
4
|
|
|
|
|
6
|
my @records; |
100
|
4
|
|
|
|
|
14
|
while($length <= length($self->{buffer})) { |
101
|
3
|
|
|
|
|
7
|
push(@records, substr($self->{buffer}, 0, $length)); |
102
|
3
|
|
|
|
|
10
|
substr($self->{buffer}, 0, $length) = ''; |
103
|
|
|
|
|
|
|
} |
104
|
4
|
|
|
|
|
13
|
return @records; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=item returns_last() |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=cut |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub returns_last { |
112
|
0
|
|
|
0
|
1
|
0
|
return 1; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=item read_last() |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=cut |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub read_last { |
120
|
2
|
|
|
2
|
1
|
669
|
my ($self) = @_; |
121
|
2
|
|
|
|
|
6
|
my @records = $self->read(); |
122
|
2
|
100
|
|
|
|
8
|
push(@records, $self->{buffer}) if $self->{buffer} ne ''; |
123
|
2
|
|
|
|
|
4
|
$self->{buffer} = ''; |
124
|
2
|
|
|
|
|
11
|
return @records; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=back |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head1 AUTHOR |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
Troels Liebe Bentsen |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head1 COPYRIGHT |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
Copyright(C) 2008 Troels Liebe Bentsen |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
139
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=cut |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
1; |
144
|
|
|
|
|
|
|
|