File Coverage

blib/lib/Command/Runner/LineBuffer.pm
Criterion Covered Total %
statement 32 32 100.0
branch 15 16 93.7
condition 2 3 66.6
subroutine 6 6 100.0
pod 0 4 0.0
total 55 61 90.1


line stmt bran cond sub pod time code
1             package Command::Runner::LineBuffer;
2 11     11   56690 use strict;
  11         24  
  11         392  
3 11     11   61 use warnings;
  11         59  
  11         4642  
4              
5             sub new {
6 70     70 0 372 my ($class, %args) = @_;
7 70 100       300 my $buffer = exists $args{buffer} ? $args{buffer} : "";
8             bless {
9             buffer => $buffer,
10 70 100       596 $args{keep} ? (keep => $buffer) : (),
11             }, $class;
12             }
13              
14             sub raw {
15 30     30 0 556 my $self = shift;
16 30 100       1072 exists $self->{keep} ? $self->{keep} : undef;
17             }
18              
19             sub add {
20 33     33 0 686 my ($self, $buffer) = @_;
21 33         332 $self->{buffer} .= $buffer;
22 33 100       348 $self->{keep} .= $buffer if exists $self->{keep};
23 33         133 $self;
24             }
25              
26             sub get {
27 113     113 0 2351 my ($self, $drain) = @_;
28 113 100       383 if ($drain) {
29 52 100       222 if (length $self->{buffer}) {
30 28         125 my @line = $self->get;
31 28 100 66     142 if (length $self->{buffer} and $self->{buffer} ne "\x0d") {
32 11         33 $self->{buffer} =~ s/[\x0d\x0a]+\z//;
33 11         23 push @line, $self->{buffer};
34             }
35 28         65 $self->{buffer} = "";
36 28         99 return @line;
37             } else {
38 24         153 return;
39             }
40             }
41 61         128 my @line;
42 61         758 while ($self->{buffer} =~ s/\A(.*?(?:\x0d\x0a|\x0d|\x0a))//sm) {
43 121         553 my $line = $1;
44 121 50       314 next if $line eq "\x0d";
45 121         658 $line =~ s/[\x0d\x0a]+\z//;
46 121         617 push @line, $line;
47             }
48 61         557 return @line;
49             }
50              
51             1;