File Coverage

blib/lib/Data/Coloured.pm
Criterion Covered Total %
statement 12 25 48.0
branch 0 4 0.0
condition n/a
subroutine 4 8 50.0
pod 0 4 0.0
total 16 41 39.0


line stmt bran cond sub pod time code
1             package Data::Coloured;
2             our $AUTHORITY = 'cpan:GETTY';
3             # ABSTRACT: Visualize random ASCII data streams
4             $Data::Coloured::VERSION = '0.003';
5 1     1   686 use strict;
  1         2  
  1         39  
6 1     1   6 use warnings;
  1         2  
  1         31  
7 1     1   12 use Exporter 'import';
  1         1  
  1         30  
8 1     1   622 use Term::ANSIColor qw( colored );
  1         7066  
  1         831  
9              
10             our @EXPORT_OK = qw( pc c );
11             our @EXPORT = qw( coloured poloured );
12              
13             our %control = (qw(
14             0 NUL
15             1 SOH
16             2 STX
17             3 ETX
18             4 EOT
19             5 ENQ
20             6 ACK
21             7 BEL
22             8 BS
23             9 TAB
24             10 LF
25             11 VT
26             12 FF
27             13 CR
28             14 SO
29             15 SI
30             16 DLE
31             17 DC1
32             18 DC2
33             19 DC3
34             20 DC4
35             21 NAK
36             22 SYN
37             23 ETB
38             24 CAN
39             25 EM
40             26 SUB
41             27 ESC
42             28 FS
43             29 GS
44             30 RS
45             31 US
46             127 DEL
47             ));
48              
49             our %colours = (qw(
50             control bright_red
51             print bright_yellow
52             binary bright_cyan
53             ));
54              
55             our @control_delimiter = qw( [ ] );
56             our @binary_delimiter = qw( < > );
57              
58             sub poloured {
59 0     0 0   print coloured(@_);
60             }
61 0     0 0   sub pc { poloured(@_) }
62              
63             sub coloured {
64 0     0 0   my $data = join('',@_);
65 0           my @chars = split(//,$_[0]);
66 0           my $output = "";
67 0           for my $char (@chars) {
68 0           my $chr = ord($char);
69 0 0         if (defined $control{$chr}) {
    0          
70 0           $output .= colored($control_delimiter[0].$control{$chr}.$control_delimiter[1],$colours{control});
71             } elsif ($char =~ /[ -~]/) {
72 0           $output .= colored($char,$colours{print});
73             } else {
74 0           $output .= colored($binary_delimiter[0].unpack('H*',$char).$binary_delimiter[1], $colours{binary});
75             }
76             }
77 0           return $output;
78             }
79 0     0 0   sub c { coloured(@_) }
80              
81             1;
82              
83             __END__