File Coverage

lib/App/Tel/Color.pm
Criterion Covered Total %
statement 35 35 100.0
branch 9 10 90.0
condition n/a
subroutine 7 7 100.0
pod 3 3 100.0
total 54 55 98.1


line stmt bran cond sub pod time code
1             package App::Tel::Color;
2              
3 8     8   89951 use strict;
  8         18  
  8         176  
4 8     8   23 use warnings;
  8         10  
  8         142  
5 8     8   23 use Carp;
  8         8  
  8         618  
6 8     8   408 use Module::Load;
  8         660  
  8         37  
7             require Exporter;
8             our @ISA = qw(Exporter);
9             our @EXPORT = qw();
10             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             sub load_syntax {
34 14     14 1 3204 my ($self, $list) = @_;
35 14 100       38 return $self if (!defined $list);
36 8         8 my @syntax;
37 8         10 push(@syntax, $list);
38 8 100       24 if (ref($list) eq 'ARRAY') {
39 4         6 @syntax = @$list;
40             }
41              
42 8         13 foreach my $l (@syntax) {
43 11         26 for(split(/\+/, $l)) {
44              
45 12         16 my $module = "App::Tel::Color::$_";
46 12 50       55 next if defined($self->{colors}->{$module});
47              
48 12         12 eval {
49 12         31 Module::Load::load $module;
50 4         201 $self->{colors}->{$module}=$module->new;
51             };
52 12 100       2487 if ($@) {
53 8 100       45 carp $@ if ($self->{debug});
54             }
55             }
56             }
57              
58 8         431 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             sub new {
71 8     8 1 2508 my ($class,$debug) = @_;
72              
73 8         64 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             sub colorize {
88 1     1 1 4 my ($self, $input) = @_;
89              
90 1         2 foreach my $mod (values %{$self->{colors}}) {
  1         4  
91 1         5 $input = $mod->parse($input);
92             }
93 1         3 return $input;
94             }
95              
96             1;