File Coverage

blib/lib/CAD/AutoCAD/Detect.pm
Criterion Covered Total %
statement 32 32 100.0
branch 5 6 83.3
condition 3 3 100.0
subroutine 9 9 100.0
pod 1 1 100.0
total 50 51 98.0


line stmt bran cond sub pod time code
1             package CAD::AutoCAD::Detect;
2              
3 3     3   142833 use base qw(Exporter);
  3         5  
  3         379  
4 3     3   16 use strict;
  3         5  
  3         80  
5 3     3   15 use warnings;
  3         3  
  3         174  
6              
7 3     3   1531 use CAD::Format::DWG::Version;
  3         47819  
  3         227  
8 3     3   25 use Error::Pure qw(err);
  3         5  
  3         169  
9 3     3   14 use List::Util 1.33 qw(any);
  3         47  
  3         151  
10 3     3   13 use Readonly;
  3         5  
  3         828  
11              
12             # Constants.
13             Readonly::Array our @EXPORT => qw(detect_dwg_file);
14              
15             our $VERSION = 0.05;
16              
17             # Detect DWG file.
18             sub detect_dwg_file {
19 6     6 1 266452 my $file = shift;
20              
21 6         13 my $dwg_flag = 0;
22 6 100       457 open my $fh, '<', $file or err "Cannot open file '$file'.";
23 5         17 my $magic;
24 5         198 my $read = read $fh, $magic, 6;
25 5 50       86 close $fh or err "Cannot close file '$file'.";
26              
27             # Remove NULL characters from end of string.
28 5         32 $magic =~ s/\x00$//;
29              
30 5 100 100 37   68 if ($read == 6 && (any { $_ eq $magic }
  37         9077  
31             CAD::Format::DWG::Version->list_of_dwg_identifiers)) {
32              
33 3         27 return $magic;
34             } else {
35 2         15 return;
36             }
37             }
38              
39             1;
40              
41             __END__