lib/App/Tel/Color/CiscoPingRainbow.pm

filter: Statementstmt 100% 31 / 31 Branchbran 83.3% 5 / 6 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 7 / 7 Podpod 100% 2 / 2 totaltotal 90.2% 46 / 51 CC 5 SCAR 8.3
CC
5
Cov
92%
colorize
4.0
new
2.1
BEGIN
1.0
CRAP 2.3
« lib/App/Tel/Color/Base.pm ↑ Summary blib/lib/App/Tel/Passwd/Mock.pm »
1 package App::Tel::Color::CiscoPingRainbow;
2 2 ▶use parent 'App::Tel::Color::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use Term::ANSIColor;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 =head2 new
8  
9 my $color = App::Tel::Color::CiscoPingRainbow->new;
10  
11 New color object..
12  
13 =cut
14  
15 1 ▶sub new {
Subroutine new: called CC=2 SCAR=7.2
Pod documented
16 1 my $proto = shift;
17 1 ▶ my $class = ref($proto) || $proto;
Condition33%1/3
ref $proto || $proto
l!l&&r!l&&!r
010
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
18  
19 1 my $self = bless( {
20 'current_color' => 0,
21 'ping' => 0,
22 }, $class);
23  
24 1 $self->{'color_count'} = scalar $self->get_colors();
25 1 return $self;
26 }
27  
28 16 ▶sub _next_color {
Subroutine _next_color: called CC=1 SCAR=0.0
29 16 my $self = shift;
30 16 return colored(@_, $self->get_colors($self->{current_color}++ % $self->{color_count}));
31 }
32  
33 =head2 colorize
34  
35 my $output = $self->colorize($input);
36  
37 Given a line of text from a cisco router, this will try to colorize it.
38  
39 =cut
40  
41  
42 3 ▶sub colorize {
Subroutine colorize: called CC=4 SCAR=13.9
Pod documented
43 3 my ($self, $text) = @_;
44  
45 # We need to define a start point in the buffer that the dot regex isn't
46 # allowed to search before so that this line and ones before it with
47 # dots don't get red dots.
48 3 ▶ if ($text =~ /Sending \d+, \d+-byte ICMP Echos to/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($text =~ /Sending \d+, \d+-byte ICMP Echos to/) { } 1 2 3
elsif ($self->{'ping'}) { } 2 0 2
49 1 $self->{ping}=1;
50 } elsif ($self->{ping}) {
51 2 $text =~ s/(\!)/$self->_next_color($1)/eg;
52 2 $text =~ s/(\.)/colored('.', 'red')/eg;
53 2 ▶ if ($text =~ /Success rate is/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($text =~ /Success rate is/) 1 1 2
54 1 $self->{ping}=0;
55 1 $self->{current_color}=0;
56 }
57 }
58 3 return $text;
59 }
60  
61 2 1;
« lib/App/Tel/Color/Base.pm ↑ Summary blib/lib/App/Tel/Passwd/Mock.pm »