| 1 | package IO::Buffered::FixedSize; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 9 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | 9 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 9 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 9 | ▶ | use base ("IO::Buffered"); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | # FIXME: Write documentation | ||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 9 | 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 | 9 | ▶ | use base "Exporter"; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | 9 | our @EXPORT_OK = qw(); | |||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | =item new() | ||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | 4 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=7 SCAR=23.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 4 | my ($class, $length, %opts) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | # Check if $length is a number | ||||||||||||||||||||||||||||||||||||||||||
| 38 | 4 | ▶ | croak "FixedSize should be a number" if !(defined $length | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $length and $length =~ /^\d+$/
MC/DC50%1/2
defined $length and $length =~ /^\d+$/
defined $length
$length =~ /^\d+$/
Truth table66%2/3
A and B
A= defined $lengthB= $length =~ /^\d+$/
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | and $length =~ /^\d+$/); | ||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | # Check that $regexp is a Regexp or a non empty string | ||||||||||||||||||||||||||||||||||||||||||
| 42 | croak "Option MaxSize should be a positiv integer" if $opts{MaxSize} and !( | ||||||||||||||||||||||||||||||||||||||||||
| 43 | 1 | ▶ | $opts{MaxSize} =~ /^\d+$/ and $opts{MaxSize} > 0); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition16%1/6
$opts{"MaxSize"} and not $opts{"MaxSize"} =~ /^\d+$/ && $opts{"MaxSize"} > 0
$opts{'MaxSize'} =~ /^\d+$/ && $opts{'MaxSize'} > 0
MC/DC0%0/3
$opts{"MaxSize"} and not $opts{"MaxSize"} =~ /^\d+$/ && $opts{"MaxSize"} > 0
$opts{"MaxSize"}
$opts{'MaxSize'} =~ /^\d+$/
$opts{'MaxSize'} > 0
Truth table25%1/4
A and not(B && C)
A= $opts{"MaxSize"}B= $opts{'MaxSize'} =~ /^\d+$/C= $opts{'MaxSize'} > 0
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | my %self = ( | ||||||||||||||||||||||||||||||||||||||||||
| 46 | buffer => '', | ||||||||||||||||||||||||||||||||||||||||||
| 47 | length => $length, | ||||||||||||||||||||||||||||||||||||||||||
| 48 | maxsize => $opts{MaxSize}, | ||||||||||||||||||||||||||||||||||||||||||
| 49 | 1 | ); | |||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | 1 | ▶ | return bless \%self, (ref $class || $class); | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $class || $class
MC/DC0%0/2
ref $class || $class
ref $class
$class
Truth table33%1/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | =item flush($str, ...) | ||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | ▶ | sub flush { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
flush: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | $self->{buffer} = join ('', @_); | |||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||
| 64 | =item buffer() | ||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | ▶ | sub buffer { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
buffer: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | return $self->{buffer}; | |||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | =item write($str, ...) | ||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | 2 | ▶ | sub write { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
write: called CC=3 SCAR=15.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 79 | 2 | my $str = join ('', @_); | |||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | 2 | ▶ | if(my $maxsize = $self->{maxsize}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | my $length = length($str) + length($self->{buffer}); | |||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | ▶ | if($length > $maxsize) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | croak "Buffer overrun"; | |||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | 2 | $self->{buffer} .= $str; | |||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | =item read() | ||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | 4 | ▶ | sub read { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 96 | 4 | my ($self) = (@_); | |||||||||||||||||||||||||||||||||||||||||
| 97 | 4 | my $length = $self->{length}; | |||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | 4 | my @records; | |||||||||||||||||||||||||||||||||||||||||
| 100 | 4 | ▶ | while($length <= length($self->{buffer})) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | 3 | push(@records, substr($self->{buffer}, 0, $length)); | |||||||||||||||||||||||||||||||||||||||||
| 102 | 3 | substr($self->{buffer}, 0, $length) = ''; | |||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||
| 104 | 4 | return @records; | |||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | =item returns_last() | ||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||
| 109 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | ▶ | sub returns_last { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
returns_last: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||
| 115 | =item read_last() | ||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||
| 119 | 2 | ▶ | sub read_last { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_last: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 120 | 2 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 121 | 2 | my @records = $self->read(); | |||||||||||||||||||||||||||||||||||||||||
| 122 | 2 | ▶ | push(@records, $self->{buffer}) if $self->{buffer} ne ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 123 | 2 | $self->{buffer} = ''; | |||||||||||||||||||||||||||||||||||||||||
| 124 | 2 | return @records; | |||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||
| 130 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||
| 132 | Troels Liebe Bentsen <tlb@rapanden.dk> | ||||||||||||||||||||||||||||||||||||||||||
| 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 | 9 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||