blib/lib/Lingua/Ogmios/FileManager.pm

filter: Statementstmt 67.6% 44 / 65 Branchbran 40.0% 8 / 20 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 72.7% 8 / 11 Podpod 0.0% 0 / 6 totaltotal 57.0% 61 / 107 CC 12 SCAR 21.7
CC
12
Cov
60%
getType
17.2
_load_MagicNumber
6.9
setMagicNumberFilename
2.0
CRAP 8.7
« blib/lib/Lingua/Ogmios/NLPWrappers/MorphoSemanticTagging.pm ↑ Summary blib/lib/Lingua/Ogmios/Annotations/Section.pm »
1 package Lingua::Ogmios::FileManager;
2  
3 16 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 16 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 16 ▶use File::MMagic;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 16 ▶use Lingua::Ogmios::Annotations;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9  
10 13 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
11 13 my ($class, $MNFile) = @_;
12  
13 13 my $FM = {
14 'MagicNumberFilename' => $MNFile,
15 'MagicNumbers' => undef,
16 };
17  
18 13 bless $FM, $class;
19  
20 13 $FM->_load_MagicNumber;
21  
22 13 return($FM);
23 }
24  
25 13 ▶sub getMagicNumberFilename {
Subroutine getMagicNumberFilename: called CC=1 SCAR=0.0
Pod undocumented
26 13 my ($self) = @_;
27  
28 13 return($self->{'MagicNumberFilename'});
29 }
30  
31 0 ▶sub setMagicNumberFilename {
Subroutine setMagicNumberFilename: not called CC=1 SCAR=6.9
Pod undocumented
32 0 my ($self, $filename) = @_;
33  
34 0 $self->{'MagicNumberFilename'} = $filename;
35 }
36  
37  
38  
39 sub _load_MagicNumber
40 13 ▶{
Subroutine _load_MagicNumber: called CC=4 SCAR=19.3
41 13 my $self = shift;
42 13 my $MNFile = $self->getMagicNumberFilename;
43  
44 13 my $mm = new File::MMagic; # use internal magic file
45  
46 13 print STDERR "Loading complementary magic number ... ";
47
48 13 ▶ if (open FILEM, $MNFile) {
Branch: 1 branch
BranchTrueFalseTotal
if (open FILEM, $MNFile) { } 0 13 13
49  
50 0 my $line;
51
52 0 ▶ while($line = <FILEM>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($line = readline FILEM)) 0 0 0
53 0 chomp $line;
54 0 $line =~ s/\s*\#.*//;
55 0 $line =~ s/^\s*//;
56
57 0 ▶ if ($line ne "") {
Branch: 1 branch
BranchTrueFalseTotal
if ($line ne "") 0 0 0
58 0 $mm->addMagicEntry($line);
59 }
60 }
61 0 print STDERR "done\n";
62  
63 } else {
64 13 warn "$MNFile: no such file or directory\n";
65 13 warn "No more Magic Number definition is loaded\n";
66  
67 }
68 13 $self->{'MagicNumbers'} = $mm;
69
70 13 return($mm);
71 }
72  
73 2 ▶sub getType {
Subroutine getType: called CC=9 SCAR=28.4
Pod undocumented
74 2 my ($self, $file) = @_;
75  
76 2 my $xmlns;
77  
78 2 ▶ if (-d $file) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $file) 1 1 2
79 1 return('directory');
80 }
81 1 ▶ if (-f $file) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $file) { } 1 0 1
82  
83 1 my $mm = $self->{'MagicNumbers'};
84  
85 1 print STDERR "Determining the type of the file " . $file . ": ";
86
87 1 my $type = $mm->checktype_filename($file);
88  
89 1 ▶ if ($file =~ /.ppt$/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file =~ /.ppt$/i) 0 1 1
90 0 $type = "application/powerpoint";
91 0 warn "Getting the type thanks to the extension\n";
92 }
93 1 ▶ if ($file =~ /.xls$/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file =~ /.xls$/i) 0 1 1
94 0 $type = "application/vnd.ms-excel";
95 0 warn "Getting the type thanks to the extension\n";
96 }
97 # if msword may be it should be relevant to check the extension, to better determine the type
98 1 $type =~ s/;.*//;
99 1 ▶ if (($type eq "message/rfc822") || ($file =~ /^x-system\/x-unix;/)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "message/rfc822" or $file =~ m[^x-system/x-unix;]) 0 1 1
Condition33%1/3
$type eq "message/rfc822" or $file =~ m[^x-system/x-unix;]
l!l&&r!l&&!r
001
MC/DC0%0/2
$type eq "message/rfc822" or $file =~ m[^x-system/x-unix;]
$type eq "message/rfc822" $file =~ m[^x-system/x-unix;]
Truth table33%1/3
A or B
A= $type eq "message/rfc822"B= $file =~ m[^x-system/x-unix;]
ABresult
1X1
011
000
100 0 ▶ if ($file =~ /.tex$/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file =~ /.tex$/i) 0 0 0
101 0 $type = "text/x-tex";
102 0 warn "Getting the type thanks to the extension\n";
103 }
104 }
105 1 ▶ if ($type eq 'text/xml') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "text/xml") 0 1 1
106 0 $xmlns = Lingua::Ogmios::Annotations::getNamespace($file);
107 0 $type .= " ns=$xmlns";
108 }
109 1 print STDERR "Type file: $type\n";
110 1 return($type);
111
112 } else {
113 0 warn "Unknown type\n";
114 0 return('unknown');
115 }
116  
117 }
118  
119  
120 0 ▶sub convert {
Subroutine convert: not called CC=1 SCAR=0.0
Pod undocumented
121  
122 }
123  
124 0 ▶sub XMLconvert {
Subroutine XMLconvert: not called CC=1 SCAR=0.0
Pod undocumented
125  
126 }
127  
128 16 1;
129  
130 __END__
« blib/lib/Lingua/Ogmios/NLPWrappers/MorphoSemanticTagging.pm ↑ Summary blib/lib/Lingua/Ogmios/Annotations/Section.pm »