line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package File::MimeInfo::Rox; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
1723
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
64
|
|
4
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
58
|
|
5
|
2
|
|
|
2
|
|
9
|
use Carp; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
130
|
|
6
|
2
|
|
|
2
|
|
488
|
use File::BaseDir qw/config_home data_dirs/; |
|
2
|
|
|
|
|
1330
|
|
|
2
|
|
|
|
|
114
|
|
7
|
2
|
|
|
2
|
|
14
|
use File::Spec; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
1651
|
|
8
|
|
|
|
|
|
|
require Exporter; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
11
|
|
|
|
|
|
|
our @EXPORT = qw(mime_exec mime_system); |
12
|
|
|
|
|
|
|
our @EXPORT_OK = qw(suggest_script_name); |
13
|
|
|
|
|
|
|
our %EXPORT_TAGS = (magic => \@EXPORT); |
14
|
|
|
|
|
|
|
our $VERSION = '0.31'; |
15
|
|
|
|
|
|
|
our @choicespath = ( |
16
|
|
|
|
|
|
|
config_home('rox.sourceforge.net'), |
17
|
|
|
|
|
|
|
File::Spec->catdir($ENV{HOME}, 'Choices'), |
18
|
|
|
|
|
|
|
data_dirs('Choices'), |
19
|
|
|
|
|
|
|
); |
20
|
|
|
|
|
|
|
our ($DEBUG); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub import { |
23
|
1
|
50
|
|
1
|
|
13
|
my $parent = (grep {$_ eq q/:magic/} @_) |
|
1
|
|
|
|
|
6
|
|
24
|
|
|
|
|
|
|
? q/File::MimeInfo::Magic/ |
25
|
|
|
|
|
|
|
: q/File::MimeInfo/; |
26
|
1
|
|
|
1
|
|
82
|
eval "use $parent"; |
|
1
|
|
|
|
|
593
|
|
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
65
|
|
27
|
1
|
50
|
|
|
|
7
|
die $@ if $@; |
28
|
1
|
|
|
|
|
40
|
goto \&Exporter::import; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
0
|
|
|
0
|
1
|
0
|
sub mime_system { _do_mime('system', @_) } |
32
|
0
|
|
|
0
|
1
|
0
|
sub mime_exec { _do_mime('exec', @_) } |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub _do_mime { |
35
|
0
|
|
|
0
|
|
0
|
my ($act, $file, $mimet) = (shift, shift, shift); |
36
|
|
|
|
|
|
|
|
37
|
0
|
|
0
|
|
|
0
|
$mimet ||= mimetype($file); |
38
|
0
|
0
|
|
|
|
0
|
return undef unless $mimet; |
39
|
0
|
0
|
|
|
|
0
|
print "Using mimetype: $mimet\n" if $DEBUG; |
40
|
|
|
|
|
|
|
|
41
|
0
|
|
|
|
|
0
|
my $script = _locate_script($mimet); |
42
|
0
|
0
|
|
|
|
0
|
return undef unless $script; |
43
|
|
|
|
|
|
|
|
44
|
0
|
0
|
|
|
|
0
|
print "Going to $act: $script $file\n" if $DEBUG; |
45
|
0
|
0
|
|
|
|
0
|
($act eq 'exec') |
|
|
0
|
|
|
|
|
|
46
|
|
|
|
|
|
|
? exec($script, $file, @_) |
47
|
|
|
|
|
|
|
: (system($script, $file, @_) == 0) |
48
|
|
|
|
|
|
|
or croak "couldn't $act: $script $file"; |
49
|
0
|
|
|
|
|
0
|
42; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub _locate_script { |
53
|
0
|
|
|
0
|
|
0
|
my $mime = shift; |
54
|
0
|
|
|
|
|
0
|
$mime =~ /^(\w+)/; |
55
|
0
|
|
|
|
|
0
|
my $media = $1; |
56
|
0
|
|
|
|
|
0
|
$mime =~ s#/#_#; |
57
|
|
|
|
|
|
|
my @p = $ENV{CHOICESPATH} |
58
|
|
|
|
|
|
|
? split(/:/, $ENV{CHOICESPATH}) |
59
|
0
|
0
|
|
|
|
0
|
: (@choicespath); |
60
|
0
|
|
|
|
|
0
|
my $script; |
61
|
0
|
|
|
|
|
0
|
for ( |
62
|
|
|
|
|
|
|
map("$_/MIME-types/$mime", @p), |
63
|
|
|
|
|
|
|
map("$_/MIME-types/$media", @p) |
64
|
|
|
|
|
|
|
) { |
65
|
0
|
0
|
|
|
|
0
|
print "looking for: $_\n" if $DEBUG; |
66
|
0
|
0
|
|
|
|
0
|
next unless -e $_; |
67
|
0
|
|
|
|
|
0
|
$script = $_; |
68
|
0
|
|
|
|
|
0
|
last; |
69
|
|
|
|
|
|
|
} |
70
|
0
|
0
|
|
|
|
0
|
return undef unless $script; |
71
|
0
|
0
|
|
|
|
0
|
$script = "$script/AppRun" if -d $script; |
72
|
0
|
0
|
|
|
|
0
|
return -f $script ? $script : undef; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub suggest_script_name { |
76
|
1
|
|
|
1
|
1
|
573
|
my $m = pop; |
77
|
1
|
|
|
|
|
6
|
$m =~ s#/#_#; |
78
|
|
|
|
|
|
|
my @p = $ENV{CHOICESPATH} |
79
|
|
|
|
|
|
|
? split(/:/, $ENV{CHOICESPATH}) |
80
|
1
|
50
|
|
|
|
11
|
: (@choicespath); |
81
|
1
|
|
|
|
|
9
|
return "$p[0]/MIME-types", $m; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
1; |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
__END__ |