File Coverage

lib/Rex/Hook/File/Impostor.pm
Criterion Covered Total %
statement 31 33 93.9
branch 1 2 50.0
condition n/a
subroutine 10 10 100.0
pod 0 3 0.0
total 42 48 87.5


line stmt bran cond sub pod time code
1             package Rex::Hook::File::Impostor;
2              
3             # ABSTRACT: execute Rex file management commands on a copy of the original file
4              
5 1     1   151808 use 5.012;
  1         3  
6 1     1   5 use strict;
  1         2  
  1         17  
7 1     1   5 use warnings;
  1         2  
  1         36  
8              
9             our $VERSION = 'v0.1.1';
10              
11 1     1   5 use File::Basename;
  1         3  
  1         79  
12 1     1   7 use File::Spec;
  1         2  
  1         7  
13 1     1   39 use Rex 1.012 -base;
  1         19  
  1         9  
14 1     1   279965 use Rex::Hook;
  1         3  
  1         292  
15              
16             register_function_hooks { before => { file => \©_file, }, };
17              
18             sub copy_file {
19 1     1 0 36543 my ( $original_file, @opts ) = @_;
20              
21 1         22 my $impostor_file = get_impostor_for($original_file);
22              
23 1         19 Rex::Logger::debug("Copying $original_file to $impostor_file");
24              
25 1 50       28 if ( is_windows() ) {
26 0         0 my $exec = Rex::Interface::Exec->create;
27 0         0 $exec->exec("copy /v /y $original_file $impostor_file");
28             }
29             else {
30 1         130321 cp $original_file, $impostor_file;
31             }
32              
33 1         22865 return $impostor_file, @opts;
34             }
35              
36             sub get_impostor_for {
37 2     2 0 12376 my $file = shift;
38              
39 2         17 return File::Spec->catfile( get_impostor_dir(), basename($file) );
40             }
41              
42             sub get_impostor_dir {
43 3     3 0 105 my $tmp_dir =
44             File::Spec->catfile( Rex::Config->get_tmp_dir(), 'rex_hook_file_impostor' );
45              
46 3         3918 mkdir $tmp_dir;
47 3         113930 return $tmp_dir;
48             }
49              
50             1;
51              
52             __END__