line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Module::Start::Config; |
2
|
1
|
|
|
1
|
|
809
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
38
|
|
3
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
38
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
8
|
use base 'Module::Start::Base'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
141
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
6
|
use Class::Field 'field'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
72
|
|
8
|
1
|
|
|
1
|
|
7
|
use IO::All; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
20
|
|
9
|
1
|
|
|
1
|
|
70
|
use Config; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
48
|
|
10
|
1
|
|
|
1
|
|
6
|
use XXX; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
8
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
field 'base_dir', -init => '$self->get_base_dir'; |
13
|
|
|
|
|
|
|
field 'is_configured' => 0; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# Template variables |
16
|
|
|
|
|
|
|
field 'flavor' => 'UNDEFINED'; |
17
|
|
|
|
|
|
|
field 'module_name' => 'UNDEFINED'; |
18
|
|
|
|
|
|
|
field 'module_dist_name' => 'UNDEFINED'; |
19
|
|
|
|
|
|
|
field 'module_dist_name_version' => 'UNDEFINED'; |
20
|
|
|
|
|
|
|
field 'module_dist_name_lower' => 'UNDEFINED'; |
21
|
|
|
|
|
|
|
field 'module_lib_path' => 'UNDEFINED'; |
22
|
|
|
|
|
|
|
field 'module_pm' => 'UNDEFINED'; |
23
|
|
|
|
|
|
|
field 'module_all_lib_paths' => 'UNDEFINED'; |
24
|
|
|
|
|
|
|
field 'author_full_name' => 'UNDEFINED'; |
25
|
|
|
|
|
|
|
field 'author_email_address' => 'UNDEFINED'; |
26
|
|
|
|
|
|
|
field 'author_email_masked' => 'UNDEFINED'; |
27
|
|
|
|
|
|
|
field 'date_time_human' => scalar(gmtime); |
28
|
|
|
|
|
|
|
field 'date_time_year' => (gmtime)[5] + 1900; |
29
|
|
|
|
|
|
|
field 'perl_config' => { %Config::Config }; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# Short/compatibility template variables |
32
|
|
|
|
|
|
|
field 'module', -init => '$self->module_name'; |
33
|
|
|
|
|
|
|
field 'main_module', -init => '$self->module_dist_name'; |
34
|
|
|
|
|
|
|
field 'main_pm_file', -init => '$self->module_lib_path'; |
35
|
|
|
|
|
|
|
field 'rtnname', -init => '$self->module_dist_name_lower'; |
36
|
|
|
|
|
|
|
field 'build_instructions' => ''; |
37
|
|
|
|
|
|
|
field 'modules', -init => '$self->module_all_lib_paths'; |
38
|
|
|
|
|
|
|
field 'year', -init => '$self->date_time_year'; |
39
|
|
|
|
|
|
|
field 'author', -init => '$self->author_full_name'; |
40
|
|
|
|
|
|
|
field 'email', -init => '$self->author_email_address'; |
41
|
|
|
|
|
|
|
field 'distro', -init => '$self->module_dist_name_version'; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub new { |
44
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
45
|
0
|
|
|
|
|
|
my $self = $class->SUPER::new(@_); |
46
|
0
|
0
|
|
|
|
|
$self->is_configured(1) |
47
|
|
|
|
|
|
|
if -e $self->config_path; |
48
|
0
|
|
|
|
|
|
return $self; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub initialize { |
52
|
0
|
|
|
0
|
0
|
|
my ($self, $args) = @_; |
53
|
0
|
|
|
|
|
|
$self->read_config; |
54
|
0
|
0
|
|
|
|
|
if ($self->author_email_address ne 'UNDEFINED') { |
55
|
0
|
|
|
|
|
|
my $email = $self->author_email_address; |
56
|
0
|
|
|
|
|
|
$email =~ s/\@/ at /; |
57
|
0
|
|
|
|
|
|
$self->author_email_masked($email); |
58
|
|
|
|
|
|
|
} |
59
|
0
|
0
|
|
|
|
|
if (my $module_name = $args->{target}) { |
60
|
0
|
|
|
|
|
|
$module_name =~ s/-/::/g; |
61
|
0
|
|
|
|
|
|
$module_name =~ s/\.pm$//; |
62
|
0
|
|
|
|
|
|
$self->module_name($module_name); |
63
|
0
|
|
|
|
|
|
local $_ = $module_name; |
64
|
0
|
|
|
|
|
|
$self->module_dist_name(do { s/::/-/g; $_ }); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
$self->module_dist_name_lower(do { lc($_) }); |
|
0
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
$self->module_lib_path( |
67
|
0
|
|
|
|
|
|
do { s/-/\//g; $_ = "lib/$_.pm" } |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
); |
69
|
0
|
|
|
|
|
|
$self->module_pm(do { s/.*\///g; $_ }); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
} |
71
|
0
|
0
|
|
|
|
|
if (my $flavor = $args->{flavor}) { |
72
|
0
|
|
|
|
|
|
$self->flavor($flavor); |
73
|
|
|
|
|
|
|
} |
74
|
0
|
|
|
|
|
|
$self->set_all; |
75
|
0
|
|
|
|
|
|
return $self; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub set_all { |
79
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
80
|
0
|
|
|
|
|
|
map { $self->$_ } qw( |
|
0
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
author_full_name |
82
|
|
|
|
|
|
|
author_email_address |
83
|
|
|
|
|
|
|
author_email_masked |
84
|
|
|
|
|
|
|
date_time_human |
85
|
|
|
|
|
|
|
date_time_year |
86
|
|
|
|
|
|
|
perl_config |
87
|
|
|
|
|
|
|
module |
88
|
|
|
|
|
|
|
main_module |
89
|
|
|
|
|
|
|
main_pm_file |
90
|
|
|
|
|
|
|
rtnname |
91
|
|
|
|
|
|
|
build_instructions |
92
|
|
|
|
|
|
|
modules |
93
|
|
|
|
|
|
|
year |
94
|
|
|
|
|
|
|
author |
95
|
|
|
|
|
|
|
email |
96
|
|
|
|
|
|
|
distro |
97
|
|
|
|
|
|
|
); |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub get_base_dir { |
101
|
0
|
0
|
0
|
0
|
0
|
|
return $ENV{MODULE_START_BASE} || |
102
|
|
|
|
|
|
|
defined $ENV{HOME} |
103
|
|
|
|
|
|
|
? "$ENV{HOME}/.module-start" |
104
|
|
|
|
|
|
|
: die "HOME environment variable not set"; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub templates_path { |
108
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
109
|
0
|
|
|
|
|
|
my $path = |
110
|
|
|
|
|
|
|
$self->base_dir . '/templates/' . $self->flavor; |
111
|
0
|
0
|
|
|
|
|
die "Templates path '$path' does not exist!!" |
112
|
|
|
|
|
|
|
unless -e $path; |
113
|
0
|
|
|
|
|
|
return $path; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
sub read_config { |
117
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
118
|
0
|
|
|
|
|
|
my $file_path = $self->config_path; |
119
|
0
|
|
|
|
|
|
my $config_content = io($file_path)->all; |
120
|
0
|
|
|
|
|
|
for my $line ($config_content =~ /(.*\n)/g) { |
121
|
0
|
0
|
|
|
|
|
next if $line =~ /^(#|\s*$)/; |
122
|
0
|
0
|
|
|
|
|
$line =~ /^(\w+)\s*:\s+(.*)/ or die "Error in $file_path"; |
123
|
0
|
|
|
|
|
|
$self->{$1} = $2; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
sub write_config { |
128
|
0
|
|
|
0
|
0
|
|
my ($self, $template) = @_; |
129
|
0
|
|
|
|
|
|
my $file_content = $self->render_template(\ $template, |
130
|
|
|
|
|
|
|
author_full_name => $self->author_full_name, |
131
|
|
|
|
|
|
|
author_email_address => $self->author_email_address, |
132
|
|
|
|
|
|
|
); |
133
|
0
|
|
|
|
|
|
io->file($self->config_path)->assert->print($file_content); |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub config_path { |
137
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
138
|
0
|
|
|
|
|
|
return $self->base_dir . "/config"; |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
1; |