blib/lib/Pinto/Initializer.pm

filter: Statementstmt 100% 74 / 74 Branchbran 60.0% 6 / 10 Conditioncond 60.0% 3 / 5 MC/DCmcdc 33.3% 1 / 3 Subroutinesub 100% 16 / 16 Podpod 0.0% 0 / 1 totaltotal 91.7% 100 / 109 CC 9 SCAR 6.8
CC
9
Cov
93%
_check_sanity
3.3
_write_mailrc
3.1
_create_stack
3.0
CRAP 2.0
« blib/lib/Pinto/Difference.pm ↑ Summary blib/lib/Pinto/Result.pm »
1 # ABSTRACT: Initializes a new Pinto repository
2  
3 package Pinto::Initializer;
4  
5 52 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 52 ▶use MooseX::StrictConstructor;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 52 ▶use MooseX::MarkAsMethods ( autoclean => 1 );
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 52 ▶use IO::Zlib;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 52 ▶use Path::Class;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 52 ▶use Pinto;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 52 ▶use Pinto::Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 52 ▶use Pinto::Util qw(debug);
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 #------------------------------------------------------------------------------
17  
18 52 our $VERSION = '0.14'; # VERSION
19  
20 #------------------------------------------------------------------------------
21  
22 70 ▶sub init {
Subroutine init: called CC=2 SCAR=6.9
Pod undocumented
23 70 my ( $self, %args ) = @_;
24  
25 die "Must specify a root\n"
26 70 ▶ if not $args{root};
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"root"} 0 70 70
27  
28 # Normalize root
29 70 $args{root} =~ s{^file://}{};
30  
31 70 $self->_check_sanity(%args);
32 70 $self->_make_dirs(%args);
33 70 $self->_write_config(%args);
34 70 $self->_write_mailrc(%args);
35 70 $self->_set_version(%args);
36 70 $self->_create_db(%args);
37 70 $self->_create_stack(%args);
38  
39 70 return $self;
40 }
41  
42 #------------------------------------------------------------------------------
43  
44 70 ▶sub _check_sanity {
Subroutine _check_sanity: called CC=3 SCAR=12.0
45 70 my ( $self, %args ) = @_;
46  
47 70 my $root_dir = dir( $args{root} );
48 70 ▶ die "Directory $root_dir must be empty to create a repository there\n"
Branch: 1 branch
BranchTrueFalseTotal
if -e $root_dir and $root_dir->children 0 70 70
Condition33%1/3
-e $root_dir and $root_dir->children
!ll&&!rl&&r
0700
MC/DC0%0/2
-e $root_dir and $root_dir->children
-e $root_dir $root_dir->children
Truth table33%1/3
A and B
A= -e $root_dirB= $root_dir->children
ABresult
0X0
100
111
49 if -e $root_dir and $root_dir->children;
50  
51 70 return;
52 }
53  
54 #------------------------------------------------------------------------------
55  
56 70 ▶sub _make_dirs {
Subroutine _make_dirs: called CC=2 SCAR=6.9
57 70 my ( $self, %args ) = @_;
58  
59 70 my $config = Pinto::Config->new( root => $args{root} );
60  
61 70 for my $dir ( $config->directories ) {
62 420 debug "Making directory $dir";
63 420 $dir->mkpath;
64 }
65  
66 70 return;
67 }
68  
69 #------------------------------------------------------------------------------
70  
71 70 ▶sub _write_config {
Subroutine _write_config: called CC=1 SCAR=0.0
72 70 my ( $self, %args ) = @_;
73  
74 70 my $config = Pinto::Config->new( root => $args{root} );
75  
76 70 my $config_file = $config->config_dir->file( $config->basename );
77 70 $config->write_config_file( file => $config_file, values => \%args );
78  
79 70 return;
80 }
81  
82 #------------------------------------------------------------------------------
83  
84 70 ▶sub _write_mailrc {
Subroutine _write_mailrc: called CC=3 SCAR=11.2
85 70 my ( $self, %args ) = @_;
86  
87 70 my $config = Pinto::Config->new( root => $args{root} );
88  
89 70 ▶ my $fh = IO::Zlib->new( $config->mailrc_file->stringify, 'wb' ) or die $!;
Branch: 1 branch
BranchTrueFalseTotal
my $fh = "IO::Zlib"->new($config->mailrc_file->stringify, "wb") or die $! 70 0 70
90 70 print {$fh} ''; # File will be empty, but have gzip headers
91 70 ▶ close $fh or throw $!;
Branch: 1 branch
BranchTrueFalseTotal
close $fh or $!->throw 70 0 70
92  
93 70 return;
94 }
95  
96 #------------------------------------------------------------------------------
97  
98 70 ▶sub _set_version {
Subroutine _set_version: called CC=1 SCAR=0.0
99 70 my ( $self, %args ) = @_;
100  
101 70 my $pinto = Pinto->new( root => $args{root} );
102  
103 70 $pinto->repo->set_version;
104  
105 70 return;
106 }
107  
108 #------------------------------------------------------------------------------
109  
110 70 ▶sub _create_db {
Subroutine _create_db: called CC=1 SCAR=0.0
111 70 my ( $self, %args ) = @_;
112  
113 70 my $pinto = Pinto->new( root => $args{root} );
114  
115 70 $pinto->repo->db->deploy;
116  
117 70 return;
118 }
119  
120 #------------------------------------------------------------------------------
121  
122 70 ▶sub _create_stack {
Subroutine _create_stack: called CC=3 SCAR=11.0
123 70 my ( $self, %args ) = @_;
124  
125 70 ▶ my $stack = $args{stack} || 'master';
Condition100%2/2
$args{'stack'} || 'master'
l!l
169
MC/DC100%1/1
$args{'stack'} || 'master'
$args{'stack'}
Truth table100%2/2
A
A= $args{'stack'}
Aresult
11
00
126 70 ▶ my $is_default = $args{no_default} ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$args{'no_default'} ? : 2 68 70
127 70 my $pinto = Pinto->new( root => $args{root} );
128  
129 70 $pinto->run( New => ( stack => $stack, default => $is_default ) );
130  
131 70 return;
132 }
133  
134 #------------------------------------------------------------------------------
135  
136 52 __PACKAGE__->meta->make_immutable;
137  
138 #------------------------------------------------------------------------------
139  
140 52 1;
141  
142 __END__
« blib/lib/Pinto/Difference.pm ↑ Summary blib/lib/Pinto/Result.pm »