Readlink/Perl58.pm untested

filter: Statementstmt 0.0% 0 / 37 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 79 CC 11 SCAR 44.6
CC
11
Cov
0%
readlink
132.0
BEGIN
2.0
BEGIN
2.0
CRAP 86.1
1 package
2 Win32::Shortcut::Readlink;
3  
4 use strict;
5 use warnings;
6 use Carp qw( carp croak );
7 use constant _is_cygwin => $^O eq 'cygwin';
8 use constant _is_mswin32 => $^O eq 'MSWin32';
9 use constant _is_windows => _is_cygwin || _is_mswin32;
10  
11 sub readlink (;$)
12 {
13 unless(_is_windows)
14 {
15 if(@_ > 0)
16 { return CORE::readlink($_[0]) }
17 else
18 # If you need this feature, then please either upgrade to 5.10 or downgrade to 5.6
19 { croak "implicit \$_ and Win32::Shortcut::Readlink are not interoperable on Perl 5.8.x" }
20 }
21  
22 my $arg = @_ > 0 ? $_[0] : $_;
23
24 if(defined $arg && $arg =~ /\.lnk$/ && -r $arg)
25 {
26 my $target = _win32_resolve(_is_cygwin ? Cygwin::posix_to_win_path($arg) : $arg);
27 return $target if defined $target;
28 }
29  
30 if(_is_cygwin)
31 {
32 if(@_ > 0)
33 { return CORE::readlink($_[0]) }
34 else
35 # If you need this feature, then please either upgrade to 5.10 or downgrade to 5.6
36 { croak "implicit \$_ and Win32::Shortcut::Readlink are not interoperable on Perl 5.8.x" }
37 }
38  
39 # else is MSWin32
40 # emulate unix failues
41 if(!defined $arg)
42 {
43 # TODO: only warn if warnings on in caller
44 carp "Use of uninitialized value in readlink";
45 $! = 22;
46 }
47 elsif(-e $arg)
48 {
49 $! = 22; # Invalid argument
50 }
51 else
52 {
53 $! = 2; # No such file or directory
54 }
55
56 return;
57 }
58  
59 1;
60  
61 __END__