line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package System::InitD::Base; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
8
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
49
|
|
4
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
42
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
1401
|
use System::InitD::Template; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
56
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
57
|
use Carp; |
|
1
|
|
|
|
|
28
|
|
|
1
|
|
|
|
|
811
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new { |
11
|
1
|
|
|
1
|
0
|
2
|
my ($class, $options) = @_; |
12
|
|
|
|
|
|
|
|
13
|
1
|
|
|
|
|
5
|
my $self = { |
14
|
|
|
|
|
|
|
_options => $options, |
15
|
|
|
|
|
|
|
_rp => {}, |
16
|
|
|
|
|
|
|
}; |
17
|
1
|
|
|
|
|
6
|
return bless $self, $class; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub set_render_params { |
22
|
0
|
|
|
0
|
0
|
0
|
my ($self, $params) = @_; |
23
|
|
|
|
|
|
|
|
24
|
0
|
0
|
|
|
|
0
|
croak "Missing params" unless $params; |
25
|
|
|
|
|
|
|
|
26
|
0
|
|
|
|
|
0
|
$self->{_rp} = $params; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub _rp { |
31
|
1
|
|
|
1
|
|
2
|
my $self = shift; |
32
|
|
|
|
|
|
|
|
33
|
1
|
|
|
|
|
6
|
return $self->{_rp}; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub forward_render_params { |
38
|
1
|
|
|
1
|
0
|
3
|
my ($self, $params, @allowed) = @_; |
39
|
|
|
|
|
|
|
|
40
|
1
|
50
|
33
|
|
|
6
|
return 0 if (!$params || ! scalar @allowed); |
41
|
|
|
|
|
|
|
# allowed paarams |
42
|
1
|
|
|
|
|
2
|
my $ap; |
43
|
1
|
|
|
|
|
3
|
%$ap = map{($_, 1)}@allowed; |
|
6
|
|
|
|
|
12
|
|
44
|
|
|
|
|
|
|
|
45
|
1
|
|
|
|
|
4
|
for my $k (keys %$params) { |
46
|
6
|
50
|
33
|
|
|
23
|
if (defined $ap->{$k} && $ap->{$k}) { |
47
|
6
|
|
|
|
|
16
|
$self->{_rp}->{$k} = $params->{$k}; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
1
|
|
|
|
|
4
|
return 1; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub write_script { |
56
|
1
|
|
|
1
|
0
|
3
|
my ($self, $template) = @_; |
57
|
|
|
|
|
|
|
|
58
|
1
|
|
|
|
|
2
|
my $script; |
59
|
1
|
|
|
|
|
7
|
$script = System::InitD::Template::render( |
60
|
|
|
|
|
|
|
file => $template, |
61
|
|
|
|
|
|
|
render_params => $self->_rp(), |
62
|
|
|
|
|
|
|
); |
63
|
|
|
|
|
|
|
|
64
|
1
|
|
|
|
|
4
|
my $target = $self->{_options}->{target}; |
65
|
1
|
50
|
|
|
|
3
|
croak "Missing target" unless $target; |
66
|
|
|
|
|
|
|
|
67
|
1
|
50
|
|
|
|
93
|
open TARGET, '>', $target or croak "Can't write target"; |
68
|
1
|
|
|
|
|
17
|
print TARGET $script; |
69
|
1
|
|
|
|
|
46
|
close TARGET; |
70
|
|
|
|
|
|
|
|
71
|
1
|
|
|
|
|
35
|
chmod 0755, $target; |
72
|
1
|
|
|
|
|
4
|
return 1; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
1; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
__END__ |