MimeInfo/Rox.pm

filter: Statementstmt 59.0% 36 / 61 Branchbran 10.0% 3 / 30 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 66.6% 8 / 12 Podpod 100% 3 / 3 totaltotal 45.0% 50 / 111 CC 18 SCAR 37.0
CC
18
Cov
41%
_do_mime
72.0
_locate_script
72.0
import
3.0
CRAP 40.5
↑ Summary MimeInfo/Applications.pm »
1 package File::MimeInfo::Rox;
2  
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use File::BaseDir qw/config_home data_dirs/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 require Exporter;
9  
10 3 our @ISA = qw(Exporter);
11 3 our @EXPORT = qw(mime_exec mime_system);
12 3 our @EXPORT_OK = qw(suggest_script_name);
13 3 our %EXPORT_TAGS = (magic => \@EXPORT);
14 3 our $VERSION = '0.37';
15 our @choicespath = (
16 config_home('rox.sourceforge.net'),
17 3 File::Spec->catdir($ENV{HOME}, 'Choices'),
18 data_dirs('Choices'),
19 );
20 3 our ($DEBUG);
21  
22 1 ▶sub import {
Subroutine import: called CC=3 SCAR=11.1
23 1 ▶ my $parent = (grep {$_ eq q/:magic/} @_)
Branch: 1 branch
BranchTrueFalseTotal
grep({$_ eq ':magic';} @_) ? : 0 1 1
24 ? q/File::MimeInfo::Magic/
25 : q/File::MimeInfo/;
26 1 ▶ eval "use $parent";
Subroutine BEGIN: called CC=1 SCAR=0.0
27 1 ▶ die $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 1 1
28 1 goto \&Exporter::import;
29 }
30  
31 0 ▶sub mime_system { _do_mime('system', @_) }
Subroutine mime_system: not called CC=1 SCAR=6.9
Pod documented
32 0 ▶sub mime_exec { _do_mime('exec', @_) }
Subroutine mime_exec: not called CC=1 SCAR=6.9
Pod documented
33  
34 0 ▶sub _do_mime {
Subroutine _do_mime: not called CC=8 SCAR=42.8
35 0 my ($act, $file, $mimet) = (shift, shift, shift);
36  
37 0 ▶ $mimet ||= mimetype($file);
Condition0%0/3
$mimet ||= mimetype($file)
l!l&&r!l&&!r
000
MC/DC0%0/2
$mimet ||= mimetype($file)
$mimet mimetype($file)
Truth table0%0/3
A ||= B
A= $mimetB= mimetype($file)
ABresult
1X1
011
000
38 0 ▶ return undef unless $mimet;
Branch: 1 branch
BranchTrueFalseTotal
unless $mimet 0 0 0
39 0 ▶ print "Using mimetype: $mimet\n" if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $File::MimeInfo::Rox::DEBUG 0 0 0
40  
41 0 my $script = _locate_script($mimet);
42 0 ▶ return undef unless $script;
Branch: 1 branch
BranchTrueFalseTotal
unless $script 0 0 0
43  
44 0 ▶ print "Going to $act: $script $file\n" if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $File::MimeInfo::Rox::DEBUG 0 0 0
45 0 ▶ ($act eq 'exec')
Branch: 2 branches
BranchTrueFalseTotal
$act eq "exec" ? exec($script, $file, @_) : system($script, $file, @_) == 0 or croak("couldn't ${act}: $script $file") 0 0 0
$act eq 'exec' ? : 0 0 0
46 ? exec($script, $file, @_)
47 : (system($script, $file, @_) == 0)
48 or croak "couldn't $act: $script $file";
49 0 42;
50 }
51  
52 0 ▶sub _locate_script {
Subroutine _locate_script: not called CC=8 SCAR=42.8
53 0 my $mime = shift;
54 0 $mime =~ /^(\w+)/;
55 0 my $media = $1;
56 0 $mime =~ s#/#_#;
57 my @p = $ENV{CHOICESPATH}
58 ? split(/:/, $ENV{CHOICESPATH})
59 0 ▶ : (@choicespath);
Branch: 1 branch
BranchTrueFalseTotal
$ENV{'CHOICESPATH'} ? : 0 0 0
60 0 my $script;
61 0 for (
62 map("$_/MIME-types/$mime", @p),
63 map("$_/MIME-types/$media", @p)
64 ) {
65 0 ▶ print "looking for: $_\n" if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $File::MimeInfo::Rox::DEBUG 0 0 0
66 0 ▶ next unless -e $_;
Branch: 1 branch
BranchTrueFalseTotal
unless -e $_ 0 0 0
67 0 $script = $_;
68 0 last;
69 }
70 0 ▶ return undef unless $script;
Branch: 1 branch
BranchTrueFalseTotal
unless $script 0 0 0
71 0 ▶ $script = "$script/AppRun" if -d $script;
Branch: 1 branch
BranchTrueFalseTotal
if -d $script 0 0 0
72 0 ▶ return -f $script ? $script : undef;
Branch: 1 branch
BranchTrueFalseTotal
-f $script ? : 0 0 0
73 }
74  
75 1 ▶sub suggest_script_name {
Subroutine suggest_script_name: called CC=2 SCAR=7.0
Pod documented
76 1 my $m = pop;
77 1 $m =~ s#/#_#;
78 my @p = $ENV{CHOICESPATH}
79 ? split(/:/, $ENV{CHOICESPATH})
80 1 ▶ : (@choicespath);
Branch: 1 branch
BranchTrueFalseTotal
$ENV{'CHOICESPATH'} ? : 1 0 1
81 1 return "$p[0]/MIME-types", $m;
82 }
83  
84 3 1;
85  
86 __END__
↑ Summary MimeInfo/Applications.pm »