| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# $Id$ |
|
2
|
|
|
|
|
|
|
package File::Fingerprint; |
|
3
|
2
|
|
|
2
|
|
2983
|
use strict; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
94
|
|
|
4
|
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
13
|
use warnings; |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
157
|
|
|
6
|
2
|
|
|
2
|
|
23
|
no warnings; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
97
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
2446
|
use subs qw(); |
|
|
2
|
|
|
|
|
63
|
|
|
|
2
|
|
|
|
|
50
|
|
|
9
|
2
|
|
|
2
|
|
11
|
use vars qw($VERSION); |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
159
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
2
|
|
|
2
|
|
10
|
use Carp; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
2468
|
|
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
$VERSION = '0.10_02'; |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 NAME |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
File::Fingerprint - This is the description |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
use File::Fingerprint; |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
my $fingerprint = File::Fingerprint->roll( $file ); |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=over 4 |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=cut |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=item roll |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=cut |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub roll |
|
36
|
|
|
|
|
|
|
{ |
|
37
|
2
|
|
|
2
|
1
|
8999
|
my( $class, $file ) = @_; |
|
38
|
|
|
|
|
|
|
|
|
39
|
2
|
100
|
|
|
|
43
|
unless( -e $file ) |
|
40
|
|
|
|
|
|
|
{ |
|
41
|
1
|
|
|
|
|
137
|
carp "File [$file] does not exist! Can't fingerprint it"; |
|
42
|
1
|
|
|
|
|
5
|
return; |
|
43
|
|
|
|
|
|
|
} |
|
44
|
|
|
|
|
|
|
|
|
45
|
1
|
|
|
|
|
5
|
my $self = bless { file => $file }, $class; |
|
46
|
|
|
|
|
|
|
|
|
47
|
1
|
|
|
|
|
5
|
$self->init; |
|
48
|
|
|
|
|
|
|
} |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=item init |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=cut |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
BEGIN { |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
my %Prints = ( |
|
57
|
1
|
|
|
|
|
882
|
md5 => sub { require MD5; my $ctx = MD5->new; $ctx->add( $_[0]->file ); $ctx->hexdigest }, |
|
|
1
|
|
|
|
|
208
|
|
|
|
1
|
|
|
|
|
4
|
|
|
|
1
|
|
|
|
|
18
|
|
|
58
|
|
|
|
|
|
|
|
|
59
|
1
|
|
|
|
|
2165
|
mmagic => sub { require File::MMagic; File::MMagic->new->checktype_filename( $_[0]->file ) }, |
|
|
1
|
|
|
|
|
12310
|
|
|
60
|
|
|
|
|
|
|
# mime_info => sub { require File::MimeInfo; File::MimeInfo::mimetype( $_[0]->file ) }, |
|
61
|
|
|
|
|
|
|
|
|
62
|
1
|
|
|
|
|
4
|
extension => sub { my @b = split /\./, $_[0]->file; shift @b; [ @b ] }, |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
6
|
|
|
63
|
1
|
|
|
|
|
6
|
size => sub { -s $_[0]->file }, |
|
64
|
1
|
|
|
|
|
4
|
stat => sub { [ stat $_[0]->file ] }, |
|
65
|
1
|
|
|
|
|
23
|
lines => sub { open my($fh), "<", $_[0]->file; 1 while( <$fh> ); $. }, |
|
|
1
|
|
|
|
|
22
|
|
|
|
1
|
|
|
|
|
16
|
|
|
66
|
1
|
|
|
|
|
14
|
crc16 => sub { require Digest::CRC; my $ctx = Digest::CRC->new( type => 'crc16' ); open my($fh), "<", $_[0]->file; $ctx->addfile( $fh ); $ctx->hexdigest; }, |
|
|
1
|
|
|
|
|
10
|
|
|
|
1
|
|
|
|
|
18155
|
|
|
|
1
|
|
|
|
|
9
|
|
|
|
1
|
|
|
|
|
292
|
|
|
67
|
1
|
|
|
|
|
1101
|
crc32 => sub { require Digest::CRC; my $ctx = Digest::CRC->new( type => 'crc32' ); open my($fh), "<", $_[0]->file; $ctx->addfile( $fh ); $ctx->hexdigest; }, |
|
|
1
|
|
|
|
|
20839
|
|
|
|
1
|
|
|
|
|
11943
|
|
|
|
1
|
|
|
|
|
8
|
|
|
|
1
|
|
|
|
|
8691
|
|
|
68
|
1
|
|
|
|
|
16
|
basename => sub { require File::Basename; File::Basename::basename( $_[0]->file ) }, |
|
|
1
|
|
|
|
|
4
|
|
|
69
|
2
|
|
|
2
|
|
383
|
); |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub init |
|
72
|
|
|
|
|
|
|
{ |
|
73
|
1
|
|
|
1
|
1
|
3
|
my( $self ) = shift; |
|
74
|
|
|
|
|
|
|
|
|
75
|
1
|
|
|
|
|
5
|
print "File is ", $self->file, "\n"; |
|
76
|
|
|
|
|
|
|
|
|
77
|
1
|
|
|
|
|
10
|
foreach my $print ( keys %Prints ) |
|
78
|
|
|
|
|
|
|
{ |
|
79
|
9
|
|
|
|
|
14
|
$self->{$print} = eval { $self->$print() }; |
|
|
9
|
|
|
|
|
78
|
|
|
80
|
9
|
50
|
|
|
|
80896
|
carp "Error is $@\n" if $@; |
|
81
|
|
|
|
|
|
|
} |
|
82
|
|
|
|
|
|
|
|
|
83
|
1
|
|
|
|
|
7
|
return $self; |
|
84
|
|
|
|
|
|
|
} |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub AUTOLOAD |
|
87
|
|
|
|
|
|
|
{ |
|
88
|
12
|
|
|
12
|
|
1948
|
our $AUTOLOAD; |
|
89
|
|
|
|
|
|
|
|
|
90
|
12
|
|
|
|
|
82
|
( my $method = $AUTOLOAD ) =~ s/.*:://; |
|
91
|
|
|
|
|
|
|
|
|
92
|
12
|
100
|
|
|
|
222
|
carp "No such method as $AUTOLOAD" unless exists $Prints{$method}; |
|
93
|
|
|
|
|
|
|
|
|
94
|
12
|
|
100
|
|
|
192
|
return $_[0]->{$method} || $Prints{$method}->( $_[0] ); |
|
95
|
|
|
|
|
|
|
} |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
} |
|
98
|
|
|
|
|
|
|
|
|
99
|
1
|
|
|
1
|
|
1078
|
sub DESTROY { 1 } |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=item file |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
Returns the filename of the fingerprinted file. This is the same path |
|
104
|
|
|
|
|
|
|
passed to C. |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=cut |
|
107
|
|
|
|
|
|
|
|
|
108
|
10
|
|
|
10
|
1
|
1280
|
sub file { $_[0]->{file} } |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=item md5 |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=item mmagic |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
Return the MIME type of the file, as determined by File::MMagic. For |
|
115
|
|
|
|
|
|
|
instance, C. |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=item basename |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
Returns the basename of the file. |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=item extension |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
Returns the file extensions as an array reference. |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
For instance, F returns C<[ qw(tar gz) ]>. |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=item size |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
Returns the file size, in bytes. |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=item stat |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
Returns that stat buffer. This is the array reference of all of the values |
|
134
|
|
|
|
|
|
|
returned by C. |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=item lines |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
Returns the line count of the file. |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=item crc16 |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
Returns the CRC-16 checksum of the file. |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=item crc32 |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
Returns the CRC-32 checksum of the file. |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=back |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head1 TO DO |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=head1 SOURCE AVAILABILITY |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
This source is in Github |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
git://github.com/briandfoy/file-fingerprint.git |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=head1 AUTHOR |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
brian d foy, C<< >> |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
Copyright (c) 2008, brian d foy, All Rights Reserved. |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
You may redistribute this under the same terms as Perl itself. |
|
171
|
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=cut |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
1; |