| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
1
|
|
|
1
|
|
812
|
use 5.006; # our |
|
|
1
|
|
|
|
|
3
|
|
|
2
|
1
|
|
|
1
|
|
4
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
23
|
|
|
3
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
98
|
|
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package App::colourhexdump; |
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '1.000002'; |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# ABSTRACT: HexDump, but with character-class highlighting. |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY |
|
12
|
|
|
|
|
|
|
|
|
13
|
1
|
|
|
1
|
|
620
|
use Moose qw( has with ); |
|
|
1
|
|
|
|
|
427757
|
|
|
|
1
|
|
|
|
|
8
|
|
|
14
|
1
|
|
|
1
|
|
6300
|
use MooseX::Getopt::Dashes 0.37; |
|
|
1
|
|
|
|
|
381326
|
|
|
|
1
|
|
|
|
|
77
|
|
|
15
|
|
|
|
|
|
|
with qw( MooseX::Getopt::Dashes ); |
|
16
|
|
|
|
|
|
|
|
|
17
|
1
|
|
|
1
|
|
11
|
use Getopt::Long::Descriptive; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
12
|
|
|
18
|
1
|
|
|
1
|
|
995
|
use Term::ANSIColor 3.00 qw( colorstrip ); |
|
|
1
|
|
|
|
|
6664
|
|
|
|
1
|
|
|
|
|
445
|
|
|
19
|
1
|
|
|
1
|
|
570
|
use App::colourhexdump::Formatter; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
37
|
|
|
20
|
1
|
|
|
1
|
|
7
|
use namespace::autoclean; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
7
|
|
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
has colour_profile => ( |
|
23
|
|
|
|
|
|
|
metaclass => 'Getopt', |
|
24
|
|
|
|
|
|
|
isa => 'Str', |
|
25
|
|
|
|
|
|
|
is => 'rw', |
|
26
|
|
|
|
|
|
|
default => 'DefaultColourProfile', |
|
27
|
|
|
|
|
|
|
cmd_aliases => [qw/ C color-profile /], |
|
28
|
|
|
|
|
|
|
documentation => 'Backend to use for colour highlighting (DefaultColourProfile)', |
|
29
|
|
|
|
|
|
|
); |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
has row_length => ( |
|
32
|
|
|
|
|
|
|
metaclass => 'Getopt', |
|
33
|
|
|
|
|
|
|
isa => 'Int', |
|
34
|
|
|
|
|
|
|
is => 'ro', |
|
35
|
|
|
|
|
|
|
default => 32, |
|
36
|
|
|
|
|
|
|
cmd_aliases => [qw/ r row /], |
|
37
|
|
|
|
|
|
|
documentation => 'Number of bytes per display row (32).', |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
); |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
has chunk_length => ( |
|
42
|
|
|
|
|
|
|
metaclass => 'Getopt', |
|
43
|
|
|
|
|
|
|
isa => 'Int', |
|
44
|
|
|
|
|
|
|
is => 'rw', |
|
45
|
|
|
|
|
|
|
default => 4, |
|
46
|
|
|
|
|
|
|
cmd_aliases => [qw/ x chunk /], |
|
47
|
|
|
|
|
|
|
documentation => 'Number of bytes per display hex display group (4).', |
|
48
|
|
|
|
|
|
|
); |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
has _files => ( |
|
51
|
|
|
|
|
|
|
metaclass => 'Getopt', |
|
52
|
|
|
|
|
|
|
isa => 'ArrayRef[Str]', |
|
53
|
|
|
|
|
|
|
is => 'rw', |
|
54
|
|
|
|
|
|
|
default => sub { [] }, |
|
55
|
|
|
|
|
|
|
cmd_flag => 'file', |
|
56
|
|
|
|
|
|
|
cmd_aliases => [qw/ f /], |
|
57
|
|
|
|
|
|
|
documentation => 'Add a file to the list of files to process. \'-\' for STDIN.', |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
); |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
has 'show_file_prefix' => ( |
|
62
|
|
|
|
|
|
|
metaclass => 'Getopt', |
|
63
|
|
|
|
|
|
|
isa => 'Bool', |
|
64
|
|
|
|
|
|
|
is => 'rw', |
|
65
|
|
|
|
|
|
|
default => 0, |
|
66
|
|
|
|
|
|
|
documentation => 'Enable printing the filename on the start of every line ( off ).', |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
); |
|
69
|
|
|
|
|
|
|
has 'show_file_heading' => ( |
|
70
|
|
|
|
|
|
|
metaclass => 'Getopt', |
|
71
|
|
|
|
|
|
|
isa => 'Bool', |
|
72
|
|
|
|
|
|
|
is => 'rw', |
|
73
|
|
|
|
|
|
|
default => 0, |
|
74
|
|
|
|
|
|
|
documentation => 'Enable printing the filename before the hexdump output. ( off ).', |
|
75
|
|
|
|
|
|
|
); |
|
76
|
|
|
|
|
|
|
has 'colour' => ( |
|
77
|
|
|
|
|
|
|
metaclass => 'Getopt', |
|
78
|
|
|
|
|
|
|
isa => 'Bool', |
|
79
|
|
|
|
|
|
|
is => 'rw', |
|
80
|
|
|
|
|
|
|
default => 1, |
|
81
|
|
|
|
|
|
|
cmd_aliases => [qw/ c color /], |
|
82
|
|
|
|
|
|
|
documentation => 'Enable coloured output ( on ). --no-colour to disable.', |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
); |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
|
87
|
1
|
|
|
1
|
|
207
|
no Moose; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
6
|
|
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub BUILD { |
|
98
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
99
|
0
|
|
|
|
|
|
push @{ $self->_files() }, @{ $self->extra_argv }; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
100
|
0
|
|
|
|
|
|
return $self; |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
} |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub get_filehandle { |
|
113
|
0
|
|
|
0
|
1
|
|
my ( undef, $filename ) = @_; |
|
114
|
0
|
0
|
|
|
|
|
if ( q[-] eq $filename ) { |
|
115
|
0
|
|
|
|
|
|
return \*STDIN; |
|
116
|
|
|
|
|
|
|
} |
|
117
|
0
|
|
|
|
|
|
require Carp; |
|
118
|
0
|
0
|
|
|
|
|
open my $fh, '<', $filename or Carp::confess("Cant open $_ , $!"); |
|
119
|
0
|
|
|
|
|
|
return $fh; |
|
120
|
|
|
|
|
|
|
} |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
sub run { |
|
131
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
132
|
0
|
0
|
|
|
|
|
if ( not @{ $self->_files } ) { |
|
|
0
|
|
|
|
|
|
|
|
133
|
0
|
|
|
|
|
|
push @{ $self->_files }, q[-]; |
|
|
0
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
} |
|
135
|
|
|
|
|
|
|
## no critic ( Variables::RequireLocalizedPunctuationVars ) |
|
136
|
0
|
|
|
|
|
|
local $ENV{ANSI_COLORS_DISABLED} = $ENV{ANSI_COLORS_DISABLED}; |
|
137
|
0
|
0
|
|
|
|
|
if ( not $self->colour ) { |
|
138
|
0
|
|
|
|
|
|
$ENV{ANSI_COLORS_DISABLED} = 1; |
|
139
|
|
|
|
|
|
|
} |
|
140
|
0
|
|
|
|
|
|
for ( @{ $self->_files } ) { |
|
|
0
|
|
|
|
|
|
|
|
141
|
0
|
|
|
|
|
|
my $prefix = q{}; |
|
142
|
0
|
0
|
|
|
|
|
if ( $self->show_file_prefix ) { |
|
143
|
0
|
|
|
|
|
|
$prefix = $_; |
|
144
|
|
|
|
|
|
|
} |
|
145
|
0
|
0
|
|
|
|
|
if ( length $prefix ) { |
|
146
|
0
|
|
|
|
|
|
$prefix .= q{:}; |
|
147
|
|
|
|
|
|
|
} |
|
148
|
|
|
|
|
|
|
## no critic ( RequireCheckedSyscalls ); |
|
149
|
0
|
0
|
|
|
|
|
if ( $self->show_file_heading ) { |
|
150
|
0
|
|
|
|
|
|
print qq{- Contents of $_ --\n}; |
|
151
|
|
|
|
|
|
|
} |
|
152
|
0
|
|
|
|
|
|
my $formatter = App::colourhexdump::Formatter->new( |
|
153
|
|
|
|
|
|
|
colour_profile => $self->colour_profile, |
|
154
|
|
|
|
|
|
|
row_length => $self->row_length, |
|
155
|
|
|
|
|
|
|
chunk_length => $self->chunk_length, |
|
156
|
|
|
|
|
|
|
); |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
$formatter->format_foreach_in_fh( |
|
159
|
|
|
|
|
|
|
$self->get_filehandle($_), |
|
160
|
|
|
|
|
|
|
sub { |
|
161
|
0
|
|
|
0
|
|
|
print $prefix . shift; |
|
162
|
|
|
|
|
|
|
}, |
|
163
|
0
|
|
|
|
|
|
); |
|
164
|
|
|
|
|
|
|
} |
|
165
|
0
|
|
|
|
|
|
return 1; |
|
166
|
|
|
|
|
|
|
} |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
1; |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
__END__ |
|
171
|
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=pod |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=encoding UTF-8 |
|
175
|
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=head1 NAME |
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
App::colourhexdump - HexDump, but with character-class highlighting. |
|
179
|
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=head1 VERSION |
|
181
|
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
version 1.000002 |
|
183
|
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
usage: colourhexdump [-?Ccfrx] [long options...] |
|
187
|
|
|
|
|
|
|
-? --usage --help Prints this usage information. |
|
188
|
|
|
|
|
|
|
--color-profile -C --colour-profile Backend to use for colour highlighting (DefaultColourProfile) |
|
189
|
|
|
|
|
|
|
--row -r --row-length Number of bytes per display row (32). |
|
190
|
|
|
|
|
|
|
--chunk -x --chunk-length Number of bytes per display hex display group (4). |
|
191
|
|
|
|
|
|
|
-f --file Add a file to the list of files to process. '-' for STDIN. |
|
192
|
|
|
|
|
|
|
--show-file-prefix Enable printing the filename on the start of every line ( off ). |
|
193
|
|
|
|
|
|
|
--show-file-heading Enable printing the filename before the hexdump output. ( off ). |
|
194
|
|
|
|
|
|
|
--color -c --colour Enable coloured output ( on ). --no-colour to disable. |
|
195
|
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
It can be used like so |
|
197
|
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
colourhexdump file/a.txt file/b.txt -- --this-is-treated-like-a-file.txt |
|
199
|
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
If you are using an HTML-enabled POD viewer, you should see a screenshot of this in action: |
|
201
|
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
( Everyone else can visit L<http://kentnl.github.io/App-colourhexdump/media/Screenshot.png> ) |
|
203
|
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=for html <center><img src="http://kentnl.github.io/App-colourhexdump/media/Screenshot.png" alt="Screenshot with explanation of colours" width="826" height="838"/></center> |
|
205
|
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=head1 METHODS |
|
207
|
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=head2 BUILD |
|
209
|
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
This just pushes extra_argv from getopt into the files list. |
|
211
|
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
B<INTERNAL> |
|
213
|
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=head2 get_filehandle |
|
215
|
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
my $fh = $self->get_filehandle( $filename_or_stdindash ); |
|
217
|
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
B<INTERNAL> |
|
219
|
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
=head2 run |
|
221
|
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
Run the app. |
|
223
|
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
App::colourhexdump->new_with_options()->run(); |
|
225
|
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
=head1 AUTHOR |
|
227
|
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
Kent Fredric <kentnl@cpan.org> |
|
229
|
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
231
|
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
This software is copyright (c) 2015 by Kent Fredric <kentnl@cpan.org>. |
|
233
|
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
|
235
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
|
236
|
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
=cut |