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 14     14   68312 use strict;
  14         50  
  14         412  
3 14     14   71 use warnings;
  14         37  
  14         6249  
4              
5             sub new {
6 112     112 0 656 my ($class, %args) = @_;
7 112 100       373 my $buffer = exists $args{buffer} ? $args{buffer} : "";
8             bless {
9             buffer => $buffer,
10 112 100       836 $args{keep} ? (keep => $buffer) : (),
11             }, $class;
12             }
13              
14             sub raw {
15 55     55 0 988 my $self = shift;
16 55 100       1562 exists $self->{keep} ? $self->{keep} : undef;
17             }
18              
19             sub add {
20 57     57 0 846 my ($self, $buffer) = @_;
21 57         580 $self->{buffer} .= $buffer;
22 57 100       370 $self->{keep} .= $buffer if exists $self->{keep};
23 57         210 $self;
24             }
25              
26             sub get {
27 193     193 0 2981 my ($self, $drain) = @_;
28 193 100       620 if ($drain) {
29 89 100       284 if (length $self->{buffer}) {
30 47         174 my @line = $self->get;
31 47 100 66     265 if (length $self->{buffer} and $self->{buffer} ne "\x0d") {
32 22         109 $self->{buffer} =~ s/[\x0d\x0a]+\z//;
33 22         58 push @line, $self->{buffer};
34             }
35 47         107 $self->{buffer} = "";
36 47         252 return @line;
37             } else {
38 42         234 return;
39             }
40             }
41 104         244 my @line;
42 104         1462 while ($self->{buffer} =~ s/\A(.*?(?:\x0d\x0a|\x0d|\x0a))//sm) {
43 181         854 my $line = $1;
44 181 50       468 next if $line eq "\x0d";
45 181         884 $line =~ s/[\x0d\x0a]+\z//;
46 181         970 push @line, $line;
47             }
48 104         885 return @line;
49             }
50              
51             1;