File Coverage

blib/lib/Directory/Deploy/Maker.pm
Criterion Covered Total %
statement 27 29 93.1
branch 9 16 56.2
condition 0 6 0.0
subroutine 5 5 100.0
pod 0 1 0.0
total 41 57 71.9


line stmt bran cond sub pod time code
1             package Directory::Deploy::Maker;
2              
3 4     4   25 use Moose;
  4         10  
  4         35  
4              
5 4     4   30883 use Directory::Deploy::Carp;
  4         12  
  4         51  
6              
7             has deploy => qw/is ro required 1/;
8              
9             sub make {
10 4     4 0 6 my $self = shift;
11 4         5 my $entry = shift;
12              
13 4 100       153 if ($entry->is_file) {
14 2         9 $self->_make_file( $entry );
15             }
16             else {
17 2         7 $self->_make_dir( $entry );
18             }
19             }
20              
21             sub _make_file {
22 2     2   4 my $self = shift;
23 2         3 my $entry = shift;
24              
25 2         78 my $file = $self->deploy->file( $entry->path );
26 2         435 my $content = $entry->content;
27              
28 2 100       9 $file->parent->mkpath unless -d $file->parent;
29 2 50       292 my $file_handle = $file->openw or croak "Couldn't open write file handle for ($file) since: $!";
30              
31 2 50       562 if (! defined $content) {
    50          
    0          
32             }
33             elsif ( ref $content eq 'SCALAR' ) {
34 2         14 $file_handle->print( $$content );
35             }
36             elsif ( ! ref $content ) { # && $content =~ m/\n/ ) {
37 0         0 $file_handle->print( $content );
38             }
39             else {
40 0         0 croak "Don't know how to make $content";
41             }
42              
43 2         38 my $mode;
44 2 50 0     92 chmod $mode, "$file" or carp "Unable to set mode ($mode) on file ($file)" if $mode = $entry->mode;
45             }
46              
47             sub _make_dir {
48 2     2   3 my $self = shift;
49 2         1 my $entry = shift;
50              
51 2         61 my $dir = $self->deploy->dir( $entry->path );
52              
53 2         120 $dir->mkpath;
54              
55 2         408 my $mode;
56 2 50 0     86 chmod $mode, "$dir" or carp "Unable to set mode ($mode) on dir ($dir)" if $mode = $entry->mode;
57             }
58              
59             1;