File Coverage

blib/lib/Test/Smoke/Syncer/Hardlink.pm
Criterion Covered Total %
statement 27 28 96.4
branch 11 16 68.7
condition 1 3 33.3
subroutine 5 5 100.0
pod 1 1 100.0
total 45 53 84.9


line stmt bran cond sub pod time code
1             package Test::Smoke::Syncer::Hardlink;
2 11     11   147 use warnings;
  11         36  
  11         456  
3 11     11   77 use strict;
  11         23  
  11         444  
4              
5             our $VERSION = '0.029';
6              
7 11     11   88 use base 'Test::Smoke::Syncer::Base';
  11         34  
  11         5613  
8              
9             =head1 Test::Smoke::Syncer::Hardlink
10              
11             This handles syncing by copying the source-tree from a local directory
12             using the B function. This can be used as an alternative for
13             B.
14              
15             Thanks to Nicholas Clark for donating this suggestion!
16              
17             =cut
18              
19             require File::Find;
20              
21             =head2 Test::Smoke::Syncer::Hardlink->new( %args )
22              
23             Keys for C<%args>:
24              
25             * ddir: destination directory
26             * hdir: source directory
27             * v: verbose
28              
29             =cut
30              
31             =head2 $syncer->sync( )
32              
33             C uses the B module to make the hardlink forest in {ddir}.
34              
35             =cut
36              
37             sub sync {
38 5     5 1 7604 my $self = shift;
39              
40 5         106 $self->pre_sync;
41 5 100       1159 require File::Copy unless $self->{haslink};
42              
43 5 100       4135 -d $self->{ddir} or File::Path::mkpath( $self->{ddir} );
44              
45 5         52 my $source_dir = File::Spec->canonpath( $self->{hdir} );
46              
47             File::Find::find( sub {
48 40     40   3095 my $dest = File::Spec->abs2rel( $File::Find::name, $source_dir );
49             # nasty thing in older File::Spec::Win32::abs2rel()
50 40 50       196 $^O eq 'MSWin32' and $dest =~ s|^[a-z]:(?![/\\])||i;
51 40         368 $dest = File::Spec->catfile( $self->{ddir}, $dest );
52 40 100       699 if ( -d ) {
53 10         1387 mkdir $dest, (stat _)[2] & 07777;
54             } else {
55 30   33     1005 -e $dest and 1 while unlink $dest;
56 30 50       123 $self->{v} > 1 and print "link $_ $dest";
57             my $ok = $self->{haslink}
58 30 100       644 ? link $_, $dest
59             : File::Copy::copy( $_, $dest );
60 30 50       2422 if ( $self->{v} > 1 ) {
61 0 0       0 print $ok ? " OK\n" : " $!\n";
62             }
63             }
64 5         681 }, $source_dir );
65              
66 5         119 $self->clean_from_directory( $source_dir );
67              
68 5         116 $self->post_sync;
69 5         43 return $self->check_dot_patch();
70             }
71              
72             1;
73              
74             =head1 COPYRIGHT
75              
76             (c) 2002-2013, All rights reserved.
77              
78             * Abe Timmerman
79              
80             This library is free software; you can redistribute it and/or modify
81             it under the same terms as Perl itself.
82              
83             See:
84              
85             * ,
86             *
87              
88             This program is distributed in the hope that it will be useful,
89             but WITHOUT ANY WARRANTY; without even the implied warranty of
90             MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
91              
92             =cut