line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Module::Start::Base; |
2
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
25
|
|
3
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
18
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
903
|
use Term::ReadLine; |
|
1
|
|
|
|
|
3285
|
|
|
1
|
|
|
|
|
978
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
sub new { |
8
|
0
|
|
|
0
|
0
|
|
my $self = bless {}, shift; |
9
|
0
|
|
|
|
|
|
while (@_) { |
10
|
0
|
|
|
|
|
|
my ($key, $value) = splice(@_, 0, 2); |
11
|
0
|
|
|
|
|
|
$self->$key($value); |
12
|
|
|
|
|
|
|
} |
13
|
0
|
|
|
|
|
|
return $self; |
14
|
|
|
|
|
|
|
} |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# XXX In the future support a config class override in the config file. |
17
|
|
|
|
|
|
|
sub new_config_object { |
18
|
0
|
|
|
0
|
0
|
|
require Module::Start::Config; |
19
|
0
|
|
|
|
|
|
return Module::Start::Config->new; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub exit { |
23
|
0
|
|
|
0
|
0
|
|
my ($self, $msg, $option) = (@_, '', ''); |
24
|
0
|
|
|
|
|
|
chomp $msg; |
25
|
0
|
0
|
|
|
|
|
print "$msg\n" if $msg; |
26
|
0
|
0
|
|
|
|
|
print "Exiting...\n" unless $option eq -noExitMsg; |
27
|
0
|
|
|
|
|
|
CORE::exit; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# prompt a query and return true or false |
31
|
|
|
|
|
|
|
sub p { |
32
|
0
|
|
|
0
|
0
|
|
my ($self, $query, $default) = @_; |
33
|
0
|
|
0
|
|
|
|
$query ||= ''; |
34
|
0
|
|
0
|
|
|
|
$default ||= ''; |
35
|
0
|
|
|
|
|
|
PROMPT: { |
36
|
0
|
|
|
|
|
|
my $answer = read_line($query . ' '); |
37
|
0
|
|
|
|
|
|
chomp $answer; |
38
|
0
|
|
|
|
|
|
$answer =~ s/^\s*(.*?)\s*$/$1/; |
39
|
0
|
0
|
|
|
|
|
$answer = $default unless length $answer; |
40
|
0
|
0
|
|
|
|
|
redo PROMPT unless length $answer; |
41
|
0
|
|
|
|
|
|
return $answer; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub q { |
46
|
0
|
|
|
0
|
0
|
|
my ($self, $query, $default) = @_; |
47
|
0
|
|
0
|
|
|
|
$query ||= ''; |
48
|
0
|
|
0
|
|
|
|
$default ||= ''; |
49
|
0
|
0
|
|
|
|
|
$query .= |
|
|
0
|
|
|
|
|
|
50
|
|
|
|
|
|
|
$default eq 'y' ? ' [Yn] ' : |
51
|
|
|
|
|
|
|
$default eq 'n' ? ' [yN] ' : |
52
|
|
|
|
|
|
|
' [yn] '; |
53
|
0
|
|
|
|
|
|
PROMPT: { |
54
|
0
|
|
|
|
|
|
my $answer = lc read_line($query); |
55
|
0
|
|
|
|
|
|
chomp $answer; |
56
|
0
|
0
|
|
|
|
|
$answer = $default unless $answer; |
57
|
0
|
0
|
|
|
|
|
redo PROMPT unless $answer =~ /^[yn]$/; |
58
|
0
|
|
|
|
|
|
return $answer =~ /y/; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
{ |
63
|
|
|
|
|
|
|
$| = 1; |
64
|
|
|
|
|
|
|
my $rl; |
65
|
|
|
|
|
|
|
$rl = Term::ReadLine->new if -t STDOUT; |
66
|
|
|
|
|
|
|
sub read_line { |
67
|
0
|
|
|
0
|
0
|
|
my $query = shift; |
68
|
0
|
|
|
|
|
|
my $input; |
69
|
0
|
0
|
|
|
|
|
if ($rl) { |
70
|
0
|
|
|
|
|
|
$input = $rl->readline($query); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
else { |
73
|
0
|
|
|
|
|
|
print $query; |
74
|
0
|
|
|
|
|
|
$input = readline(); |
75
|
|
|
|
|
|
|
} |
76
|
0
|
0
|
|
|
|
|
if (not defined $input) { |
77
|
0
|
|
|
|
|
|
print "\n"; |
78
|
0
|
|
|
|
|
|
CORE::exit; |
79
|
|
|
|
|
|
|
} |
80
|
0
|
|
|
|
|
|
$input .= "\n"; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub read_data_files { |
85
|
0
|
|
|
0
|
0
|
|
my ($self, $package) = @_; |
86
|
0
|
|
|
|
|
|
my $hash; |
87
|
0
|
|
|
|
|
|
%$hash = $self->get_packed_files($package); |
88
|
0
|
|
|
|
|
|
return $hash; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub get_packed_files { |
92
|
0
|
|
|
0
|
0
|
|
my ($self, $package) = @_; |
93
|
0
|
0
|
|
|
|
|
my $data = $self->data($package) or return; |
94
|
0
|
|
|
|
|
|
my @data = split $self->file_separator_regexp, $data; |
95
|
0
|
|
|
|
|
|
shift @data; |
96
|
0
|
|
|
|
|
|
return @data; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub file_separator_regexp { |
100
|
0
|
|
|
0
|
0
|
|
return qr/^__+\[\s*(.+?)\s*\]__+\n/m; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub data { |
104
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
105
|
0
|
|
|
|
|
|
my $package = shift; |
106
|
0
|
|
|
0
|
|
|
local $SIG{__WARN__} = sub {}; |
|
0
|
|
|
|
|
|
|
107
|
0
|
|
|
|
|
|
local $/; |
108
|
0
|
|
|
|
|
|
eval "package $package; "; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub render_template { |
112
|
0
|
|
|
0
|
0
|
|
require Template; |
113
|
0
|
|
|
|
|
|
my ($self, $template, %vars) = @_; |
114
|
|
|
|
|
|
|
|
115
|
0
|
|
|
|
|
|
$vars{self} = $self; |
116
|
|
|
|
|
|
|
|
117
|
0
|
|
|
|
|
|
my $t = Template->new; |
118
|
|
|
|
|
|
|
|
119
|
0
|
|
|
|
|
|
my $output; |
120
|
0
|
|
|
|
|
|
eval { |
121
|
0
|
0
|
|
|
|
|
$t->process($template, \%vars, \$output) or die $t->error; |
122
|
|
|
|
|
|
|
}; |
123
|
0
|
0
|
|
|
|
|
die "Template Toolkit error:\n$@" if $@; |
124
|
0
|
|
|
|
|
|
return $output; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
1; |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head1 NAME |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
Module::Start::Base - Base class for Module::Start |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head1 SYNOPSIS |
134
|
|
|
|
|
|
|
|