| 1 | package App::Tel::Color::Base; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | =head1 name | ||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | App::Tel::Color::Base - parent stub and examples for Color modules | ||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | =cut | ||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | 2 | ▶ | use Term::ANSIColor; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 2 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | 2 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | 2 | our $VERSION = '0.2'; | |||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | 2 | $Term::ANSIColor::AUTORESET++; # reset color after each print | |||||||||||||||||||
| 16 | 0 | ▶ | $SIG{INT} = sub { print "\n"; exit; }; # reset color after Ctrl-C | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=2.6
| |||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | 2 | our @colors = qw ( GREEN YELLOW BLUE MAGENTA CYAN WHITE ); | |||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | # Bright colors were added after Term::ANSIColor 3.00 | ||||||||||||||||||||
| 21 | 2 | ▶ | if ($Term::ANSIColor::VERSION >= 3.00) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 22 | 2 | push(@colors, qw ( | |||||||||||||||||||
| 23 | BRIGHT_GREEN BRIGHT_YELLOW | ||||||||||||||||||||
| 24 | BRIGHT_BLUE BRIGHT_MAGENTA BRIGHT_CYAN BRIGHT_WHITE | ||||||||||||||||||||
| 25 | )); | ||||||||||||||||||||
| 26 | } | ||||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | =head1 METHODS | ||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | =head2 new | ||||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | my $colorobject = new App::Tel::Base; | ||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | Initializes a new color object. | ||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | =cut | ||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | 6 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||
| 41 | 6 | my $proto = shift; | |||||||||||||||||||
| 42 | 6 | ▶ | my $class = ref($proto) || $proto; | ||||||||||||||||||
|
Condition33%1/3
ref $proto || $proto
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | 6 | return bless( { }, $class); | |||||||||||||||||||
| 45 | } | ||||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | =head2 colorize | ||||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | my $output = $colorobject->colorize('text'); | ||||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | Normally this will consume text from an input buffer and have some logic that | ||||||||||||||||||||
| 52 | determines how it will color the output. This method is designed to be | ||||||||||||||||||||
| 53 | overridden in all child modules. | ||||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | =cut | ||||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | 0 | ▶ | sub colorize { undef } | ||||||||||||||||||
|
Subroutine
colorize: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | =head2 parse | ||||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | $colorobject->parse($buffer, $callback); | ||||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | Breaks a string up into substrings by line. It then calls colorize with the | ||||||||||||||||||||
| 64 | substring. | ||||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | =cut | ||||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | 11 | ▶ | sub parse { | ||||||||||||||||||
|
Subroutine
parse: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||
| 69 | 11 | my ($self, $buffer) = @_; | |||||||||||||||||||
| 70 | 11 | my $output = ''; | |||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | 11 | while(1) { | |||||||||||||||||||
| 73 | 29 | my $string; | |||||||||||||||||||
| 74 | # what about final lines that don't end in \r? Need to check this.. | ||||||||||||||||||||
| 75 | 29 | ▶ | if($buffer =~ /^(.*?[\x0d\x0a]{1,2})/s) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 76 | 18 | $string = substr($buffer,0,length $1,''); | |||||||||||||||||||
| 77 | } | ||||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | 29 | ▶ | last unless $string; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 80 | 18 | $output .= $self->colorize($string); | |||||||||||||||||||
| 81 | } | ||||||||||||||||||||
| 82 | |||||||||||||||||||||
| 83 | 11 | ▶ | if (length $buffer) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 84 | 10 | $output .= $self->colorize($buffer); | |||||||||||||||||||
| 85 | } | ||||||||||||||||||||
| 86 | 11 | return $output; | |||||||||||||||||||
| 87 | } | ||||||||||||||||||||
| 88 | |||||||||||||||||||||
| 89 | =head2 get_colors | ||||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | my @colors = $self->get_colors(); | ||||||||||||||||||||
| 92 | my $color = $self->get_colors(1); | ||||||||||||||||||||
| 93 | |||||||||||||||||||||
| 94 | Returns a list of available colors by their names. This list excludes the RED | ||||||||||||||||||||
| 95 | color because it's used for errors and these colors are specifically for the | ||||||||||||||||||||
| 96 | rainbow code that doesn't use red. | ||||||||||||||||||||
| 97 | |||||||||||||||||||||
| 98 | If given a value, it returns $color[value]. | ||||||||||||||||||||
| 99 | |||||||||||||||||||||
| 100 | =cut | ||||||||||||||||||||
| 101 | |||||||||||||||||||||
| 102 | 17 | ▶ | sub get_colors { | ||||||||||||||||||
|
Subroutine
get_colors: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 103 | 17 | ▶ | $_[1] ? $colors[$_[1]] : @colors; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 104 | } | ||||||||||||||||||||
| 105 | |||||||||||||||||||||
| 106 | 2 | 1; | |||||||||||||||||||