line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Dicom::File::Detect; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# Pragmas. |
4
|
3
|
|
|
3
|
|
27254
|
use base qw(Exporter); |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
306
|
|
5
|
3
|
|
|
3
|
|
15
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
62
|
|
6
|
3
|
|
|
3
|
|
14
|
use warnings; |
|
3
|
|
|
|
|
13
|
|
|
3
|
|
|
|
|
90
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# Modules. |
9
|
3
|
|
|
3
|
|
2298
|
use Error::Pure qw(err); |
|
3
|
|
|
|
|
37209
|
|
|
3
|
|
|
|
|
71
|
|
10
|
3
|
|
|
3
|
|
166
|
use Readonly; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
591
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# Constants. |
13
|
|
|
|
|
|
|
Readonly::Array our @EXPORT => qw(dicom_detect_file); |
14
|
|
|
|
|
|
|
Readonly::Scalar our $DCM_MAGIC => qw{DICM}; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# Version. |
17
|
|
|
|
|
|
|
our $VERSION = 0.03; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# Detect DICOM file. |
20
|
|
|
|
|
|
|
sub dicom_detect_file { |
21
|
3
|
|
|
3
|
1
|
1553
|
my $file = shift; |
22
|
3
|
|
|
|
|
6
|
my $dcm_flag = 0; |
23
|
3
|
100
|
|
|
|
150
|
open my $fh, '<', $file or err "Cannot open file '$file'."; |
24
|
2
|
|
|
|
|
13
|
my $seek = seek $fh, 128, 0; |
25
|
2
|
|
|
|
|
3
|
my $magic; |
26
|
2
|
|
|
|
|
1030
|
my $read = read $fh, $magic, 4; |
27
|
2
|
50
|
|
|
|
47
|
close $fh or err "Cannot close file '$file'."; |
28
|
2
|
100
|
|
|
|
9
|
if ($magic eq $DCM_MAGIC) { |
29
|
1
|
|
|
|
|
6
|
return 1; |
30
|
|
|
|
|
|
|
} else { |
31
|
1
|
|
|
|
|
8
|
return 0; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
1; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
__END__ |