File Coverage

blib/lib/App/bif/init.pm
Criterion Covered Total %
statement 36 43 83.7
branch 4 12 33.3
condition 0 3 0.0
subroutine 8 8 100.0
pod 1 2 50.0
total 49 68 72.0


line stmt bran cond sub pod time code
1             package App::bif::init;
2 50     50   101200 use strict;
  50         98  
  50         1953  
3 50     50   233 use warnings;
  50         87  
  50         1719  
4 50     50   716 use Bif::Mo;
  50         81  
  50         354  
5 50     50   1669 use Path::Tiny qw/cwd path/;
  50         12546  
  50         25252  
6              
7             our $VERSION = '0.1.5_5';
8             extends 'App::bif';
9              
10             sub init_user_repo {
11 49     49 0 93 my $self = shift;
12 49         117 my $keep_invalid = shift;
13              
14 49         275 require File::HomeDir;
15 49         359 my $user_repo = path( File::HomeDir->my_home )->child('.bifu');
16 49 100       3947 return if $user_repo->is_dir;
17              
18             $self->new_cmd(
19             'App::bif::new::repo',
20             opts => { config => 1, directory => $user_repo },
21             subref => sub {
22              
23             # This $self is a new_repo with a valid db handle
24 48     48   143 my $self = shift;
25 48         196 my $major_version = shift;
26 48         110 my $minor_version = shift;
27              
28 48         321 $self->dbw->xdo(
29             insert_into => 'bifkv',
30             values => {
31             key => 'keep_invalid',
32             bool_val => $keep_invalid,
33             },
34             );
35              
36 48         18503 $self->new_cmd( 'App::bif::new::identity', opts => { self => 1, } )
37             ->run;
38             },
39 48         1367 )->run;
40             }
41              
42             sub run {
43 49     49 1 91 my $self = shift;
44 49         162 my $opts = $self->opts;
45              
46 49         83 my $dir;
47             my $name;
48 49 50       167 if ( $opts->{directory} ) {
49             $opts->{directory} .= '.bifhub'
50 0 0       0 unless $opts->{directory} =~ m/\.bifhub$/;
51 0         0 $dir = path( $opts->{directory} );
52 0         0 $name = $dir->basename;
53 0         0 $dir = $dir->parent->realpath->child($name);
54             }
55             else {
56 49         215 $dir = cwd->child('.bif');
57             }
58              
59 49 50       3477 return $self->err( 'DirExists', 'directory exists: ' . $dir )
60             if -e $dir;
61              
62 49         1835 $self->init_user_repo( $opts->{keep_invalid} );
63              
64             $self->new_cmd(
65             'App::bif::new::repo',
66             opts => { directory => $dir },
67             subref => sub {
68              
69             # This $self is a new_repo with a valid db handle
70 49     49   191 my $self = shift;
71 49         211 my $major_version = shift;
72 49         239 my $minor_version = shift;
73              
74             $self->dbw->xdo(
75             insert_into => 'bifkv',
76             values => {
77             key => 'keep_invalid',
78             bool_val => $opts->{keep_invalid},
79             },
80 49         506 );
81              
82 49         18518 $self->new_cmd(
83             'App::bif::pull::identity',
84             opts => {
85             location => $self->user_repo,
86             self => 1,
87             },
88             )->run;
89              
90             $self->new_cmd(
91             'App::bif::new::hub',
92             opts => {
93             name => $name,
94             title => $opts->{title} || $name,
95             location => $dir,
96             default => 1,
97             }
98             )->run
99 0 0 0       if $opts->{directory};
100             },
101 49         5208 )->run;
102              
103 0 0         return $self->ok('InitHub') if $opts->{directory};
104 0           return $self->ok('Init');
105             }
106              
107             1;
108             __END__