File Coverage

blib/lib/App/colourhexdump/ColourProfile.pm
Criterion Covered Total %
statement 20 30 66.6
branch 0 4 0.0
condition n/a
subroutine 7 9 77.7
pod 2 2 100.0
total 29 45 64.4


line stmt bran cond sub pod time code
1 2     2   1165 use 5.006; # our
  2         8  
2 2     2   10 use strict;
  2         2  
  2         82  
3 2     2   19 use warnings;
  2         4  
  2         150  
4              
5             package App::colourhexdump::ColourProfile;
6              
7             our $VERSION = '1.000003';
8              
9             # ABSTRACT: A Role for Colour Profiles
10              
11             our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY
12              
13 2     2   1020 use Moose::Role qw( requires );
  2         359978  
  2         8  
14 2     2   7597 use namespace::autoclean;
  2         5856  
  2         11  
15              
16              
17              
18              
19              
20              
21              
22              
23              
24              
25              
26              
27              
28              
29              
30             requires 'get_colour_for';
31              
32              
33              
34              
35              
36              
37              
38              
39              
40             requires 'get_display_symbol_for';
41              
42 2     2   155 no Moose::Role;
  2         4  
  2         12  
43              
44 2     2   707 use Term::ANSIColor 3.00 qw( RESET );
  2         4284  
  2         1341  
45              
46              
47              
48              
49              
50              
51              
52             ## no critic ( RequireArgUnpacking )
53              
54             sub get_string_pre {
55 0     0 1   my ( $self, $char ) = ( $_[0], $_[1] );
56 0           my $colourcode = $self->get_colour_for($char);
57 0 0         if ( defined $colourcode ) {
58 0           return $colourcode;
59             }
60 0           return q{};
61             }
62              
63              
64              
65              
66              
67              
68              
69              
70             ## no critic ( RequireArgUnpacking )
71              
72             sub get_string_post {
73 0     0 1   my ( $self, $char ) = ( $_[0], $_[1] );
74 0           my $colourcode = $self->get_colour_for($char);
75 0 0         if ( defined $colourcode ) {
76 0           return RESET;
77             }
78 0           return q{};
79             }
80              
81             1;
82              
83             __END__
84              
85             =pod
86              
87             =encoding UTF-8
88              
89             =head1 NAME
90              
91             App::colourhexdump::ColourProfile - A Role for Colour Profiles
92              
93             =head1 VERSION
94              
95             version 1.000003
96              
97             =head1 SYNOPSIS
98              
99             package App::colourhexdump::ColourProfileName
100              
101             use Moose;
102             with qw( App::colourhexdump::ColourProfile );
103              
104             sub get_colour_for {
105             my ( $self, $char ) = @_ ;
106             ...
107             return "\e[31m" if /badthings/;
108             return undef; # don't colour
109             }
110             sub get_display_symbol_for {
111             my ($self, $char) = @_ ;
112             ...
113             return '.' if $char =~ /badthings/
114             return $char; # printable
115             }
116              
117             =head1 REQUIRED METHODS
118              
119             =head2 C<get_colour_for>
120              
121             my $colour = $object->get_colour_for( "\n" );
122              
123             Return any string of data that should be prepended every time a given character is seen.
124              
125             Generally, you only want to print ANSI Escape codes.
126              
127             Don't worry about resetting things, we put a C<^[[0m> in for you.
128              
129             Return C<undef> if you do not wish to apply colouring.
130              
131             =head2 C<get_display_symbol_for>
132              
133             my $symbol = $object->get_display_symbol_for( "\n" );
134              
135             Returns a user viewable alternative to the matched string.
136              
137             =head1 METHODS
138              
139             =head2 C<get_string_pre>
140              
141             Wraps L</get_colour_for> and returns either a string sequence or ''.
142              
143             =head2 C<get_string_post>
144              
145             Wraps L</get_colour_for> and returns either an ANSI Reset Code, or '', depending
146             on what was returned.
147              
148             =head1 AUTHOR
149              
150             Kent Fredric <kentnl@cpan.org>
151              
152             =head1 COPYRIGHT AND LICENSE
153              
154             This software is copyright (c) 2017 by Kent Fredric <kentnl@cpan.org>.
155              
156             This is free software; you can redistribute it and/or modify it under
157             the same terms as the Perl 5 programming language system itself.
158              
159             =cut