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 13     13   67099 use strict;
  13         34  
  13         570  
3 13     13   78 use warnings;
  13         31  
  13         5609  
4              
5             sub new {
6 97     97 0 455 my ($class, %args) = @_;
7 97 100       311 my $buffer = exists $args{buffer} ? $args{buffer} : "";
8             bless {
9             buffer => $buffer,
10 97 100       609 $args{keep} ? (keep => $buffer) : (),
11             }, $class;
12             }
13              
14             sub raw {
15 45     45 0 674 my $self = shift;
16 45 100       1272 exists $self->{keep} ? $self->{keep} : undef;
17             }
18              
19             sub add {
20 47     47 0 775 my ($self, $buffer) = @_;
21 47         686 $self->{buffer} .= $buffer;
22 47 100       293 $self->{keep} .= $buffer if exists $self->{keep};
23 47         133 $self;
24             }
25              
26             sub get {
27 169     169 0 2720 my ($self, $drain) = @_;
28 169 100       497 if ($drain) {
29 80 100       244 if (length $self->{buffer}) {
30 42         154 my @line = $self->get;
31 42 100 66     204 if (length $self->{buffer} and $self->{buffer} ne "\x0d") {
32 18         74 $self->{buffer} =~ s/[\x0d\x0a]+\z//;
33 18         53 push @line, $self->{buffer};
34             }
35 42         92 $self->{buffer} = "";
36 42         197 return @line;
37             } else {
38 38         176 return;
39             }
40             }
41 89         206 my @line;
42 89         1069 while ($self->{buffer} =~ s/\A(.*?(?:\x0d\x0a|\x0d|\x0a))//sm) {
43 161         730 my $line = $1;
44 161 50       383 next if $line eq "\x0d";
45 161         685 $line =~ s/[\x0d\x0a]+\z//;
46 161         885 push @line, $line;
47             }
48 89         600 return @line;
49             }
50              
51             1;