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