lib/HTML/FormFu/Deploy.pm

filter: Statementstmt 45.1% 37 / 82 Branchbran 7.6% 2 / 26 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 71.4% 10 / 14 Podpod 0.0% 0 / 3 totaltotal 38.4% 50 / 130 CC 13 SCAR 30.8
CC
13
Cov
36%
deploy
56.0
__ANON__
20.0
file_source
20.0
CRAP 21.7
« lib/HTML/FormFu/Constraint/DependOn.pm ↑ Summary lib/HTML/FormFu/Role/Constraint/Others.pm »
1 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2  
3 package HTML::FormFu::Deploy;
4 # ABSTRACT: deploy project
5 1 $HTML::FormFu::Deploy::VERSION = '2.09';
6 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use HTML::FormFu::Constants qw( $EMPTY_STR );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Cwd qw( getcwd );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Fatal qw( open binmode close mkdir );
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use File::Copy qw( move );
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use File::Find qw( find );
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use File::ShareDir qw( dist_file );
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 1 our $SHARE_DIR;
18  
19 1 ▶if ( -f 'MANIFEST.SKIP' && -d 'share/templates/tt/xhtml' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f 'MANIFEST.SKIP' and -d 'share/templates/tt/xhtml') { } 1 0 1
Condition33%1/3
-f "MANIFEST.SKIP" and -d "share/templates/tt/xhtml"
!ll&&!rl&&r
001
MC/DC0%0/2
-f "MANIFEST.SKIP" and -d "share/templates/tt/xhtml"
-f "MANIFEST.SKIP" -d "share/templates/tt/xhtml"
Truth table33%1/3
A and B
A= -f "MANIFEST.SKIP"B= -d "share/templates/tt/xhtml"
ABresult
0X0
100
111
20 warn "Running as a developer, using the local, not installed templates\n\n"
21 1 ▶ unless ( $ENV{HARNESS_ACTIVE} );
Branch: 1 branch
BranchTrueFalseTotal
unless $ENV{"HARNESS_ACTIVE"} 0 1 1
22  
23 1 my $cwd = getcwd();
24  
25 1 $SHARE_DIR = File::Spec->catfile( $cwd, 'share/templates/tt/xhtml' );
26 }
27 else {
28  
29 # dist_dir() doesn't reliably return the directory our files are in.
30 # find the path of one of our files, then get the directory from that
31  
32 0 my $path = dist_file( 'HTML-FormFu', 'templates/tt/xhtml/form' );
33  
34 0 my ( $volume, $dirs, $file ) = File::Spec->splitpath($path);
35  
36 0 $SHARE_DIR = File::Spec->catpath( $volume, $dirs, '' );
37 }
38  
39 0 ▶sub file_list {
Subroutine file_list: not called CC=1 SCAR=6.9
Pod undocumented
40 0 my @dir;
41  
42 0 ▶ my $wanted = sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
43 0 ▶ return if /^\./; # skip files beginning with "."
Branch: 1 branch
BranchTrueFalseTotal
if /^\./ 0 0 0
44 0 ▶ return if !-f $File::Find::name; # skip non-files
Branch: 1 branch
BranchTrueFalseTotal
unless -f $File::Find::name 0 0 0
45  
46 # necessary when using dev files
47 0 ▶ return if $File::Find::name =~ m|/\.svn|;
Branch: 1 branch
BranchTrueFalseTotal
if $File::Find::name =~ m[/\.svn] 0 0 0
48  
49 0 push @dir, $_;
50 0 };
51  
52 0 find( $wanted, $SHARE_DIR );
53  
54 0 return @dir;
55 }
56  
57 0 ▶sub file_source {
Subroutine file_source: not called CC=4 SCAR=30.0
Pod undocumented
58 0 ▶ my $filename = shift
Branch: 1 branch
BranchTrueFalseTotal
my $filename = shift() or croak("filename argument required") 0 0 0
59 or croak "filename argument required";
60  
61 0 my $path = File::Spec->catfile( $SHARE_DIR, $filename );
62  
63 0 ▶ croak "unknown filename: '$path'" if !-f $path;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $path 0 0 0
64  
65 0 open my $fh, '<', $path;
66  
67 0 my $data = do { local $/; <$fh> };
68  
69 0 ▶ $data = $EMPTY_STR if !defined $data;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $data 0 0 0
70  
71 0 close $fh;
72  
73 0 return $data;
74 }
75  
76 0 ▶sub deploy {
Subroutine deploy: not called CC=7 SCAR=40.3
Pod undocumented
77 0 my ($dir) = @_;
78  
79 0 ▶ croak "directory argument required" if !defined $dir;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $dir 0 0 0
80  
81 0 ▶ if ( !-d $dir ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $dir) 0 0 0
82 0 warn "creating directory '$dir'\n";
83 0 mkdir $dir;
84 }
85  
86 0 for my $filename ( file_list() ) {
87 0 my $path = File::Spec->catfile( $dir, $filename );
88  
89 0 ▶ if ( -f $path ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $path) 0 0 0
90 0 my $bck = $path . ".bck";
91 0 warn "file '$path' already exists, backing up to $bck\n";
92 0 my $ok = move( $path, $bck );
93 0 ▶ if ( !$ok ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 0 0 0
94 0 warn "failed to backup, skipping file\n$@\n";
95 0 next;
96 }
97 }
98  
99 0 my $fh;
100 0 eval { open $fh, '>', $path };
101 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
102 0 warn "failed to open '$path' for writing, skipping file\n$@\n";
103 0 next;
104 }
105 0 binmode $fh;
106 0 print $fh file_source($filename);
107 0 close $fh;
108 }
109 0 return;
110 }
111  
112 1 1;
113  
114 __END__
« lib/HTML/FormFu/Constraint/DependOn.pm ↑ Summary lib/HTML/FormFu/Role/Constraint/Others.pm »