| 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
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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)
MC/DC0%0/2
$mimet ||= mimetype($file)
$mimet
mimetype($file)
Truth table0%0/3
A ||= B
A= $mimetB= mimetype($file)
| |||||||||||||||||||||
| 38 | 0 | ▶ | return undef unless $mimet; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 39 | 0 | ▶ | print "Using mimetype: $mimet\n" if $DEBUG; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | 0 | my $script = _locate_script($mimet); | |||||||||||||||||||
| 42 | 0 | ▶ | return undef unless $script; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | 0 | ▶ | print "Going to $act: $script $file\n" if $DEBUG; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 45 | 0 | ▶ | ($act eq 'exec') | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 66 | 0 | ▶ | next unless -e $_; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 67 | 0 | $script = $_; | |||||||||||||||||||
| 68 | 0 | last; | |||||||||||||||||||
| 69 | } | ||||||||||||||||||||
| 70 | 0 | ▶ | return undef unless $script; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 71 | 0 | ▶ | $script = "$script/AppRun" if -d $script; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 72 | 0 | ▶ | return -f $script ? $script : undef; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 81 | 1 | return "$p[0]/MIME-types", $m; | |||||||||||||||||||
| 82 | } | ||||||||||||||||||||
| 83 | |||||||||||||||||||||
| 84 | 3 | 1; | |||||||||||||||||||
| 85 | |||||||||||||||||||||
| 86 | __END__ | ||||||||||||||||||||