Perlbal/Plugin/Include.pm

filter: Statementstmt 63.6% 21 / 33 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 66.6% 6 / 9 Podpod 0.0% 0 / 3 totaltotal 52.9% 27 / 51 CC 5 SCAR 19.6
CC
5
Cov
54%
load_config_local
20.0
__ANON__
2.0
unload
2.0
CRAP 7.1
« Perlbal/ClientHTTP.pm ↑ Summary Perlbal/Test.pm »
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 <eamon@eamondaly.com>
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 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
44 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
45 1 ▶no warnings qw(deprecated);
Subroutine BEGIN: called CC=1 SCAR=0.0
46  
47 # called when we are loaded
48 1 ▶sub load {
Subroutine load: called CC=1 SCAR=0.0
Pod undocumented
49 1 my $class = shift;
50  
51 3 ▶ Perlbal::register_global_hook('manage_command.include', sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
52 3 my $mc = shift->parse(qr/^include\s+=\s+(.+)\s*$/,
53 "usage: INCLUDE = <config files>");
54  
55 3 my ($glob) = $mc->args;
56  
57 1 ▶ for (glob($glob)) {
Subroutine BEGIN: called CC=1 SCAR=0.0
58 0 ▶ Perlbal::load_config($_, sub { print STDOUT "$_[0]\n"; });
Subroutine __ANON__: not called CC=1 SCAR=1.2
59 }
60  
61 2 return $mc->ok;
62 1 });
63  
64 1 return 1;
65 }
66  
67 # called for a global unload
68 0 ▶sub unload {
Subroutine unload: not called CC=1 SCAR=6.9
Pod undocumented
69 # unregister our global hooks
70 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 0 ▶sub load_config_local {
Subroutine load_config_local: not called CC=4 SCAR=30.0
Pod undocumented
78 0 my ($file, $writer) = @_;
79 0 ▶ open(my $fh, $file) or die "Error opening config file ($file): $!\n";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, $file or die "Error opening config file ($file): $!\n" 0 0 0
80 0 my $ctx = Perlbal::CommandContext->new;
81 0 $ctx->verbose(0);
82 0 ▶ while (my $line = <$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $fh)) 0 0 0
83 0 $line =~ s/\$(\w+)/$ENV{$1}/g;
84 0 ▶ return 0 unless Perlbal::run_manage_command($line, $writer, $ctx);
Branch: 1 branch
BranchTrueFalseTotal
unless Perlbal::run_manage_command($line, $writer, $ctx) 0 0 0
85 }
86 0 close($fh);
87 0 return 1;
88 }
89  
90 1 1;
« Perlbal/ClientHTTP.pm ↑ Summary Perlbal/Test.pm »