File Coverage

blib/lib/Dicom/File/Detect.pm
Criterion Covered Total %
statement 25 25 100.0
branch 5 6 83.3
condition n/a
subroutine 6 6 100.0
pod 1 1 100.0
total 37 38 97.3


line stmt bran cond sub pod time code
1             package Dicom::File::Detect;
2              
3 3     3   73135 use base qw(Exporter);
  3         16  
  3         396  
4 3     3   20 use strict;
  3         6  
  3         58  
5 3     3   25 use warnings;
  3         14  
  3         118  
6              
7 3     3   1455 use Error::Pure qw(err);
  3         34576  
  3         82  
8 3     3   176 use Readonly;
  3         6  
  3         552  
9              
10             # Constants.
11             Readonly::Array our @EXPORT => qw(dicom_detect_file);
12             Readonly::Scalar our $DCM_MAGIC => qw{DICM};
13              
14             our $VERSION = 0.04;
15              
16             # Detect DICOM file.
17             sub dicom_detect_file {
18 3     3 1 1631 my $file = shift;
19              
20 3         6 my $dcm_flag = 0;
21 3 100       140 open my $fh, '<', $file or err "Cannot open file '$file'.";
22 2         20 my $seek = seek $fh, 128, 0;
23 2         4 my $magic;
24 2         36 my $read = read $fh, $magic, 4;
25 2 50       25 close $fh or err "Cannot close file '$file'.";
26              
27 2 100       9 if ($magic eq $DCM_MAGIC) {
28 1         6 return 1;
29             } else {
30 1         6 return 0;
31             }
32             }
33              
34             1;
35              
36             __END__