| 1 | package Data::LineBuffer; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 1 | our $VERSION = '0.01'; | |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | sub new | ||||||||||||||||||||||||||||
| 9 | 5 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=7 SCAR=19.9
Pod
documented
| |||||||||||||||||||||||||||||
| 10 | 5 | my $class = shift; | |||||||||||||||||||||||||||
| 11 | 5 | ▶ | $class = 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
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 5 | my $self = bless { cache => [], | |||||||||||||||||||||||||||
| 14 | line => 1 }, $class; | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | # we use closures like mad here to make a uniform definition | ||||||||||||||||||||||||||||
| 19 | # of the get method possible. | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | # Don't shift next argument; need to get a reference | ||||||||||||||||||||||||||||
| 22 | # to it if it's a scalar. | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 5 | my $what = $_[0]; | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | # scalar? split on newlines | ||||||||||||||||||||||||||||
| 27 | 5 | ▶ | unless ( ref $_[0] ) | ||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||
| 28 | { | ||||||||||||||||||||||||||||
| 29 | 1 | my $sref = \$_[0]; | |||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 1 | pos( $$sref ) = 0; | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | $self->{next} = | ||||||||||||||||||||||||||||
| 34 | 6 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=12.0
| |||||||||||||||||||||||||||||
| 35 | 6 | ▶ | defined pos($$sref) ? scalar $$sref =~ /^(.*)$/mg && $1 : undef | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
scalar $$sref =~ /^(.*)$/gm and $1
MC/DC50%1/2
scalar $$sref =~ /^(.*)$/gm and $1
scalar $$sref =~ /^(.*)$/gm
$1
Truth table66%2/3
A and B
A= scalar $$sref =~ /^(.*)$/gmB= $1
| |||||||||||||||||||||||||||||
| 36 | 1 | }; | |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | # array? grab the next element | ||||||||||||||||||||||||||||
| 40 | elsif ( 'ARRAY' eq ref($what) ) | ||||||||||||||||||||||||||||
| 41 | { | ||||||||||||||||||||||||||||
| 42 | 1 | my $idx = 0; | |||||||||||||||||||||||||||
| 43 | $self->{next} = | ||||||||||||||||||||||||||||
| 44 | 1 | ▶ | sub { $idx == @$what ? undef : $what->[$idx++] }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.2
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | # glob (we're assuming file glob)? read next line | ||||||||||||||||||||||||||||
| 48 | elsif ( 'GLOB' eq ref($what) ) | ||||||||||||||||||||||||||||
| 49 | { | ||||||||||||||||||||||||||||
| 50 | 1 | ▶ | $self->{next} = sub { scalar <$what> }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | # subroutine? call it | ||||||||||||||||||||||||||||
| 54 | elsif ( 'CODE' eq ref($what) ) | ||||||||||||||||||||||||||||
| 55 | { | ||||||||||||||||||||||||||||
| 56 | 1 | $self->{next} = $what; | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | # file handle? read next line | ||||||||||||||||||||||||||||
| 60 | elsif ( UNIVERSAL::isa($what, 'IO::File') ) | ||||||||||||||||||||||||||||
| 61 | { | ||||||||||||||||||||||||||||
| 62 | 1 | ▶ | $self->{next} = sub { scalar <$what> }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | else | ||||||||||||||||||||||||||||
| 66 | { | ||||||||||||||||||||||||||||
| 67 | 0 | undef $self; | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 5 | $self; | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 45 | ▶ | sub pos { $_[0]->{line} } | ||||||||||||||||||||||||||
|
Subroutine
pos: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | sub unget | ||||||||||||||||||||||||||||
| 76 | 15 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
unget: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 77 | 15 | my $self = shift; | |||||||||||||||||||||||||||
| 78 | 15 | push @{$self->{cache}}, @_; | |||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 15 | $self->{line} -= @_; | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | sub get | ||||||||||||||||||||||||||||
| 84 | 45 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
get: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 85 | 45 | my $self = shift; | |||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 45 | my $ret = pop @{$self->{cache}}; | |||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 45 | ▶ | $ret = &{$self->{next}} | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | unless defined $ret; | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 45 | ▶ | if ( defined $ret ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | { | ||||||||||||||||||||||||||||
| 94 | 45 | $self->{line}++; | |||||||||||||||||||||||||||
| 95 | 45 | chomp $ret; | |||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 45 | $ret; | |||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 0 | ▶ | sub cache { $_[0]->{cache} }; | ||||||||||||||||||||||||||
|
Subroutine
cache: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 1 | 1; | |||||||||||||||||||||||||||
| 106 | __END__ | ||||||||||||||||||||||||||||