PerlIO/via/EscStatus/Parser.pm

filter: Statementstmt 100% 24 / 24 Branchbran 100% 4 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod 100% 2 / 2 totaltotal 100% 36 / 36 CC 3 SCAR 5.6
CC
3
Cov
100%
parse
3.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.8
« ProgressMonitor/Stringify/ToEscStatus.pm ↑ Summary PerlIO/via/EscStatus/ShowAll.pm »
1 # Copyright 2008, 2009, 2010, 2011, 2012 Kevin Ryde
2  
3 # This file is part of PerlIO-via-EscStatus.
4 #
5 # PerlIO-via-EscStatus is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License as published
7 # by the Free Software Foundation; either version 3, or (at your option) any
8 # later version.
9 #
10 # PerlIO-via-EscStatus is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
13 # Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License along
16 # with PerlIO-via-EscStatus. If not, see <http://www.gnu.org/licenses/>.
17  
18 package PerlIO::via::EscStatus::Parser;
19 5 ▶use 5.006; # for $-[0]
Subroutine BEGIN: called CC=1 SCAR=0.0
20 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 5 our $VERSION = 12;
24  
25 # This regexp generated by devel/partial-end.pl. It matches either a whole
26 # ESCSTATUS_STR anywhere, or a leading portion of it at the end of the
27 # string, like say /\e_$/. Frequently there won't be any Esc's left in the
28 # string and the first \e will quickly fail to match.
29 #
30 5 ▶use constant ESCSTATUS_STR_PARTIAL_REGEXP =>
Subroutine BEGIN: called CC=1 SCAR=0.0
31 5 qr/\e(?:$|_(?:$|E(?:$|s(?:$|c(?:$|S(?:$|t(?:$|a(?:$|t(?:$|u(?:$|s(?:$|\e(?:$|\\))))))))))))/;
32  
33 7 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
34 7 my ($class) = @_;
35 7 return bless { partial => '' }, $class;
36 }
37  
38 20 ▶sub parse {
Subroutine parse: called CC=3 SCAR=11.0
Pod documented
39 20 my ($self, $buf) = @_;
40 20 my $status = undef;
41 20 $buf = $self->{'partial'} . $buf;
42  
43 # whole statuses
44 20 ▶ if ($buf =~ s/\e_EscStatus\e\\([^\n]*)\n//g) {
Branch: 1 branch
BranchTrueFalseTotal
if ($buf =~ s/\e_EscStatus\e\\([^\n]*)\n//g) 9 11 20
45 9 $status = $1;
46 }
47 20 ▶ my $pos = ($buf =~ ESCSTATUS_STR_PARTIAL_REGEXP
Branch: 1 branch
BranchTrueFalseTotal
$buf =~ /\e(?:$|_(?:$|E(?:$|s(?:$|c(?:$|S(?:$|t(?:$|a(?:$|t(?:$|u(?:$|s(?:$|\e(?:$|\\))))))))))))/ ? : 3 17 20
48 ? $-[0] # start of match
49 : length ($buf));
50 20 $self->{'partial'} = substr ($buf, $pos); # match onwards
51 20 $buf = substr ($buf, 0, $pos); # prematch
52 20 return ($status, $buf);
53 }
54  
55 5 1;
56 __END__
« ProgressMonitor/Stringify/ToEscStatus.pm ↑ Summary PerlIO/via/EscStatus/ShowAll.pm »