line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Module::New::Config;
|
2
|
|
|
|
|
|
|
|
3
|
7
|
|
|
7
|
|
20914
|
use strict;
|
|
7
|
|
|
|
|
10
|
|
|
7
|
|
|
|
|
217
|
|
4
|
7
|
|
|
7
|
|
24
|
use warnings;
|
|
7
|
|
|
|
|
12
|
|
|
7
|
|
|
|
|
128
|
|
5
|
7
|
|
|
7
|
|
55
|
use Carp;
|
|
7
|
|
|
|
|
8
|
|
|
7
|
|
|
|
|
368
|
|
6
|
7
|
|
|
7
|
|
4094
|
use File::HomeDir;
|
|
7
|
|
|
|
|
28362
|
|
|
7
|
|
|
|
|
345
|
|
7
|
7
|
|
|
7
|
|
4167
|
use Getopt::Long ();
|
|
7
|
|
|
|
|
56067
|
|
|
7
|
|
|
|
|
180
|
|
8
|
7
|
|
|
7
|
|
1864
|
use Path::Tiny ();
|
|
7
|
|
|
|
|
27542
|
|
|
7
|
|
|
|
|
127
|
|
9
|
7
|
|
|
7
|
|
4618
|
use YAML::Tiny;
|
|
7
|
|
|
|
|
32934
|
|
|
7
|
|
|
|
|
4044
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub new {
|
12
|
20
|
|
|
20
|
1
|
9907
|
my ($class, %options) = @_;
|
13
|
|
|
|
|
|
|
|
14
|
20
|
|
|
|
|
174
|
my $parser = Getopt::Long::Parser->new(
|
15
|
|
|
|
|
|
|
config => [qw( bundling ignore_case pass_through )]
|
16
|
|
|
|
|
|
|
);
|
17
|
|
|
|
|
|
|
|
18
|
20
|
|
|
|
|
1591
|
my $self = bless { parser => $parser, %options }, $class;
|
19
|
|
|
|
|
|
|
|
20
|
20
|
|
|
|
|
70
|
$self->load;
|
21
|
20
|
|
|
|
|
10524
|
$self;
|
22
|
|
|
|
|
|
|
}
|
23
|
|
|
|
|
|
|
|
24
|
5
|
|
|
5
|
1
|
31
|
sub file { shift->{file} }
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub get {
|
27
|
306
|
|
|
306
|
1
|
788
|
my ($self, $key) = @_;
|
28
|
306
|
100
|
|
|
|
516
|
return $self->{option}->{$key} if exists $self->{option}->{$key};
|
29
|
301
|
100
|
|
|
|
1096
|
return $self->{config}->{$key} if exists $self->{config}->{$key};
|
30
|
216
|
|
|
|
|
579
|
return;
|
31
|
|
|
|
|
|
|
}
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub set {
|
34
|
23
|
|
|
23
|
1
|
26
|
my $self = shift;
|
35
|
|
|
|
|
|
|
|
36
|
23
|
50
|
33
|
|
|
106
|
if ( @_ and @_ % 2 == 0 ) {
|
37
|
23
|
50
|
|
|
|
24
|
$self->{config} = { %{ $self->{config} || {} }, @_ };
|
|
23
|
|
|
|
|
139
|
|
38
|
|
|
|
|
|
|
}
|
39
|
|
|
|
|
|
|
}
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub save {
|
42
|
3
|
|
|
3
|
1
|
13
|
my $self = shift;
|
43
|
|
|
|
|
|
|
|
44
|
3
|
100
|
|
|
|
10
|
$self->set(@_) if @_;
|
45
|
|
|
|
|
|
|
|
46
|
3
|
|
33
|
|
|
11
|
$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
|
34
|
my $self = shift;
|
53
|
|
|
|
|
|
|
|
54
|
22
|
100
|
|
|
|
94
|
if ( $self->{file} ) {
|
55
|
7
|
100
|
|
|
|
19
|
return if $self->_load_and_merge( $self->{file} );
|
56
|
|
|
|
|
|
|
}
|
57
|
|
|
|
|
|
|
else {
|
58
|
15
|
|
|
|
|
53
|
foreach my $file ( $self->_search ) {
|
59
|
15
|
100
|
|
|
|
104
|
return if $self->_load_and_merge( $file );
|
60
|
|
|
|
|
|
|
}
|
61
|
|
|
|
|
|
|
}
|
62
|
14
|
|
|
|
|
86
|
$self->_first_time;
|
63
|
|
|
|
|
|
|
}
|
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub _load_and_merge {
|
66
|
22
|
|
|
22
|
|
40
|
my ($self, $file) = @_;
|
67
|
|
|
|
|
|
|
|
68
|
22
|
100
|
66
|
|
|
245
|
return unless $file && -f $file;
|
69
|
|
|
|
|
|
|
|
70
|
8
|
|
|
|
|
104
|
my $config;
|
71
|
8
|
|
|
|
|
8
|
eval { $config = YAML::Tiny::LoadFile( $file ) };
|
|
8
|
|
|
|
|
22
|
|
72
|
8
|
50
|
|
|
|
4181
|
return if $@;
|
73
|
|
|
|
|
|
|
|
74
|
8
|
|
|
|
|
8
|
foreach my $key ( keys %{ $config } ) {
|
|
8
|
|
|
|
|
22
|
|
75
|
16
|
|
|
|
|
35
|
$self->{config}->{$key} = $config->{$key};
|
76
|
|
|
|
|
|
|
}
|
77
|
8
|
|
|
|
|
12
|
$self->{file} = $file;
|
78
|
8
|
|
|
|
|
33
|
return 1;
|
79
|
|
|
|
|
|
|
}
|
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub get_options {
|
82
|
18
|
|
|
18
|
1
|
554
|
my ($self, @specs) = @_;
|
83
|
18
|
|
|
|
|
31
|
my $config = {};
|
84
|
18
|
|
|
|
|
78
|
$self->{parser}->getoptions($config, @specs);
|
85
|
18
|
100
|
|
|
|
5038
|
$self->{option} = { %{ $self->{option} || {} }, %{ $config } };
|
|
18
|
|
|
|
|
107
|
|
|
18
|
|
|
|
|
54
|
|
86
|
|
|
|
|
|
|
}
|
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub _first_time {
|
89
|
2
|
|
|
2
|
|
4
|
my $self = shift;
|
90
|
2
|
|
33
|
|
|
10
|
my $author = $self->{author} || $self->_prompt('Enter Author: ');
|
91
|
2
|
|
33
|
|
|
6
|
my $email = $self->{email} || $self->_prompt('Enter Email: ');
|
92
|
|
|
|
|
|
|
|
93
|
2
|
|
33
|
|
|
14
|
$self->{file} ||= $self->_default_file;
|
94
|
2
|
|
|
|
|
6
|
$self->{config} = {
|
95
|
|
|
|
|
|
|
author => $author,
|
96
|
|
|
|
|
|
|
email => $email,
|
97
|
|
|
|
|
|
|
};
|
98
|
|
|
|
|
|
|
|
99
|
2
|
|
|
|
|
7
|
$self->save;
|
100
|
|
|
|
|
|
|
}
|
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub _search {
|
103
|
3
|
|
|
3
|
|
4
|
my $self = shift;
|
104
|
|
|
|
|
|
|
|
105
|
12
|
|
|
|
|
146
|
grep { $_->exists }
|
|
6
|
|
|
|
|
292
|
|
106
|
3
|
|
|
|
|
12
|
map {( $_->child('.new_perl_module.yml'),
|
107
|
|
|
|
|
|
|
$_->child('.new_perl_module.yaml') )}
|
108
|
|
|
|
|
|
|
( Path::Tiny::path('.'), $self->_home );
|
109
|
|
|
|
|
|
|
}
|
110
|
|
|
|
|
|
|
|
111
|
3
|
|
|
3
|
|
95
|
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
|
|
5
|
my ($self, $prompt) = @_;
|
117
|
4
|
50
|
|
|
|
14
|
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__
|