Interact/Transport/Role/StripControlChars.pm

filter: Statementstmt 100% 21 / 21 Branchbran 100% 2 / 2 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 93.3% 28 / 30 CC 4 SCAR 10.0
CC
4
Cov
96%
__ANON__
4.0
BEGIN
1.0
BEGIN
1.0
CRAP 2.7
« Interact/Role/FindMatch.pm ↑ Summary Interact/Transport/Wrapper/IPC_Run.pm »
1 package Net::CLI::Interact::Transport::Role::StripControlChars;
2 8 $Net::CLI::Interact::Transport::Role::StripControlChars::VERSION = '2.400002';
3 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 8 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 8 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 8 my %ansi_codes = (
9 1 => q/\x1b\[\d+;\d+H/, # code_position_cursor
10 3 => q/\x1b\[\?25h/, #code_show_cursor
11 4 => q/\x1b\x45/, #code_next_line
12 5 => q/\x1b\[2K/, #code_erase_line
13 6 => q/\x1b\[K/, #code_erase_start_line
14 7 => q/\x1b\[\d+;\d+r/, #code_enable_scroll
15 68 => q/\e\[\??\d+(;\d+)*[A-Za-z]/, #VLZ addon from ytti/oxidized
16 );
17  
18 # https://github.com/ollyg/Net-CLI-Interact/issues/22
19 4 ▶around 'buffer' => sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
20 4 my $orig = shift;
21 4 ▶ my $buffer = ($orig->(@_) || '');
Condition50%1/2
&$orig(@_) || ''
l!l
04
MC/DC0%0/1
&$orig(@_) || ''
&$orig(@_)
Truth table50%1/2
A
A= &$orig(@_)
Aresult
11
00
22  
23 # remove control characters
24 4 $buffer =~ s/[\000-\010\013\014\016-\032\034-\037]//g;
25  
26 # strip ANSI terminal codes
27 4 foreach my $code (sort keys %ansi_codes) {
28 28 my $to = '';
29 28 ▶ $to = "\n" if ($code == 4); # CODE_NEXT_LINE must substitute with '\n'
Branch: 1 branch
BranchTrueFalseTotal
if $code == 4 4 24 28
30 28 $buffer =~ s/$ansi_codes{$code}/$to/g;
31 }
32  
33 4 return $buffer;
34 8 };
35  
36 =pod
37  
38 =cut
39  
40 8 1;
« Interact/Role/FindMatch.pm ↑ Summary Interact/Transport/Wrapper/IPC_Run.pm »