My/Role/ColoredHelp.pm untested

filter: Statementstmt 0.0% 0 / 15 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 3 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 19 CC 1 SCAR 6.9
CC
1
Cov
0%
color_msg
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 package My::Role::ColoredHelp;
2  
3 use Mojo::Base -role;
4 use Term::ANSIColor qw( colored );
5  
6 =head2 color_msg
7  
8 Apply some colors to a help message.
9  
10 =cut
11  
12 sub color_msg {
13 my ( $s, $msg, $script ) = @_;
14  
15 # Script.
16 $msg =~ s/ <SCRIPT> / colored($script,"YELLOW") /xge;
17  
18 # Quotes.
19 $msg =~ s/ ( ' [^']*+ ' ) / colored($1,"GREEN") /xge;
20  
21 # Variables.
22 $msg =~ s/ (\$\w+) / colored($1,"GREEN") /xge;
23  
24 # Functions.
25 $msg =~ s/ ( \w+\(\) ) / colored($1,"GREEN") /xge;
26  
27 # Options.
28 $msg =~ s/ (-+\w[^#]+) / colored($1,"GREEN") /xge;
29  
30 # Comments.
31 $msg =~ s/ (\#.+) / colored($1,"ON_BRIGHT_BLACK") /xge;
32  
33 # Errors.
34 $msg =~ s/ ^ (ERROR:.+) / colored($1,"RED") /xge;
35  
36 $msg;
37 }
38  
39 1;