| 1 | package Data::Coloured; | ||||||||||||||
| 2 | 1 | our $AUTHORITY = 'cpan:GETTY'; | |||||||||||||
| 3 | # ABSTRACT: Visualize random ASCII data streams | ||||||||||||||
| 4 | 1 | $Data::Coloured::VERSION = '0.003'; | |||||||||||||
| 5 | 1 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | 1 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | 1 | ▶ | use Exporter 'import'; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 8 | 1 | ▶ | use Term::ANSIColor qw( colored ); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 9 | |||||||||||||||
| 10 | 1 | our @EXPORT_OK = qw( pc c ); | |||||||||||||
| 11 | 1 | our @EXPORT = qw( coloured poloured ); | |||||||||||||
| 12 | |||||||||||||||
| 13 | 1 | 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 | 1 | our %colours = (qw( | |||||||||||||
| 50 | control bright_red | ||||||||||||||
| 51 | print bright_yellow | ||||||||||||||
| 52 | binary bright_cyan | ||||||||||||||
| 53 | )); | ||||||||||||||
| 54 | |||||||||||||||
| 55 | 1 | our @control_delimiter = qw( [ ] ); | |||||||||||||
| 56 | 1 | our @binary_delimiter = qw( < > ); | |||||||||||||
| 57 | |||||||||||||||
| 58 | 0 | ▶ | sub poloured { | ||||||||||||
|
Subroutine
poloured: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 59 | 0 | print coloured(@_); | |||||||||||||
| 60 | } | ||||||||||||||
| 61 | 0 | ▶ | sub pc { poloured(@_) } | ||||||||||||
|
Subroutine
pc: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 62 | |||||||||||||||
| 63 | 0 | ▶ | sub coloured { | ||||||||||||
|
Subroutine
coloured: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||
| 64 | 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 | ▶ | if (defined $control{$chr}) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 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 | ▶ | sub c { coloured(@_) } | ||||||||||||
|
Subroutine
c: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 80 | |||||||||||||||
| 81 | 1 | 1; | |||||||||||||
| 82 | |||||||||||||||
| 83 | __END__ | ||||||||||||||