lib/Mac/Alias.pm

filter: Statementstmt 81.5% 150 / 184 Branchbran 65.6% 67 / 102 Conditioncond 34.7% 16 / 46 MC/DCmcdc 24.1% 7 / 29 Subroutinesub 100% 13 / 13 Podpod 100% 6 / 6 totaltotal 68.1% 259 / 380 CC 72 SCAR 32.1
CC
72
Cov
70%
parse_alias
38.7
read_alias_mac
24.9
_osascript
18.7
CRAP 24.7
↑ Summary
1 4 ▶use v5.26;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 package Mac::Alias;
5 # ABSTRACT: Read or create macOS alias files
6 4 $Mac::Alias::VERSION = '1.01';
7  
8 4 ▶use Carp qw(carp croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use Fcntl ':seek';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 ▶use Path::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 4 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
13 4 our @EXPORT_OK = qw(
14 is_alias
15 make_alias
16 parse_alias
17 read_alias
18 read_alias_mac
19 read_alias_perl
20 );
21 4 our %EXPORT_TAGS = (all => \@EXPORT_OK);
22  
23  
24 # Finder alias constants
25  
26 4 our $MAGIC = "book\0\0\0\0mark\0\0\0\0";
27  
28 4 our %ITEM_TYPES= (
29 0x1004 => 'pathComponents', # POSIX path
30 0x1005 => 'fileIDs', # inode path
31 0x1010 => 'resourceProps',
32 0x1020 => 'fileName',
33 0x1040 => 'creationDate',
34 0x1054 => 'relativeDirsUp',
35 0x1055 => 'relativeDirsDown',
36 0x1056 => 'createdWithRelativeURL',
37 0x2000 => 'volInfoDepths',
38 0x2002 => 'volPath',
39 0x2005 => 'volURL',
40 0x2010 => 'volName',
41 0x2011 => 'volUUID',
42 0x2012 => 'volCapacity',
43 0x2013 => 'volCreationDate',
44 0x2020 => 'volProps',
45 0x2030 => 'volWasBoot',
46 0x2050 => 'volMountURL',
47 0xc001 => 'volHomeDirRelativePathComponentCount',
48 0xc011 => 'userName',
49 0xc012 => 'userUID',
50 0xd001 => 'wasFileIDFormat',
51 0xd010 => 'creationOptions',
52 0xf017 => 'displayName',
53 0xf020 => 'effectiveIconData',
54 0xf022 => 'typeBindingData',
55 0xfe00 => 'aliasData', # 'alis' resource
56 );
57  
58 4 our %CREATION_OPTIONS = (
59 kCFURLBookmarkCreationMinimalBookmarkMask => 1 << 9,
60 kCFURLBookmarkCreationPreferFileIDResolutionMask => 1 << 8,
61 kCFURLBookmarkCreationSecurityScopeAllowOnlyReadAccess => 1 << 12,
62 kCFURLBookmarkCreationSuitableForBookmarkFile => 1 << 10,
63 kCFURLBookmarkCreationWithSecurityScope => 1 << 11,
64 kCFURLBookmarkCreationWithoutImplicitSecurityScope => 1 << 29,
65 );
66  
67 4 our $EPOCH_OFFSET = 3600 * 24 * (365 * 31 + 8); # kCFAbsoluteTimeIntervalSince1970
68  
69  
70 5 ▶sub parse_alias :prototype($) {
Subroutine parse_alias: called CC=35 SCAR=36.5
Pod documented
71 5 my ($file) = @_;
72
73 5 ▶ open my $fh, '<:raw', $file or croak "$file: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<:raw", $file or croak("${file}: $!") 5 0 5
74 5 my $success = read $fh, my $header, 20;
75 5 ▶ $success and $MAGIC eq substr $header, 0, 16
Branch: 1 branch
BranchTrueFalseTotal
$success and $Mac::Alias::MAGIC eq substr($header, 0, 16) or croak("${file}: Not a data fork alias") 3 2 5
Condition100%3/3
$success and $Mac::Alias::MAGIC eq substr($header, 0, 16)
!ll&&!rl&&r
113
MC/DC100%2/2
$success and $Mac::Alias::MAGIC eq substr($header, 0, 16)
$success $Mac::Alias::MAGIC eq substr($header, 0, 16)
Truth table100%3/3
A and B
A= $successB= $Mac::Alias::MAGIC eq substr($header, 0, 16)
ABresult
0X0
100
111
76 or croak "$file: Not a data fork alias";
77
78 3 ▶ my $start = unpack 'V', substr $header, -4
Branch: 1 branch
BranchTrueFalseTotal
my $start = unpack("V", substr($header, -4)) or croak("${file}: Not a data fork alias: Header empty") 3 0 3
79 or croak "$file: Not a data fork alias: Header empty";
80
81 3 seek $fh, 0, SEEK_SET;
82 3 ▶ read $fh, $header, $start or die "$!" || "Unexpected EOF in alias header";
Branch: 1 branch
BranchTrueFalseTotal
read $fh, $header, $start or die "$!" || "Unexpected EOF in alias header" 3 0 3
Condition0%0/2
"$!" || 'Unexpected EOF in alias header'
l!l
00
MC/DC0%0/1
"$!" || 'Unexpected EOF in alias header'
"$!"
Truth table0%0/2
A
A= "$!"
Aresult
11
00
83
84 3 ▶ read $fh, my $next, 4 or die "$!" || "Unexpected EOF in alias data";
Branch: 1 branch
BranchTrueFalseTotal
read $fh, my $next, 4 or die "$!" || "Unexpected EOF in alias data" 3 0 3
Condition0%0/2
"$!" || 'Unexpected EOF in alias data'
l!l
00
MC/DC0%0/1
"$!" || 'Unexpected EOF in alias data'
"$!"
Truth table0%0/2
A
A= "$!"
Aresult
11
00
85 3 $next = unpack 'V', $next;
86
87 3 my @data;
88 my @toc;
89 3 ▶ while ((my $item = pop @toc) || $next) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $item = pop @toc or $next) 75 3 78
Condition100%3/3
my $item = pop @toc or $next
l!l&&r!l&&!r
7143
MC/DC100%2/2
my $item = pop @toc or $next
my $item = pop @toc $next
Truth table100%3/3
A or B
A= my $item = pop @tocB= $next
ABresult
1X1
011
000
90
91 75 my $data = $data[$#data];
92
93 75 my ($item_type, $item_offset, $item_flags, $item_ref);
94
95 75 ▶ if (ref $item) { # path element
Branch: 2 branches
BranchTrueFalseTotal
if (ref $item) { } 16 59 75
elsif (defined $item) { } 55 4 59
96 16 ($item_offset, $item_ref) = @$item;
97 }
98 elsif (defined $item) {
99 55 ($item_type, $item_offset, $item_flags) = unpack 'V V V', $item;
100 }
101 else { # no item left in queue: read next TOC
102 4 $item_offset = $next;
103 }
104
105 75 seek $fh, $start + $item_offset, SEEK_SET;
106 75 ▶ read $fh, my $chunk_header, 8 or die "$!" || "Unexpected EOF in alias chunk";
Branch: 1 branch
BranchTrueFalseTotal
read $fh, my $chunk_header, 8 or die "$!" || "Unexpected EOF in alias chunk" 75 0 75
Condition0%0/2
"$!" || 'Unexpected EOF in alias chunk'
l!l
00
MC/DC0%0/1
"$!" || 'Unexpected EOF in alias chunk'
"$!"
Truth table0%0/2
A
A= "$!"
Aresult
11
00
107 75 my ($chunk_size, $chunk_type) = unpack 'V l<', $chunk_header;
108 75 my $bytes = (read $fh, my $chunk_data, $chunk_size);
109 75 ▶ $bytes == $chunk_size or die "$!" || "Unexpected EOF in alias file";
Branch: 1 branch
BranchTrueFalseTotal
$bytes == $chunk_size or die "$!" || "Unexpected EOF in alias file" 75 0 75
Condition0%0/2
"$!" || 'Unexpected EOF in alias file'
l!l
00
MC/DC0%0/1
"$!" || 'Unexpected EOF in alias file'
"$!"
Truth table0%0/2
A
A= "$!"
Aresult
11
00
110
111 75 my $key = $item_offset;
112 75 ▶ if ($item_type) {
Branch: 1 branch
BranchTrueFalseTotal
if ($item_type) 55 20 75
113 55 $key = $ITEM_TYPES{$item_type};
114 55 ▶ $key //= sprintf '%#x', $item_type;
Condition50%1/2
$key //= sprintf("%#x", $item_type)
l!l
550
MC/DC0%0/1
$key //= sprintf("%#x", $item_type)
$key
Truth table50%1/2
A
A= $key
Aresult
11
00
115 }
116 75 my $parsed;
117
118 75 ▶ if ($chunk_type == -2) { # TOC
Branch: 9 branches
BranchTrueFalseTotal
if ($chunk_type == -2) { } 4 71 75
elsif (257 == ($chunk_type & 63487)) { } 26 45 71
elsif (513 == $chunk_type) { } 10 35 45
elsif (771 == $chunk_type) { } 7 28 35
elsif (772 == $chunk_type) { } 8 20 28
elsif (1024 == $chunk_type) { } 7 13 20
elsif (1280 == ($chunk_type & 65280)) { } 5 8 13
elsif (1537 == $chunk_type) { } 6 2 8
elsif (2561 == $chunk_type) { } 2 0 2
119 4 my ($level, $count);
120 4 ($level, $next, $count) = unpack 'V V V', $chunk_data;
121 4 for my $i (reverse 1 .. $count) {
122 # It just so happens that the TOC header is the same
123 # length as a TOC item, so we start counting at 1
124 55 my $item = substr $chunk_data, 12 * $i, 12;
125 55 push @toc, $item;
126 }
127 4 push @data, $data = {};
128 4 ($key, $parsed) = (level => $level);
129 }
130
131 elsif (0x0101 == ($chunk_type & 0xf7ff)) { # string / URL
132 26 $parsed = substr $chunk_data, 0, $chunk_size;
133 26 utf8::decode $parsed;
134 }
135
136 elsif (0x0201 == $chunk_type) { # structured data
137 10 $parsed = $chunk_data; # TODO
138 }
139
140 elsif (0x0303 == $chunk_type) { # 32-bit integer
141 7 $parsed = unpack 'l<', $chunk_data;
142
143 # Make readable names available for creationOptions
144 7 ▶ if ($item_type && $item_type == 0xd010) {
Branch: 1 branch
BranchTrueFalseTotal
if ($item_type and $item_type == 53264) 3 4 7
Condition66%2/3
$item_type and $item_type == 53264
!ll&&!rl&&r
403
MC/DC50%1/2
$item_type and $item_type == 53264
$item_type $item_type == 53264
Truth table66%2/3
A and B
A= $item_typeB= $item_type == 53264
ABresult
0X0
100
111
145 3 my %options = map { $_ => $parsed }
146 3 grep { $CREATION_OPTIONS{$_} & $parsed }
147 keys %CREATION_OPTIONS;
148 3 ▶ $parsed = %options ? \%options : { $parsed => $parsed };
Branch: 1 branch
BranchTrueFalseTotal
%options ? : 3 0 3
149 }
150 }
151
152 elsif (0x0304 == $chunk_type) { # 64-bit integer
153 8 $parsed = $chunk_data;
154 8 eval { $parsed = unpack 'q<', $chunk_data; };
155 # eval because unpack 'q' will fail on 32-bit Perls
156 }
157
158 elsif (0x0400 == $chunk_type) { # timestamp
159 7 $parsed = $EPOCH_OFFSET + unpack 'd>', $chunk_data;
160 }
161
162 elsif (0x0500 == ($chunk_type & 0xff00)) { # boolean
163 5 $parsed = !! ($chunk_type & 0x00ff);
164 }
165
166 elsif (0x0601 == $chunk_type) { # path
167 6 $data->{$key} = [];
168 6 my $path_count = $chunk_size / 4;
169 6 my @path = unpack "V[$path_count]", $chunk_data;
170 6 push @toc, map { [ $_, $data->{$key} ] } reverse @path;
171 6 next;
172 }
173
174 elsif (0x0a01 == $chunk_type) { # null
175 2 $parsed = undef;
176 }
177
178 else {
179 0 croak sprintf 'Alias file chunk type %#06x unsupported at offset %i (item %#x) in file %s',
180 $chunk_type, $item_offset, $item_type, $file;
181 }
182
183 69 ▶ if (ref $item_ref eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $item_ref eq 'ARRAY') { } 16 53 69
184 16 push @$item_ref, $parsed;
185 }
186 else {
187 53 $data->{$key} = $parsed;
188 }
189 }
190
191 3 close $fh;
192
193 3 $data[0]->{header} = $header;
194 3 $_->{path} = '/' . join '/', $_->{pathComponents}->@* for grep { $_->{pathComponents} } @data;
195 3 for my $i (1 .. $#data) {
196 1 $data[$i - 1]->{next} = $data[$i];
197 }
198 3 return $data[0];
199
200 }
201  
202  
203 5 ▶sub is_alias :prototype($) {
Subroutine is_alias: called CC=3 SCAR=11.0
Pod documented
204 5 my ($file) = @_;
205
206 # Try to read data fork alias magic number
207 5 ▶ open my $fh, '<:raw', $file or return;
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<:raw", $file or return 5 0 5
208 5 ▶ read $fh, my $data, 16 or return;
Branch: 1 branch
BranchTrueFalseTotal
read $fh, my $data, 16 or return 4 1 5
209 4 close $fh;
210 4 return $data eq $MAGIC;
211 }
212  
213  
214 10 ▶sub read_alias_perl :prototype($) {
Subroutine read_alias_perl: called CC=16 SCAR=28.8
Pod documented
215 10 my ($file) = @_;
216
217 10 ▶ open my $fh, '<:raw', $file or return;
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<:raw", $file or return 10 0 10
218 10 ▶ read $fh, my $header, 20 or return;
Branch: 1 branch
BranchTrueFalseTotal
read $fh, my $header, 20 or return 8 2 10
219 8 ▶ $MAGIC eq substr $header, 0, 16 or return;
Branch: 1 branch
BranchTrueFalseTotal
$Mac::Alias::MAGIC eq substr($header, 0, 16) or return 6 2 8
220
221 # read header
222 6 ▶ my $start = unpack 'V', substr $header, -4 or return;
Branch: 1 branch
BranchTrueFalseTotal
my $start = unpack("V", substr($header, -4)) or return 6 0 6
223 6 seek $fh, $start, SEEK_SET;
224 6 ▶ read $fh, my $toc_offset, 4 or return;
Branch: 1 branch
BranchTrueFalseTotal
read $fh, my $toc_offset, 4 or return 6 0 6
225 6 $toc_offset = unpack 'V', $toc_offset;
226
227 # read TOC
228 6 my $path_offset;
229 6 seek $fh, $start + $toc_offset + 20, SEEK_SET;
230 6 ▶ while (read $fh, my $item, 12) {
Branch: 1 branch
BranchTrueFalseTotal
if (read $fh, my $item, 12) 6 0 6
231 6 my $item_type;
232 6 ($item_type, $path_offset) = unpack 'V V', $item;
233 6 ▶ last if $item_type == 0x1004; # pathComponents
Branch: 1 branch
BranchTrueFalseTotal
if $item_type == 4100 6 0 6
234 }
235 6 ▶ $path_offset or return;
Branch: 1 branch
BranchTrueFalseTotal
$path_offset or return 6 0 6
236
237 # read path list
238 6 seek $fh, $start + $path_offset, SEEK_SET;
239 6 ▶ read $fh, my $path_header, 8 or return;
Branch: 1 branch
BranchTrueFalseTotal
read $fh, my $path_header, 8 or return 6 0 6
240 6 my ($path_size, $path_type) = unpack 'V l<', $path_header;
241 6 ▶ $path_type == 0x0601 or return;
Branch: 1 branch
BranchTrueFalseTotal
$path_type == 1537 or return 6 0 6
242 6 ▶ defined read $fh, my $path_chunk, $path_size or return;
Branch: 1 branch
BranchTrueFalseTotal
defined read($fh, my $path_chunk, $path_size) or return 6 0 6
243 6 my $path_count = $path_size / 4;
244 6 my @path_offsets = unpack "V[$path_count]", $path_chunk;
245
246 # read path elements
247 6 my $path = path('/');
248 6 ▶ while ( my $offset = shift @path_offsets ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $offset = shift @path_offsets) 12 6 18
249 12 seek $fh, $start + $offset, SEEK_SET;
250 12 ▶ read $fh, my $chunk_header, 8 or return;
Branch: 1 branch
BranchTrueFalseTotal
read $fh, my $chunk_header, 8 or return 12 0 12
251 12 my ($chunk_size, $chunk_type) = unpack 'V l<', $chunk_header;
252 12 ▶ $chunk_type == 0x0101 or return;
Branch: 1 branch
BranchTrueFalseTotal
$chunk_type == 257 or return 12 0 12
253 12 ▶ read $fh, my $chunk_data, $chunk_size or return;
Branch: 1 branch
BranchTrueFalseTotal
read $fh, my $chunk_data, $chunk_size or return 12 0 12
254 12 utf8::decode $chunk_data;
255 12 $path = $path->child($chunk_data);
256 }
257 6 return $path;
258 }
259  
260  
261 4 our %_osascript;
262 4 my %SCRIPT_SRC = (
263 resolve_alias => <<'EOF',
264 on run argv
265 set thePath to item 1 of argv
266 set theAlias to (POSIX file thePath) as alias
267 tell application "Finder"
268 if kind of theAlias is "Alias" then
269 return POSIX path of ((original item of theAlias) as alias)
270 end if
271 end tell
272 end run
273 EOF
274 create_alias => <<'EOF',
275 on run argv
276 set theTarget to item 1 of argv
277 set theFolder to item 2 of argv
278 set theName to item 3 of argv
279 set theAlias to missing value
280 try
281 tell application "Finder"
282 make alias file to (POSIX file theTarget) at (POSIX file theFolder)
283 set theAlias to the result
284 set name of the result to theName
285 end tell
286 on error errStr number errNum
287 if theAlias is not missing value then
288 -- Undo make alias
289 set theVolume to output volume of (get volume settings)
290 set volume output volume 0 -- Silence UI sound effects
291 tell application "System Events" to delete theAlias
292 set volume output volume theVolume
293 end if
294 error errStr number errNum
295 end try
296 end run
297 EOF
298 );
299  
300  
301 # Compile AppleScript just-in-time into a temp file when needed
302 # (because execution of compiled scripts is slightly faster)
303 11 ▶sub _osascript :prototype($) {
Subroutine _osascript: called CC=5 SCAR=29.3
304 11 my ($scriptname) = @_;
305
306 11 ▶ return unless -x '/usr/bin/osacompile' && -x '/usr/bin/osascript';
Branch: 1 branch
BranchTrueFalseTotal
unless -x "/usr/bin/osacompile" and -x "/usr/bin/osascript" 11 0 11
Condition33%1/3
-x "/usr/bin/osacompile" and -x "/usr/bin/osascript"
!ll&&!rl&&r
1100
MC/DC0%0/2
-x "/usr/bin/osacompile" and -x "/usr/bin/osascript"
-x "/usr/bin/osacompile" -x "/usr/bin/osascript"
Truth table33%1/3
A and B
A= -x "/usr/bin/osacompile"B= -x "/usr/bin/osascript"
ABresult
0X0
100
111
307 0 ▶ $_osascript{_dir} //= Path::Tiny->tempdir('Mac-Alias-XXXXXXXX');
Condition0%0/3
$Mac::Alias::_osascript{"_dir"} //= "Path::Tiny"->tempdir("Mac-Alias-XXXXXXXX")
l!l&&r!l&&!r
000
MC/DC0%0/2
$Mac::Alias::_osascript{"_dir"} //= "Path::Tiny"->tempdir("Mac-Alias-XXXXXXXX")
$Mac::Alias::_osascript{"_dir"} "Path::Tiny"->tempdir("Mac-Alias-XXXXXXXX")
Truth table0%0/3
A //= B
A= $Mac::Alias::_osascript{"_dir"}B= "Path::Tiny"->tempdir("Mac-Alias-XXXXXXXX")
ABresult
1X1
011
000
308 0 my $source = $_osascript{_dir}->child("$scriptname.applescript");
309 0 my $compiled = $_osascript{_dir}->child("$scriptname.scpt");
310 0 $source->spew($SCRIPT_SRC{$scriptname});
311 0 my $out = qx(osacompile -x -o "$compiled" "$source" 2>&1);
312 0 ▶ if ($?) {
Branch: 1 branch
BranchTrueFalseTotal
if ($?) 0 0 0
313 0 chomp $out;
314 0 warn $out;
315 0 return;
316 }
317 0 return $_osascript{$scriptname} = $compiled;
318 }
319  
320  
321 5 ▶sub read_alias_mac :prototype($) {
Subroutine read_alias_mac: called CC=7 SCAR=32.1
Pod documented
322 5 my ($file) = @_;
323
324 5 $file = path($file)->realpath =~ s/(["`\$\\])/\\$1/gr;
325 5 ▶ my $script = $_osascript{resolve_alias} // _osascript 'resolve_alias';
Condition33%1/3
$Mac::Alias::_osascript{"resolve_alias"} // &_osascript("resolve_alias")
l!l&&r!l&&!r
005
MC/DC0%0/2
$Mac::Alias::_osascript{"resolve_alias"} // &_osascript("resolve_alias")
$Mac::Alias::_osascript{"resolve_alias"} &_osascript("resolve_alias")
Truth table33%1/3
A // B
A= $Mac::Alias::_osascript{"resolve_alias"}B= &_osascript("resolve_alias")
ABresult
1X1
011
000
326 5 ▶ if ( ! $script ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($script) 5 0 5
327 5 carp "Failed to read alias using Mac-only function";
328 5 return;
329 }
330
331 0 my $out = qx(osascript -so "$script" "$file");
332 0 chomp $out;
333 0 utf8::decode($out);
334 0 ▶ if ( ! $out || $? ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $out or $?) 0 0 0
Condition0%0/3
not $out or $?
l!l&&r!l&&!r
000
MC/DC0%0/2
not $out or $?
not $out $?
Truth table0%0/3
not(A) or B
A= not $outB= $?
ABresult
1X1
011
000
335 0 ▶ carp $out if $out && $out !~ m/\(-1700\)/; # -1700 = can't find original
Branch: 1 branch
BranchTrueFalseTotal
if $out and not $out =~ /\(-1700\)/u 0 0 0
Condition0%0/3
$out and not $out =~ /\(-1700\)/u
!ll&&!rl&&r
000
MC/DC0%0/2
$out and not $out =~ /\(-1700\)/u
$out not $out =~ /\(-1700\)/u
Truth table0%0/3
A and not(B)
A= $outB= not $out =~ /\(-1700\)/u
ABresult
0X0
100
111
336 0 return;
337 }
338 0 return path($out);
339 }
340  
341  
342 5 ▶sub read_alias :prototype($) {
Subroutine read_alias: called CC=7 SCAR=27.5
Pod documented
343 5 my ($file) = @_;
344
345 5 my $target = read_alias_perl $file;
346 5 ▶ return $target if $target && $target->exists;
Branch: 1 branch
BranchTrueFalseTotal
if $target and $target->exists 1 4 5
Condition100%3/3
$target and $target->exists
!ll&&!rl&&r
221
MC/DC100%2/2
$target and $target->exists
$target $target->exists
Truth table100%3/3
A and B
A= $targetB= $target->exists
ABresult
0X0
100
111
347
348 4 ▶ my $script = $_osascript{resolve_alias} // _osascript 'resolve_alias'
Branch: 1 branch
BranchTrueFalseTotal
my $script = $Mac::Alias::_osascript{"resolve_alias"} // &_osascript("resolve_alias") or return $target 0 4 4
Condition33%1/3
$Mac::Alias::_osascript{"resolve_alias"} // &_osascript("resolve_alias")
l!l&&r!l&&!r
004
MC/DC0%0/2
$Mac::Alias::_osascript{"resolve_alias"} // &_osascript("resolve_alias")
$Mac::Alias::_osascript{"resolve_alias"} &_osascript("resolve_alias")
Truth table33%1/3
A // B
A= $Mac::Alias::_osascript{"resolve_alias"}B= &_osascript("resolve_alias")
ABresult
1X1
011
000
349 or return $target;
350 0 $file = path($file)->realpath =~ s/(["`\$\\])/\\$1/gr;
351
352 0 my $out = qx(osascript -so "$script" "$file");
353 0 chomp $out;
354 0 utf8::decode($out);
355 0 ▶ return path($out) if $out && ! $?;
Branch: 1 branch
BranchTrueFalseTotal
if $out and not $? 0 0 0
Condition0%0/3
$out and not $?
!ll&&!rl&&r
000
MC/DC0%0/2
$out and not $?
$out not $?
Truth table0%0/3
A and not(B)
A= $outB= not $?
ABresult
0X0
100
111
356 0 return $target;
357 }
358  
359  
360 3 ▶sub make_alias :prototype($$) {
Subroutine make_alias: called CC=5 SCAR=22.3
Pod documented
361 3 my ($target, $alias) = @_;
362
363 3 ▶ if ( ! -e $target ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $target) 1 2 3
364 1 carp "Failed to make alias to $target: File not found";
365 1 return;
366 }
367
368 2 ▶ my $script = $_osascript{create_alias} // _osascript 'create_alias';
Condition33%1/3
$Mac::Alias::_osascript{"create_alias"} // &_osascript("create_alias")
l!l&&r!l&&!r
002
MC/DC0%0/2
$Mac::Alias::_osascript{"create_alias"} // &_osascript("create_alias")
$Mac::Alias::_osascript{"create_alias"} &_osascript("create_alias")
Truth table33%1/3
A // B
A= $Mac::Alias::_osascript{"create_alias"}B= &_osascript("create_alias")
ABresult
1X1
011
000
369 2 ▶ if ( ! $script ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($script) 2 0 2
370 2 carp "Failed to make alias using Mac-only function";
371 2 return;
372 }
373 0 $target = path($target)->realpath =~ s/(["`\$\\])/\\$1/gr;
374 0 $alias = path($alias)->realpath;
375 0 my $folder = $alias->parent =~ s/(["`\$\\])/\\$1/gr;
376 0 my $name = $alias->basename =~ s/(["`\$\\])/\\$1/gr;
377
378 0 my $out = qx(osascript -so "$script" "$target" "$folder" "$name");
379 0 ▶ if ($?) {
Branch: 1 branch
BranchTrueFalseTotal
if ($?) 0 0 0
380 0 chomp $out;
381 0 carp $out;
382 0 return;
383 }
384 0 return 1;
385 }
386  
387  
388 4 1;
389  
390 __END__
↑ Summary