line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Module::New::Config; |
2
|
|
|
|
|
|
|
|
3
|
7
|
|
|
7
|
|
17568
|
use strict; |
|
7
|
|
|
|
|
12
|
|
|
7
|
|
|
|
|
233
|
|
4
|
7
|
|
|
7
|
|
62
|
use warnings; |
|
7
|
|
|
|
|
8
|
|
|
7
|
|
|
|
|
142
|
|
5
|
7
|
|
|
7
|
|
24
|
use Carp; |
|
7
|
|
|
|
|
8
|
|
|
7
|
|
|
|
|
465
|
|
6
|
7
|
|
|
7
|
|
3695
|
use File::HomeDir; |
|
7
|
|
|
|
|
32560
|
|
|
7
|
|
|
|
|
399
|
|
7
|
7
|
|
|
7
|
|
5389
|
use Getopt::Long (); |
|
7
|
|
|
|
|
68062
|
|
|
7
|
|
|
|
|
179
|
|
8
|
7
|
|
|
7
|
|
2976
|
use Path::Tiny (); |
|
7
|
|
|
|
|
42779
|
|
|
7
|
|
|
|
|
152
|
|
9
|
7
|
|
|
7
|
|
4002
|
use YAML::Tiny; |
|
7
|
|
|
|
|
33785
|
|
|
7
|
|
|
|
|
4274
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub new { |
12
|
20
|
|
|
20
|
1
|
7841
|
my ($class, %options) = @_; |
13
|
|
|
|
|
|
|
|
14
|
20
|
|
|
|
|
193
|
my $parser = Getopt::Long::Parser->new( |
15
|
|
|
|
|
|
|
config => [qw( bundling ignore_case pass_through )] |
16
|
|
|
|
|
|
|
); |
17
|
|
|
|
|
|
|
|
18
|
20
|
|
|
|
|
1846
|
my $self = bless { parser => $parser, %options }, $class; |
19
|
|
|
|
|
|
|
|
20
|
20
|
|
|
|
|
87
|
$self->load; |
21
|
20
|
|
|
|
|
10013
|
$self; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
5
|
|
|
5
|
1
|
31
|
sub file { shift->{file} } |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub get { |
27
|
306
|
|
|
306
|
1
|
931
|
my ($self, $key) = @_; |
28
|
306
|
100
|
|
|
|
721
|
return $self->{option}->{$key} if exists $self->{option}->{$key}; |
29
|
301
|
100
|
|
|
|
1805
|
return $self->{config}->{$key} if exists $self->{config}->{$key}; |
30
|
216
|
|
|
|
|
897
|
return; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub set { |
34
|
23
|
|
|
23
|
1
|
29
|
my $self = shift; |
35
|
|
|
|
|
|
|
|
36
|
23
|
50
|
33
|
|
|
126
|
if ( @_ and @_ % 2 == 0 ) { |
37
|
23
|
50
|
|
|
|
28
|
$self->{config} = { %{ $self->{config} || {} }, @_ }; |
|
23
|
|
|
|
|
169
|
|
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub save { |
42
|
3
|
|
|
3
|
1
|
4
|
my $self = shift; |
43
|
|
|
|
|
|
|
|
44
|
3
|
100
|
|
|
|
17
|
$self->set(@_) if @_; |
45
|
|
|
|
|
|
|
|
46
|
3
|
|
33
|
|
|
16
|
$self->{file} ||= $self->_default_file; |
47
|
|
|
|
|
|
|
|
48
|
3
|
|
|
|
|
11
|
YAML::Tiny::DumpFile( $self->{file}, $self->{config} ); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub load { |
52
|
22
|
|
|
22
|
1
|
36
|
my $self = shift; |
53
|
|
|
|
|
|
|
|
54
|
22
|
100
|
|
|
|
88
|
if ( $self->{file} ) { |
55
|
7
|
100
|
|
|
|
16
|
return if $self->_load_and_merge( $self->{file} ); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
else { |
58
|
15
|
|
|
|
|
61
|
foreach my $file ( $self->_search ) { |
59
|
15
|
100
|
|
|
|
130
|
return if $self->_load_and_merge( $file ); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
} |
62
|
14
|
|
|
|
|
134
|
$self->_first_time; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub _load_and_merge { |
66
|
22
|
|
|
22
|
|
33
|
my ($self, $file) = @_; |
67
|
|
|
|
|
|
|
|
68
|
22
|
100
|
66
|
|
|
283
|
return unless $file && -f $file; |
69
|
|
|
|
|
|
|
|
70
|
8
|
|
|
|
|
118
|
my $config; |
71
|
8
|
|
|
|
|
10
|
eval { $config = YAML::Tiny::LoadFile( $file ) }; |
|
8
|
|
|
|
|
26
|
|
72
|
8
|
50
|
|
|
|
5151
|
return if $@; |
73
|
|
|
|
|
|
|
|
74
|
8
|
|
|
|
|
12
|
foreach my $key ( keys %{ $config } ) { |
|
8
|
|
|
|
|
28
|
|
75
|
16
|
|
|
|
|
41
|
$self->{config}->{$key} = $config->{$key}; |
76
|
|
|
|
|
|
|
} |
77
|
8
|
|
|
|
|
15
|
$self->{file} = $file; |
78
|
8
|
|
|
|
|
32
|
return 1; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub get_options { |
82
|
18
|
|
|
18
|
1
|
510
|
my ($self, @specs) = @_; |
83
|
18
|
|
|
|
|
34
|
my $config = {}; |
84
|
18
|
|
|
|
|
99
|
$self->{parser}->getoptions($config, @specs); |
85
|
18
|
100
|
|
|
|
7078
|
$self->{option} = { %{ $self->{option} || {} }, %{ $config } }; |
|
18
|
|
|
|
|
141
|
|
|
18
|
|
|
|
|
87
|
|
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub _first_time { |
89
|
2
|
|
|
2
|
|
2
|
my $self = shift; |
90
|
2
|
|
33
|
|
|
10
|
my $author = $self->{author} || $self->_prompt('Enter Author: '); |
91
|
2
|
|
33
|
|
|
8
|
my $email = $self->{email} || $self->_prompt('Enter Email: '); |
92
|
|
|
|
|
|
|
|
93
|
2
|
|
33
|
|
|
6
|
$self->{file} ||= $self->_default_file; |
94
|
2
|
|
|
|
|
7
|
$self->{config} = { |
95
|
|
|
|
|
|
|
author => $author, |
96
|
|
|
|
|
|
|
email => $email, |
97
|
|
|
|
|
|
|
}; |
98
|
|
|
|
|
|
|
|
99
|
2
|
|
|
|
|
5
|
$self->save; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub _search { |
103
|
3
|
|
|
3
|
|
4
|
my $self = shift; |
104
|
|
|
|
|
|
|
|
105
|
12
|
|
|
|
|
197
|
grep { $_->exists } |
|
6
|
|
|
|
|
353
|
|
106
|
3
|
|
|
|
|
14
|
map {( $_->child('.new_perl_module.yml'), |
107
|
|
|
|
|
|
|
$_->child('.new_perl_module.yaml') )} |
108
|
|
|
|
|
|
|
( Path::Tiny::path('.'), $self->_home ); |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
3
|
|
|
3
|
|
98
|
sub _home { Path::Tiny::path( File::HomeDir->my_home ) } |
112
|
|
|
|
|
|
|
|
113
|
0
|
|
|
0
|
|
0
|
sub _default_file { shift->_home->child('.new_perl_module.yml') } |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
sub _prompt { |
116
|
4
|
|
|
4
|
|
4
|
my ($self, $prompt) = @_; |
117
|
4
|
50
|
|
|
|
13
|
return if $self->{no_prompt}; # for test |
118
|
|
|
|
|
|
|
|
119
|
0
|
|
|
|
|
|
print $prompt; |
120
|
0
|
|
|
|
|
|
my $ret = ; chomp $ret; |
|
0
|
|
|
|
|
|
|
121
|
0
|
|
|
|
|
|
return $ret; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
1; |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
__END__ |