File Coverage

blib/lib/File/Copy/Link.pm
Criterion Covered Total %
statement 28 28 100.0
branch 11 20 55.0
condition n/a
subroutine 6 6 100.0
pod 2 2 100.0
total 47 56 83.9


line stmt bran cond sub pod time code
1             package File::Copy::Link;
2            
3 5     5   678071 use strict;
  5         8  
  5         194  
4 5     5   44 use warnings;
  5         8  
  5         282  
5            
6 5     5   28 use Carp;
  5         12  
  5         353  
7 5     5   2763 use File::Copy ();
  5         25995  
  5         2078  
8            
9             require Exporter;
10             push our @ISA, qw(Exporter);
11            
12             our @EXPORT_OK = qw(copylink safecopylink);
13             our $VERSION = '0.200';
14            
15             sub copylink {
16 2 100   2 1 265568 local $_ = @_ ? shift : $_; # default to $_
17 2 50       46 croak "$_ not a link\n" unless -l;
18 2 50       84 open my $fh, '<', $_ or croak "Can't open link $_: $!\n";
19 2 50       239 unlink or croak "Can't unlink link $_: $!\n";
20 2         21 my $ok = File::Copy::copy $fh, $_;
21 2 50       878 croak "copy($fh $_) failed: $!\n" unless $ok;
22 2         32 return $ok;
23             }
24            
25             sub safecopylink {
26 1 50   1 1 156684 local $_ = @_ ? shift : $_; # default to $_
27 1 50       19 croak "$_ not a link\n" unless -l;
28 1         747 require File::Spec::Link;
29 1         8 my $orig = File::Spec::Link->linked($_);
30 1 50       6 croak "$_ link problem\n" unless defined $orig;
31 1 50       94 unlink or croak "Can't unlink link $_: $!\n";
32 1         7 my $ok = File::Copy::copy $orig, $_;
33 1 50       369 croak "copy($orig $_) failed: $!\n" unless $ok;
34 1         7 return $ok;
35             }
36            
37             1;
38             __END__