Enbld/Home.pm

filter: Statementstmt 100% 73 / 73 Branchbran 100% 18 / 18 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 93.7% 15 / 16 Podpod 0.0% 0 / 3 totaltotal 96.3% 106 / 110 SCAR 24.8
CC
12
Cov
100%
_create_home_directory
5.0
_delete_old_build_directory
4.0
AUTOLOAD
3.0
CRAP 12.0
« Test/Enbld/Definition.pm ↑ Summary Enbld/App/Configuration.pm »
1 package Enbld::Home;
2  
3 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 4 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use File::Path qw/make_path remove_tree/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use autodie;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 ▶use Time::Piece;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 ▶use Time::Seconds;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 4 require Enbld::Feature;
14 4 require Enbld::Error;
15 4 require Enbld::Exception;
16  
17 4 our $dirs = {
18 home => undef,
19 dists => undef,
20 depository => undef,
21 build => undef,
22 conf => undef,
23 log => undef,
24 etc => undef,
25 extlib => undef,
26 library => undef,
27 deploy_path => undef,
28 };
29  
30 sub initialize {
31 38 ▶ my $pkg = shift;
Subroutine initialize: called CC=2 SCAR=6.9
Pod undocumented
32  
33 38 $pkg->_create_home_directory;
34 36 ▶ $pkg->_set_deploy_directory if Enbld::Feature->is_deploy_mode;
Branch: 1 branch
BranchTrueFalseTotal
if "Enbld::Feature"->is_deploy_mode 4 32 36
35 36 $pkg->_delete_old_build_directory;
36  
37 36 return $dirs->{home};
38 }
39  
40 sub AUTOLOAD {
41 666 ▶ my $method = our $AUTOLOAD;
Subroutine AUTOLOAD: called CC=3 SCAR=11.0
42 666 $method =~ s/.*:://;
43  
44 666 ▶ unless ( exists $dirs->{$method} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $Enbld::Home::dirs->{$method}) 1 665 666
45 1 my $err = "Can't execute Enbld::Home's method.";
46 1 croak( Enbld::Exception->new( $err, $method ));
47 }
48  
49 665 ▶ unless ( $dirs->{$method} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Enbld::Home::dirs->{$method}) 1 664 665
50 1 my $err = "Not initialized Enbld home's path yet.";
51 1 croak( Enbld::Exception->new( $err ));
52 }
53  
54 664 return $dirs->{$method};
55 }
56  
57 sub create_build_directory {
58  
59 make_path( $dirs->{build} = File::Spec->catdir(
60 29 ▶ $dirs->{home}, 'build', time
Subroutine create_build_directory: called CC=1 SCAR=0.0
Pod undocumented
61 ));
62  
63 29 return $dirs->{build};
64 }
65  
66 sub install_path {
67  
68 48 ▶ return Enbld::Home->deploy_path if Enbld::Feature->is_deploy_mode;
Subroutine install_path: called CC=2 SCAR=6.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
if "Enbld::Feature"->is_deploy_mode 3 45 48
69 45 return Enbld::Home->home;
70  
71 }
72  
73 sub _create_home_directory {
74 38 ▶ my $pkg = shift;
Subroutine _create_home_directory: called CC=5 SCAR=16.1
75  
76 $dirs->{home} = $ENV{PERL_ENBLD_HOME} ? $ENV{PERL_ENBLD_HOME} :
77 38 ▶ File::Spec->catdir( $ENV{HOME}, '.enbld' );
Branch: 1 branch
BranchTrueFalseTotal
$ENV{'PERL_ENBLD_HOME'} ? : 35 3 38
78  
79 38 my $error;
80 38 make_path( $dirs->{home}, { error => \$error } );
81  
82 38 ▶ if ( @{ $error } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$error;}) 1 37 38
83 1 die( Enbld::Error->new(
84 "Can't create Enbld's home directory:$dirs->{home}\n" .
85 "Please check write permission for $dirs->{home}",
86 ));
87 }
88  
89 37 ▶ if ( ! -w $dirs->{home} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-w $Enbld::Home::dirs->{"home"}) 1 36 37
90 1 die( Enbld::Error->new(
91 "No permission to write directory:$dirs->{home}" .
92 "Please check write permission for $dirs->{home}"
93 ));
94 }
95  
96 36 make_path( $dirs->{$_} = File::Spec->catdir( $dirs->{home}, $_ )) for
97 qw/dists build depository conf etc log extlib/;
98  
99 36 $dirs->{library} = $dirs->{home};
100  
101 36 return $dirs->{home};
102 }
103  
104 sub _set_deploy_directory {
105  
106 4 ▶ my $deploy_path = Enbld::Feature->deploy_path;
Subroutine _set_deploy_directory: called CC=1 SCAR=0.0
107  
108 4 $dirs->{deploy_path} = $deploy_path;
109 4 $dirs->{library} = $deploy_path;
110  
111 4 return $dirs->{deploy_path};
112 }
113  
114 sub _delete_old_build_directory {
115  
116 36 ▶ opendir my $dh, $dirs->{build};
Subroutine _delete_old_build_directory: called CC=4 SCAR=13.9
117 36 my @list = grep { !/^\.{1,2}$/ } readdir $dh;
118 36 closedir $dh;
119  
120 36 my $limit = localtime;
121 36 $limit -= ONE_MONTH;
122  
123 36 foreach my $build_dir ( @list ) {
124 3 ▶ next if ( $build_dir !~ /\d{10}/ ); # for skip .DS_Store
Branch: 1 branch
BranchTrueFalseTotal
unless $build_dir =~ /\d{10}/ 1 2 3
125  
126 2 ▶ if ( $limit->epoch > $build_dir ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($limit->epoch > $build_dir) 1 1 2
127 1 remove_tree( File::Spec->catdir( $dirs->{build}, $build_dir ) );
128 }
129 }
130 }
131  
132 ▶sub DESTROY {
Subroutine DESTROY: not called CC=1 SCAR=0.0
133 # do nothing.
134 }
135  
136 4 1;
« Test/Enbld/Definition.pm ↑ Summary Enbld/App/Configuration.pm »