Psh/Strategy/Darwin_apps.pm untested

filter: Statementstmt 0.0% 0 / 39 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 7 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 77 CC 9 SCAR 31.9
CC
9
Cov
0%
_recursive_search
42.0
applies
20.0
consumes
2.0
CRAP 24.3
1 package Psh::Strategy::Darwin_apps;
2  
3  
4 =item * C<darwin_apps>
5  
6 This strategy will search for Mac OS X/Darwin .app bundles and
7 execute them using the system 'open' command'
8  
9 =cut
10  
11 require Psh::Strategy;
12  
13 @Psh::Strategy::Darwin_apps::ISA=('Psh::Strategy');
14  
15 sub consumes {
16 return Psh::Strategy::CONSUME_TOKENS;
17 }
18  
19 sub runs_before {
20 return qw(eval);
21 }
22  
23 sub _recursive_search {
24 my $file= shift;
25 my $dir= shift;
26 my $lvl= shift;
27  
28 opendir( DIR, $dir) || return ();
29 my @files= readdir(DIR);
30 closedir( DIR);
31 my @result= map { Psh::OS::catdir($dir,$_) }
32 grep { lc("$file.app") eq lc($_) } @files;
33 return $result[0] if @result;
34 if ($lvl<10) {
35 foreach my $tmp (@files) {
36 my $tmpdir= Psh::OS::catdir($dir,$tmp);
37 next if ! -d $tmpdir || !Psh::OS::no_upwards($tmp);
38 next if index($tmpdir,'.')>=0;
39 push @result, _recursive_search($file, $tmpdir, $lvl+1);
40 }
41 }
42 return $result[0] if @result;
43 }
44  
45  
46 sub applies {
47 my $com= @{$_[2]}->[0];
48 if ($com !~ m/$Psh::which_regexp/) { return ''; }
49 my $path=$ENV{APP_PATH}||'/Applications';
50 my @path= split /:/, $path;
51 my $executable;
52 foreach (@path) {
53 $executable= _recursive_search($com,$_,1);
54 last if $executable;
55 }
56 return $executable if defined $executable;
57 return '';
58 }
59  
60 sub execute {
61 my $executable= $_[3];
62 my $tmp= CORE::system("/usr/bin/open $executable");
63 $tmp= $tmp/256;
64 return ($tmp==0, undef, undef, $tmp);
65 }
66  
67 1;