File Coverage

blib/lib/App/datasection/Command/insert.pm
Criterion Covered Total %
statement 47 49 95.9
branch 7 12 58.3
condition n/a
subroutine 10 10 100.0
pod 1 1 100.0
total 65 72 90.2


line stmt bran cond sub pod time code
1 1     1   867 use warnings;
  1         2  
  1         59  
2 1     1   16 use 5.020;
  1         4  
3 1     1   5 use experimental qw( signatures );
  1         2  
  1         5  
4 1     1   142 use stable qw( postderef );
  1         3  
  1         6  
5 1     1   107 use true;
  1         2  
  1         7  
6              
7             package App::datasection::Command::insert 0.01 {
8              
9             # ABSTRACT: Insert files from the file system into Perl source __DATA__ section
10             # VERSION
11              
12 1     1   2218 use App::datasection -command;
  1         3  
  1         8  
13 1     1   365 use Data::Section::Writer 0.04;
  1         17  
  1         44  
14 1     1   6 use Path::Tiny qw( path );
  1         2  
  1         655  
15              
16 1     1 1 11 sub execute ($self, $opt, $args) {
  1         3  
  1         3  
  1         3  
  1         3  
17              
18 1         4 my @files = map { path($_) } @$args;
  1         5  
19              
20 1         56 my $dir;
21 1 50       10 if($opt->{dir}) {
22 0         0 $dir = path($opt->{dir})->absolute;
23             }
24              
25 1         3 foreach my $file (@files) {
26 1 50       8 my $dir = $dir ? $dir : $file->sibling($file->basename . '.data');
27              
28 1 50       154 if(-d $dir) {
29 1         42 my $dsw = Data::Section::Writer
30             ->new(perl_filename => $file);
31              
32 3     3   1308 $dir->visit(sub ($path, $state) {
  3         7  
  3         6  
  3         6  
33 3 100       14 return if $path->is_dir;
34 2 50       41 if(-B $path) {
35 0         0 $dsw->add_file($path->relative($dir), $path->slurp_raw, 'base64');
36             } else {
37 2         132 $dsw->add_file($path->relative($dir), $path->slurp_utf8);
38             }
39 1         332 }, { recurse => 1 });
40              
41 1         630 $dsw->update_file;
42 1 50       2715 unless($dsw->unchanged) {
43 1         55 say $file;
44             }
45             }
46             }
47             }
48              
49             }
50              
51             __END__