line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mac::CocoaDialog; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
117787
|
use version; our $VERSION = qv('0.0.3'); |
|
4
|
|
|
|
|
10871
|
|
|
4
|
|
|
|
|
25
|
|
4
|
|
|
|
|
|
|
|
5
|
4
|
|
|
4
|
|
386
|
use warnings; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
120
|
|
6
|
4
|
|
|
4
|
|
22
|
use strict; |
|
4
|
|
|
|
|
12
|
|
|
4
|
|
|
|
|
108
|
|
7
|
4
|
|
|
4
|
|
20
|
use Carp; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
451
|
|
8
|
4
|
|
|
4
|
|
3865
|
use English qw( -no_match_vars ); |
|
4
|
|
|
|
|
19211
|
|
|
4
|
|
|
|
|
25
|
|
9
|
4
|
|
|
4
|
|
6377
|
use IO::Handle; |
|
4
|
|
|
|
|
32591
|
|
|
4
|
|
|
|
|
3351
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# Module implementation here |
12
|
|
|
|
|
|
|
sub AUTOLOAD { |
13
|
1
|
|
|
1
|
|
1140
|
my $self = shift; |
14
|
|
|
|
|
|
|
|
15
|
1
|
|
|
|
|
7
|
(my $name = our $AUTOLOAD) =~ s{.*::}{}mxs; |
16
|
1
|
|
|
|
|
3
|
$name =~ tr/_/-/; |
17
|
|
|
|
|
|
|
|
18
|
1
|
|
|
|
|
12
|
return (ref($self) . '::Runner')->new(%$self, runmode => $name); |
19
|
|
|
|
|
|
|
} ## end sub AUTOLOAD |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub new { |
22
|
4
|
|
|
4
|
1
|
200
|
my $package = shift; |
23
|
4
|
50
|
|
|
|
27
|
my %opts = (@_ == 1) ? %$_ : @_; |
24
|
|
|
|
|
|
|
|
25
|
4
|
50
|
|
|
|
15
|
if (exists $opts{path}) { |
26
|
4
|
50
|
|
|
|
169
|
croak "cannot find CocoaDialog in provided path" |
27
|
|
|
|
|
|
|
unless -x $opts{path}; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
else { |
30
|
0
|
|
|
|
|
0
|
my $canonic = |
31
|
|
|
|
|
|
|
'/Applications/CocoaDialog.app/Contents/MacOS/CocoaDialog'; |
32
|
0
|
|
|
|
|
0
|
for my $candidate ($canonic, "$ENV{HOME}/$canonic") { |
33
|
0
|
0
|
|
|
|
0
|
next unless -x $candidate; |
34
|
0
|
|
|
|
|
0
|
$opts{path} = $candidate; |
35
|
0
|
|
|
|
|
0
|
last; |
36
|
|
|
|
|
|
|
} |
37
|
0
|
0
|
|
|
|
0
|
croak "cannot find CocoaDialog, please provide full path to it" |
38
|
|
|
|
|
|
|
unless -x $opts{path}; |
39
|
|
|
|
|
|
|
} ## end else [ if (exists $opts{path}) |
40
|
|
|
|
|
|
|
|
41
|
4
|
|
|
|
|
35
|
return bless {path => $opts{path}, cmdline => []}, $package; |
42
|
|
|
|
|
|
|
} ## end sub new |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub push_params { |
45
|
8
|
|
|
8
|
1
|
1304
|
my $self = shift; |
46
|
8
|
|
|
|
|
9
|
push @{$self->{cmdline}}, @_; |
|
8
|
|
|
|
|
36
|
|
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub command_line { |
50
|
9
|
|
|
9
|
1
|
1584
|
my $self = shift; |
51
|
9
|
100
|
|
|
|
28
|
return @{$self->{cmdline}} unless @_; |
|
5
|
|
|
|
|
68
|
|
52
|
|
|
|
|
|
|
|
53
|
4
|
100
|
66
|
|
|
32
|
return @_ unless @_ == 2 && ref($_[1]) eq 'HASH'; |
54
|
|
|
|
|
|
|
|
55
|
2
|
|
|
|
|
6
|
my ($cmd, $h) = @_; |
56
|
2
|
|
|
|
|
8
|
return $cmd, map { |
57
|
2
|
|
|
|
|
6
|
(my $k = $_) =~ tr/_/-/; |
58
|
2
|
50
|
|
|
|
11
|
('--' . $k) => (ref($h->{$_}) ? @{$h->{$_}} : $h->{$_}) |
|
2
|
|
|
|
|
17
|
|
59
|
|
|
|
|
|
|
} keys %$h; |
60
|
|
|
|
|
|
|
} ## end sub command_line |
61
|
|
|
|
|
|
|
|
62
|
1
|
|
|
1
|
1
|
1291
|
sub path { return $_[0]->{path} } |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub pipe_from { |
65
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
66
|
0
|
0
|
|
|
|
0
|
open my $fh, '-|', $self->path(), $self->command_line(@_) |
67
|
|
|
|
|
|
|
or croak "open() for output pipe: $OS_ERROR"; |
68
|
0
|
|
|
|
|
0
|
return $fh; |
69
|
|
|
|
|
|
|
} ## end sub pipe_from |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub qx { |
72
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
73
|
0
|
|
|
|
|
0
|
my $fh = $self->pipe_from(@_); |
74
|
0
|
0
|
|
|
|
0
|
return <$fh> if wantarray; |
75
|
0
|
|
|
|
|
0
|
return join '', <$fh>; |
76
|
|
|
|
|
|
|
} ## end sub qx |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub pipe_to { |
79
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
80
|
0
|
0
|
|
|
|
0
|
open my $fh, '|-', $self->path(), $self->command_line(@_) |
81
|
|
|
|
|
|
|
or croak "open() for input pipe: $OS_ERROR"; |
82
|
0
|
|
|
|
|
0
|
$fh->autoflush(1); # autoflush by default, it's what you want |
83
|
0
|
|
|
|
|
0
|
return $fh; |
84
|
|
|
|
|
|
|
} ## end sub pipe_to |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub background_system { |
87
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
88
|
|
|
|
|
|
|
|
89
|
0
|
|
|
|
|
0
|
my $pid = fork(); |
90
|
0
|
0
|
|
|
|
0
|
die "fork(): $OS_ERROR" unless defined $pid; |
91
|
0
|
0
|
|
|
|
0
|
return if $pid; # father returns immediately |
92
|
|
|
|
|
|
|
|
93
|
0
|
0
|
|
|
|
0
|
exec {$self->path()} $self->path(), $self->command_line(@_) |
|
0
|
|
|
|
|
0
|
|
94
|
|
|
|
|
|
|
or die "exec(): $OS_ERROR"; |
95
|
0
|
|
|
|
|
0
|
exit 1; |
96
|
|
|
|
|
|
|
} ## end sub background_system |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub foreground_system { |
99
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
100
|
0
|
|
|
|
|
0
|
system {$self->path()} $self->path(), $self->command_line(@_); |
|
0
|
|
|
|
|
0
|
|
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
{ |
104
|
4
|
|
|
4
|
|
38
|
no warnings; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
444
|
|
105
|
|
|
|
|
|
|
*grab = \&qx; |
106
|
|
|
|
|
|
|
*foreground = \&foreground_system; |
107
|
|
|
|
|
|
|
*background = \&background_system; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
package Mac::CocoaDialog::Runner; |
111
|
4
|
|
|
4
|
|
22
|
use strict; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
142
|
|
112
|
4
|
|
|
4
|
|
22
|
use warnings; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
126
|
|
113
|
4
|
|
|
4
|
|
71
|
use English qw( -no_match_vars ); |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
28
|
|
114
|
4
|
|
|
4
|
|
2257
|
use base qw( Mac::CocoaDialog ); |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
1161
|
|
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
sub AUTOLOAD { |
117
|
3
|
|
|
3
|
|
998
|
my $self = shift; |
118
|
|
|
|
|
|
|
|
119
|
3
|
|
|
|
|
16
|
(my $name = our $AUTOLOAD) =~ s{.*::}{}mxs; |
120
|
3
|
|
|
|
|
7
|
$name =~ tr/_/-/; |
121
|
3
|
|
|
|
|
17
|
$self->push_params('--' . $name, @_); |
122
|
|
|
|
|
|
|
|
123
|
3
|
|
|
|
|
13
|
return $self; |
124
|
|
|
|
|
|
|
} ## end sub AUTOLOAD |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
sub new { |
127
|
1
|
|
|
1
|
|
2
|
my $package = shift; |
128
|
1
|
50
|
|
|
|
6
|
my %opts = (@_ == 1) ? %$_ : @_; |
129
|
|
|
|
|
|
|
|
130
|
1
|
|
|
|
|
8
|
my $self = $package->SUPER::new(%opts); |
131
|
1
|
|
|
|
|
8
|
$self->push_params($opts{runmode}); |
132
|
|
|
|
|
|
|
|
133
|
1
|
|
|
|
|
5
|
return $self; |
134
|
|
|
|
|
|
|
} ## end sub new |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
1; # Magic true value required at end of module |
137
|
|
|
|
|
|
|
__END__ |