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 41     41   94265 use strict;
  41         94  
  41         1248  
3 41     41   214 use warnings;
  41         79  
  41         1237  
4 41     41   724 use Bif::Mo;
  41         73  
  41         308  
5 41     41   1349 use Path::Tiny qw/cwd path/;
  41         12727  
  41         23178  
6              
7             our $VERSION = '0.1.5_7';
8             extends 'App::bif';
9              
10             sub init_user_repo {
11 40     40 0 88 my $self = shift;
12 40         114 my $keep_invalid = shift;
13              
14 40         231 require File::HomeDir;
15 40         1021 my $user_repo = path( File::HomeDir->my_home )->child('.bifu');
16 40 100       3374 return if $user_repo->is_dir;
17              
18             $self->dispatch(
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 39     39   190 my $self = shift;
25 39         139 my $major_version = shift;
26 39         117 my $minor_version = shift;
27              
28 39         265 $self->dbw->xdo(
29             insert_into => 'bifkv',
30             values => {
31             key => 'keep_invalid',
32             bool_val => $keep_invalid,
33             },
34             );
35              
36 39         15912 $self->dispatch( 'App::bif::new::identity', opts => { self => 1 } );
37             },
38 39         1174 );
39             }
40              
41             sub run {
42 40     40 1 94 my $self = shift;
43 40         169 my $opts = $self->opts;
44              
45 40         99 my $dir;
46             my $name;
47 40 50       163 if ( $opts->{directory} ) {
48             $opts->{directory} .= '.bifhub'
49 0 0       0 unless $opts->{directory} =~ m/\.bifhub$/;
50 0         0 $dir = path( $opts->{directory} );
51 0         0 $name = $dir->basename;
52 0         0 $dir = $dir->parent->realpath->child($name);
53             }
54             else {
55 40         196 $dir = cwd->child('.bif');
56             }
57              
58 40 50       3011 return $self->err( 'DirExists', 'directory exists: ' . $dir )
59             if -e $dir;
60              
61 40         1526 $self->init_user_repo( $opts->{keep_invalid} );
62              
63             $self->dispatch(
64             'App::bif::new::repo',
65             opts => { directory => $dir },
66             subref => sub {
67              
68             # This $self is a new_repo with a valid db handle
69 40     40   136 my $self = shift;
70 40         162 my $major_version = shift;
71 40         215 my $minor_version = shift;
72              
73             $self->dbw->xdo(
74             insert_into => 'bifkv',
75             values => {
76             key => 'keep_invalid',
77             bool_val => $opts->{keep_invalid},
78             },
79 40         442 );
80              
81 40         15386 $self->dispatch(
82             'App::bif::pull::identity',
83             opts => {
84             location => $self->user_repo,
85             self => 1,
86             },
87             );
88              
89             $self->dispatch(
90             'App::bif::new::hub',
91             opts => {
92             name => $name,
93             title => $opts->{title} || $name,
94             location => $dir,
95             default => 1,
96             }
97 0 0 0       ) if $opts->{directory};
98             },
99 40         3966 );
100              
101 0 0         return $self->ok('InitHub') if $opts->{directory};
102 0           return $self->ok('Init');
103             }
104              
105             1;
106             __END__