lib/App/Tel/Color.pm

filter: Statementstmt 100% 40 / 40 Branchbran 90.0% 9 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 100% 3 / 3 totaltotal 98.3% 59 / 60 CC 9 SCAR 15.8
CC
9
Cov
98%
load_syntax
8.0
colorize
2.0
BEGIN
1.0
CRAP 4.9
« lib/App/Tel/Passwd/KeePass.pm ↑ Summary lib/App/Tel/Passwd.pm »
1 package App::Tel::Color;
2  
3 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 8 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 8 ▶use Module::Load;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 8 require Exporter;
8 8 our @ISA = qw(Exporter);
9 8 our @EXPORT = qw();
10 8 our @EXPORT_OK = qw ( load_syntax );
11  
12 =head1 NAME
13  
14 App::Tel::Color - Methods for managing App::Tel::Color:: modules
15  
16 =cut
17  
18 =head2 load_syntax
19  
20 $self->load_syntax('Cisco');
21  
22 This attempts to load syntax highlighting modules. If it can't find the
23 module it just won't load it.
24  
25 Returns $self.
26  
27 Multiple files can be chain loaded by using plus:
28  
29 $self->load_syntax('Default+Cisco');
30  
31 =cut
32  
33 14 ▶sub load_syntax {
Subroutine load_syntax: called CC=8 SCAR=20.8
Pod documented
34 14 my ($self, $list) = @_;
35 14 ▶ return $self if (!defined $list);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $list 6 8 14
36 8 my @syntax;
37 8 push(@syntax, $list);
38 8 ▶ if (ref($list) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $list eq "ARRAY") 4 4 8
39 4 @syntax = @$list;
40 }
41  
42 8 foreach my $l (@syntax) {
43 11 for(split(/\+/, $l)) {
44  
45 12 my $module = "App::Tel::Color::$_";
46 12 ▶ next if defined($self->{colors}->{$module});
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"colors"}{$module} 0 12 12
47  
48 12 eval {
49 12 Module::Load::load $module;
50 4 $self->{colors}->{$module}=$module->new;
51 };
52 12 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 8 4 12
53 8 ▶ carp $@ if ($self->{debug});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 1 7 8
54 }
55 }
56 }
57  
58 8 return $self;
59 }
60  
61 =head2 new
62  
63 my $colors = App::Tel::Color->new($debug);
64  
65 Initializes a color library. You can load syntax parsers by calling
66 load_syntax.
67  
68 =cut
69  
70 8 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
71 8 my ($class,$debug) = @_;
72  
73 8 bless( {
74 debug => $debug,
75 colors => {},
76 }, $class);
77 }
78  
79 =head2 colorize
80  
81 my $output = $self->colorize($input);
82  
83 Calls the parser routine for all the loaded syntax modules.
84  
85 =cut
86  
87 1 ▶sub colorize {
Subroutine colorize: called CC=2 SCAR=6.9
Pod documented
88 1 my ($self, $input) = @_;
89  
90 1 foreach my $mod (values %{$self->{colors}}) {
91 1 $input = $mod->parse($input);
92 }
93 1 return $input;
94 }
95  
96 8 1;
« lib/App/Tel/Passwd/KeePass.pm ↑ Summary lib/App/Tel/Passwd.pm »