| 1 | package IO::Buffered::Last; | ||||||||||||||||||||||||||||||||||||||||||
| 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::Last - Last read 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 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=5 SCAR=21.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 1 | my ($class, %opts) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | # Check that $regexp is a Regexp or a non empty string | ||||||||||||||||||||||||||||||||||||||||||
| 38 | croak "Option MaxSize should be a positiv integer" if $opts{MaxSize} and !( | ||||||||||||||||||||||||||||||||||||||||||
| 39 | 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
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | my %self = ( | ||||||||||||||||||||||||||||||||||||||||||
| 42 | buffer => '', | ||||||||||||||||||||||||||||||||||||||||||
| 43 | maxsize => $opts{MaxSize}, | ||||||||||||||||||||||||||||||||||||||||||
| 44 | 1 | ); | |||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | 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
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | =item flush($str, ...) | ||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | ▶ | sub flush { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
flush: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | $self->{buffer} = join ('', @_); | |||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | =item buffer() | ||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | 2 | ▶ | sub buffer { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
buffer: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 64 | 2 | return $self->{buffer}; | |||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | =item write($str, ...) | ||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | 2 | ▶ | sub write { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
write: called CC=3 SCAR=15.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 73 | 2 | my $str = join ('', @_); | |||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | 2 | ▶ | if(my $maxsize = $self->{maxsize}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | my $length = length($str) + length($self->{buffer}); | |||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | ▶ | if($length > $maxsize) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | croak "Buffer overrun"; | |||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | 2 | $self->{buffer} .= $str; | |||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | =item read() | ||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | 2 | ▶ | sub read { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | 2 | my @array; | |||||||||||||||||||||||||||||||||||||||||
| 91 | 2 | return @array; | |||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | =item returns_last() | ||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | ▶ | sub returns_last { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
returns_last: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||
| 102 | =item read_last() | ||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | 2 | ▶ | sub read_last { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_last: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 107 | 2 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 108 | 2 | my @records; | |||||||||||||||||||||||||||||||||||||||||
| 109 | 2 | ▶ | push(@records, $self->{buffer}) if $self->{buffer} ne ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 110 | 2 | $self->{buffer} = ''; | |||||||||||||||||||||||||||||||||||||||||
| 111 | 2 | return @records; | |||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | Troels Liebe Bentsen <tlb@rapanden.dk> | ||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||
| 120 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||
| 122 | Copyright(C) 2008 Troels Liebe Bentsen | ||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||
| 124 | This library is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||||||||||||||||
| 125 | it under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||
| 127 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||
| 129 | 9 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||