line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
=head1 NAME |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
Perlbal::Plugin::Include - Allows multiple, nesting configuration files |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 DESCRIPTION |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
This module adds an INCLUDE command to the Perlbal management console |
8
|
|
|
|
|
|
|
and allows the globbed inclusion of configuration files. |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 SYNOPSIS |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
This module provides a Perlbal plugin which can be loaded and used as |
13
|
|
|
|
|
|
|
follows: |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
LOAD include |
16
|
|
|
|
|
|
|
INCLUDE = /etc/perlbal/my.conf |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
You may also specify multiple configuration files a la File::Glob: |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
INCLUDE = /foo/bar.conf /foo/quux/*.conf |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 BUGS AND LIMITATIONS |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
This module relies entirely on Perlbal::load_config for loading, so if |
25
|
|
|
|
|
|
|
you have trouble with INCLUDE, be sure you can load the same |
26
|
|
|
|
|
|
|
configuration without error using "perlbal -c" first. |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
Also note that Perlbal::load_config versions 1.60 and below do not use |
29
|
|
|
|
|
|
|
a local filehandle while reading the configuration file, so this |
30
|
|
|
|
|
|
|
module overrides that routine on load to allow nested calls. |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
Copyright 2008 Eamon Daly |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
This module is part of the Perlbal distribution, and as such can be |
37
|
|
|
|
|
|
|
distributed under the same licence terms as the rest of Perlbal. |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=cut |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
package Perlbal::Plugin::Include; |
42
|
|
|
|
|
|
|
|
43
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
35
|
|
44
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
34
|
|
45
|
1
|
|
|
1
|
|
5
|
no warnings qw(deprecated); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
416
|
|
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
# called when we are loaded |
48
|
|
|
|
|
|
|
sub load { |
49
|
1
|
|
|
1
|
0
|
3
|
my $class = shift; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
Perlbal::register_global_hook('manage_command.include', sub { |
52
|
3
|
|
|
3
|
|
28
|
my $mc = shift->parse(qr/^include\s+=\s+(.+)\s*$/, |
53
|
|
|
|
|
|
|
"usage: INCLUDE = "); |
54
|
|
|
|
|
|
|
|
55
|
3
|
|
|
|
|
16
|
my ($glob) = $mc->args; |
56
|
|
|
|
|
|
|
|
57
|
3
|
|
|
|
|
503
|
for (glob($glob)) { |
58
|
4
|
|
|
|
|
32
|
Perlbal::load_config($_, sub { print STDOUT "$_[0]\n"; }); |
|
0
|
|
|
|
|
0
|
|
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
2
|
|
|
|
|
14
|
return $mc->ok; |
62
|
1
|
|
|
|
|
7
|
}); |
63
|
|
|
|
|
|
|
|
64
|
1
|
|
|
|
|
18
|
return 1; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
# called for a global unload |
68
|
|
|
|
|
|
|
sub unload { |
69
|
|
|
|
|
|
|
# unregister our global hooks |
70
|
0
|
|
|
0
|
0
|
|
Perlbal::unregister_global_hook('manage_command.include'); |
71
|
|
|
|
|
|
|
|
72
|
0
|
|
|
|
|
|
return 1; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
# In older versions of Perlbal, load_config uses a typeglob, throwing |
76
|
|
|
|
|
|
|
# warnings when re-entering. This uses a locally-scoped filehandle. |
77
|
|
|
|
|
|
|
sub load_config_local { |
78
|
0
|
|
|
0
|
0
|
|
my ($file, $writer) = @_; |
79
|
0
|
0
|
|
|
|
|
open(my $fh, $file) or die "Error opening config file ($file): $!\n"; |
80
|
0
|
|
|
|
|
|
my $ctx = Perlbal::CommandContext->new; |
81
|
0
|
|
|
|
|
|
$ctx->verbose(0); |
82
|
0
|
|
|
|
|
|
while (my $line = <$fh>) { |
83
|
0
|
|
|
|
|
|
$line =~ s/\$(\w+)/$ENV{$1}/g; |
84
|
0
|
0
|
|
|
|
|
return 0 unless Perlbal::run_manage_command($line, $writer, $ctx); |
85
|
|
|
|
|
|
|
} |
86
|
0
|
|
|
|
|
|
close($fh); |
87
|
0
|
|
|
|
|
|
return 1; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
1; |