Range/Format.pm

filter: Statementstmt 43.2% 29 / 67 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 15 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 69.2% 9 / 13 Podpod 33.3% 1 / 3 totaltotal 30.9% 39 / 126 CC 19 SCAR 44.9
CC
19
Cov
29%
format
182.0
get_default_color
56.0
get_bg_color
2.0
CRAP 89.4
« Range/Object.pm ↑ Summary Range.pm »
1  
2 package Data::HexDump::Range ; ## no critic (Modules::RequireFilenameMatchesPackage)
3  
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use warnings ;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Carp ;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 BEGIN
9 {
10  
11 2 ▶use Sub::Exporter -setup =>
Subroutine BEGIN: called CC=1 SCAR=0.0
12 {
13 exports => [ qw() ],
14 groups =>
15 {
16 all => [ qw() ],
17 }
18 2 };
19
20 2 ▶use vars qw ($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: not called CC=1 SCAR=0.0
21 }
22  
23 #-------------------------------------------------------------------------------
24  
25 2 ▶use English qw( -no_match_vars ) ;
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 2 ▶use Readonly ;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 2 Readonly my $EMPTY_STRING => q{} ;
29  
30 2 ▶use Carp qw(carp croak confess) ;
Subroutine BEGIN: called CC=1 SCAR=0.0
31  
32 2 ▶use Text::Colorizer ;
Subroutine BEGIN: called CC=1 SCAR=0.0
33  
34 #-------------------------------------------------------------------------------
35  
36 =head1 NAME
37  
38 Data::HexDump::Range::Format - Handles formating for Data::HexDump::Range
39  
40 =head1 SUBROUTINES/METHODS
41  
42 Subroutines prefixed with B<[P]> are not part of the public API and shall not be used directly.
43  
44 =cut
45  
46 #-------------------------------------------------------------------------------
47  
48 sub get_bg_color
49 0 ▶{
Subroutine get_bg_color: not called CC=1 SCAR=6.9
Pod undocumented
50  
51 =head2 [P] get_bg_color()
52  
53 Returns the default bg color
54  
55 I<Arguments> - None
56  
57 I<Returns> - A string - a color according to the COLOR option and FORMAT
58  
59 I<Exceptions> - None
60  
61 =cut
62  
63 0 my ($self) = @_ ;
64  
65 0 return $self->{COLORS}{$self->{FORMAT}}[-1] ;
66 }
67  
68 #-------------------------------------------------------------------------------
69  
70 sub get_default_color
71 0 ▶{
Subroutine get_default_color: not called CC=7 SCAR=40.3
Pod undocumented
72  
73 =head2 [P] get_default_color($color)
74  
75 Returns a color to use with a range that has none, only if $color is not defined
76  
77 my $default_color = $self->get_default_color($color) ;
78  
79 I<Arguments> - $color - scalar - a color name or undef
80  
81 I<Returns> - A string - a color according to the COLOR option and FORMAT
82  
83 I<Exceptions> - None
84  
85 =cut
86  
87 0 my ($self, $color) = @_ ;
88  
89 0 my $default_color ;
90  
91 0 ▶if($self->{COLOR} eq 'cycle')
Branch: 3 branches
BranchTrueFalseTotal
if ($self->{'COLOR'} eq 'cycle') { } 0 0 0
elsif ($self->{'COLOR'} eq 'no_cycle') { } 0 0 0
elsif ($self->{'COLOR'} eq 'bw') { } 0 0 0
92 {
93 0 ▶ $default_color = $color || $self->{COLORS}{$self->{FORMAT}}[$self->{CURRENT_COLOR_INDEX}] ;
Condition0%0/3
$color || $self->{'COLORS'}{$self->{'FORMAT'}}[$self->{'CURRENT_COLOR_INDEX'}]
l!l&&r!l&&!r
000
MC/DC0%0/2
$color || $self->{'COLORS'}{$self->{'FORMAT'}}[$self->{'CURRENT_COLOR_INDEX'}]
$color $self->{'COLORS'}{$self->{'FORMAT'}}[$self->{'CURRENT_COLOR_INDEX'}]
Truth table0%0/3
A || B
A= $colorB= $self->{'COLORS'}{$self->{'FORMAT'}}[$self->{'CURRENT_COLOR_INDEX'}]
ABresult
1X1
011
000
94
95 0 $self->{CURRENT_COLOR_INDEX}++ ;
96 0 ▶ $self->{CURRENT_COLOR_INDEX} = 0 if $self->{CURRENT_COLOR_INDEX} >= @{$self->{COLORS}{$self->{FORMAT}}} ;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"CURRENT_COLOR_INDEX"} >= @{$self->{"COLORS"}{$self->{"FORMAT"}};} 0 0 0
97 }
98 elsif($self->{COLOR} eq 'no_cycle')
99 {
100 0 ▶ $default_color = $color || $self->{COLORS}{$self->{FORMAT}}[-1] ;
Condition0%0/3
$color || $self->{'COLORS'}{$self->{'FORMAT'}}[-1]
l!l&&r!l&&!r
000
MC/DC0%0/2
$color || $self->{'COLORS'}{$self->{'FORMAT'}}[-1]
$color $self->{'COLORS'}{$self->{'FORMAT'}}[-1]
Truth table0%0/3
A || B
A= $colorB= $self->{'COLORS'}{$self->{'FORMAT'}}[-1]
ABresult
1X1
011
000
101 }
102 elsif($self->{COLOR} eq 'bw')
103 {
104 0 $default_color = $self->{COLORS}{$self->{FORMAT}}[-1] ;
105 }
106 else
107 {
108 0 $self->{INTERACTION}{DIE}("Error: Invalid COLOR format.\n") ;
109 }
110
111 0 return $default_color ;
112 }
113  
114 #-------------------------------------------------------------------------------
115  
116 sub format ## no critic (Subroutines::ProhibitBuiltinHomonyms)
117 0 ▶{
Subroutine format: not called CC=13 SCAR=52.0
Pod documented
118
119 =head2 [P] format($line_data)
120  
121 Transform the line data into ANSI, ASCII or HTML
122  
123 I<Arguments> -
124  
125 =over 2
126  
127 =item * \%line_data - See L<gather>
128  
129 =back
130  
131 I<Returns> - A dump in ANSI, ASCII or HTML.
132  
133 =cut
134  
135 0 my ($self, $line_data) = @_ ;
136  
137 #load user colors from file
138 0 ▶if(defined $self->{COLOR_NAMES} && 'HASH' ne ref $self->{COLOR_NAMES})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"COLOR_NAMES"} and "HASH" ne ref $self->{"COLOR_NAMES"}) 0 0 0
Condition0%0/3
defined $self->{"COLOR_NAMES"} and "HASH" ne ref $self->{"COLOR_NAMES"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->{"COLOR_NAMES"} and "HASH" ne ref $self->{"COLOR_NAMES"}
defined $self->{"COLOR_NAMES"} "HASH" ne ref $self->{"COLOR_NAMES"}
Truth table0%0/3
A and B
A= defined $self->{"COLOR_NAMES"}B= "HASH" ne ref $self->{"COLOR_NAMES"}
ABresult
0X0
100
111
139 {
140 my $colors = do $self->{COLOR_NAMES}
141 0 ▶ or $self->{INTERACTION}{DIE}("Error: Can't load color file '$self->{COLOR_NAMES}'.\n") ;
Branch: 1 branch
BranchTrueFalseTotal
my $colors = do $self->{"COLOR_NAMES"} or $self->{"INTERACTION"}{"DIE"}->(qq[Error: Can't load color file '$self->{"COLOR_NAMES"}'.\n]) 0 0 0
142  
143 'HASH' eq ref $colors
144 0 ▶ or $self->{INTERACTION}{DIE}("Error: Data not a Hash in '$self->{COLOR_NAMES}'.\n") ;
Branch: 1 branch
BranchTrueFalseTotal
"HASH" eq ref $colors or $self->{"INTERACTION"}{"DIE"}->(qq[Error: Data not a Hash in '$self->{"COLOR_NAMES"}'.\n]) 0 0 0
145  
146 0 $self->{COLOR_NAMES} = $colors ;
147 }
148  
149 0 for my $definition
150 (
151 #aliases looked up by colorizer module
152 ['ruler', 'lookup:white', 'lookup:white'],
153 ['offset', 'lookup:white', 'lookup:white'],
154 ['cumulative_offset', 'lookup:bright_black', 'lookup:bright_black'],
155 )
156 {
157 0 my ($name, $ansi_color, $html_color) = @{$definition} ;
158 0 ▶ $self->{COLOR_NAMES}{ANSI}{$name} //= $ansi_color ;
Condition0%0/3
$self->{"COLOR_NAMES"}{"ANSI"}{$name} //= $ansi_color
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"COLOR_NAMES"}{"ANSI"}{$name} //= $ansi_color
$self->{"COLOR_NAMES"}{"ANSI"}{$name} $ansi_color
Truth table0%0/3
A //= B
A= $self->{"COLOR_NAMES"}{"ANSI"}{$name}B= $ansi_color
ABresult
1X1
011
000
159 0 ▶ $self->{COLOR_NAMES}{HTML}{$name} //= $html_color ;
Condition0%0/3
$self->{"COLOR_NAMES"}{"HTML"}{$name} //= $html_color
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"COLOR_NAMES"}{"HTML"}{$name} //= $html_color
$self->{"COLOR_NAMES"}{"HTML"}{$name} $html_color
Truth table0%0/3
A //= B
A= $self->{"COLOR_NAMES"}{"HTML"}{$name}B= $html_color
ABresult
1X1
011
000
160 }
161  
162 my $colorizer = Text::Colorizer->new
163 (
164 COLORS => $self->{COLOR_NAMES},
165 FORMAT => $self->{FORMAT},
166 0 ) ;
167  
168 0 my @colored_lines ;
169  
170 0 my @fields = @{$self->{FIELDS_TO_DISPLAY}} ;
171 0 unshift @fields, 'INFORMATION', 'RULER' ;
172  
173 0 for my $line (@{$line_data})
174 {
175 0 for my $field (@fields)
176 {
177 0 ▶ if(exists $line->{$field})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $line->{$field}) 0 0 0
178 {
179 0 for my $range (@{$line->{$field}})
180 {
181 0 push @colored_lines, $range->{"${field}_COLOR"}, $range->{$field} ,
182 }
183
184 0 push @colored_lines, $EMPTY_STRING, q{ } ;
185 }
186 }
187
188 0 ▶ push @colored_lines, $EMPTY_STRING, "\n" if $line->{NEW_LINE} ;
Branch: 1 branch
BranchTrueFalseTotal
if $line->{"NEW_LINE"} 0 0 0
189 }
190  
191 0 return $colorizer->color(@colored_lines) ;
192 }
193  
194 #-------------------------------------------------------------------------------
195  
196 2 1 ;
197  
198 =head1 BUGS AND LIMITATIONS
199  
200 None so far.
201  
202 =head1 AUTHOR
203  
204 Nadim ibn hamouda el Khemir
205 CPAN ID: NKH
206 mailto: nadim@cpan.org
207  
208 =head1 COPYRIGHT AND LICENSE
209  
210 Copyright Nadim Khemir 2010-2012.
211  
212 This program is free software; you can redistribute it and/or
213 modify it under the terms of either:
214  
215 =over 4
216  
217 =item * the GNU General Public License as published by the Free
218 Software Foundation; either version 1, or (at your option) any
219 later version, or
220  
221 =item * the Artistic License version 2.0.
222  
223 =back
224  
225 =head1 SUPPORT
226  
227 You can find documentation for this module with the perldoc command.
228  
229 perldoc Data::HexDump::Range
230  
231 You can also look for information at:
232  
233 =over 4
234  
235 =item * AnnoCPAN: Annotated CPAN documentation
236  
237 L<http://annocpan.org/dist/Data-HexDump-Range>
238  
239 =item * RT: CPAN's request tracker
240  
241 Please report any bugs or feature requests to L <bug-data-hexdump-range@rt.cpan.org>.
242  
243 We will be notified, and then you'll automatically be notified of progress on
244 your bug as we make changes.
245  
246 =item * Search CPAN
247  
248 L<http://search.cpan.org/dist/Data-HexDump-Range>
249  
250 =back
251  
252 =head1 SEE ALSO
253  
254 L<Data::HexDump::Range>
255  
256 =cut
« Range/Object.pm ↑ Summary Range.pm »