line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
=head1 NAME |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
Config::Vars - A module for keeping configuration variables in a central perl file. |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 VERSION |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
This documentation describes version 0.01 of Config::Vars.pm, May 23, 2003. |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=cut |
10
|
|
|
|
|
|
|
|
11
|
5
|
|
|
5
|
|
78046
|
use strict; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
209
|
|
12
|
|
|
|
|
|
|
package Config::Vars; |
13
|
5
|
|
|
5
|
|
28
|
use vars qw/$VERSION @CARP_NOT/; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
365
|
|
14
|
|
|
|
|
|
|
$VERSION = 0.01; |
15
|
|
|
|
|
|
|
|
16
|
5
|
|
|
5
|
|
28
|
use Carp; |
|
5
|
|
|
|
|
24
|
|
|
5
|
|
|
|
|
530
|
|
17
|
5
|
|
|
5
|
|
6601
|
use Filter::Simple; |
|
5
|
|
|
|
|
168428
|
|
|
5
|
|
|
|
|
34
|
|
18
|
|
|
|
|
|
|
@CARP_NOT = qw(Filter::Simple); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# Can we use Readonly? |
21
|
5
|
|
|
5
|
|
302
|
use vars '$RO_ok'; |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
3799
|
|
22
|
|
|
|
|
|
|
my $nowarn; # if true, don't kvetch about Readonly not being available |
23
|
|
|
|
|
|
|
my $export; # Exporter array name |
24
|
|
|
|
|
|
|
eval { require 'Readonly.pm' }; |
25
|
|
|
|
|
|
|
$RO_ok = 1 unless $@; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# These get set by import() at the begining of each module; reset by xform. |
28
|
|
|
|
|
|
|
my $usevars; |
29
|
|
|
|
|
|
|
my $isa; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub import |
33
|
|
|
|
|
|
|
{ |
34
|
|
|
|
|
|
|
my $pkg = shift; |
35
|
|
|
|
|
|
|
my @errs; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# Module-by-module init |
38
|
|
|
|
|
|
|
$nowarn = 0; |
39
|
|
|
|
|
|
|
$export = 'EXPORT_OK'; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
foreach my $opt (@_) |
42
|
|
|
|
|
|
|
{ |
43
|
|
|
|
|
|
|
if ($opt eq 'nowarn') |
44
|
|
|
|
|
|
|
{ |
45
|
|
|
|
|
|
|
$nowarn = 1; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
elsif ($opt eq 'exportall') |
48
|
|
|
|
|
|
|
{ |
49
|
|
|
|
|
|
|
$export = 'EXPORT'; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
else |
52
|
|
|
|
|
|
|
{ |
53
|
|
|
|
|
|
|
push @errs, $opt; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
my $s = @errs > 1? 's' : ''; |
57
|
|
|
|
|
|
|
croak "Unknown Config::Vars option$s (@errs)" if @errs; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
$usevars = "\@$export \@ISA "; |
60
|
|
|
|
|
|
|
$isa = "\n" . q(push @ISA, 'Exporter' unless grep $_ eq 'Exporter', @ISA;); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
# Filter the code |
65
|
|
|
|
|
|
|
# Change |
66
|
|
|
|
|
|
|
# var $foo = 'bar'; |
67
|
|
|
|
|
|
|
# into |
68
|
|
|
|
|
|
|
# use vars qw($foo); |
69
|
|
|
|
|
|
|
# push @EXPORT_OK, qw($foo); # or, push @EXPORT, qw($foo); |
70
|
|
|
|
|
|
|
# $foo = 'bar'; |
71
|
|
|
|
|
|
|
FILTER_ONLY |
72
|
|
|
|
|
|
|
code => sub { |
73
|
|
|
|
|
|
|
# print STDERR "BEFORE: [$_]\n"; |
74
|
|
|
|
|
|
|
s/^ \s* # optional leading whitespace |
75
|
|
|
|
|
|
|
(var|ro) # 'var' or 'ro' keyword |
76
|
|
|
|
|
|
|
\s+ # mandatory whitespace |
77
|
|
|
|
|
|
|
([^=;\s]+) # a variable name |
78
|
|
|
|
|
|
|
\s* # optional whitespace |
79
|
|
|
|
|
|
|
(\S) # = or semicolon |
80
|
|
|
|
|
|
|
/xform($1,$2,$3)/gemx; |
81
|
|
|
|
|
|
|
# print STDERR "AFTER: [$_]\n"; |
82
|
|
|
|
|
|
|
}; |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub xform |
86
|
|
|
|
|
|
|
{ |
87
|
24
|
|
|
24
|
0
|
95
|
my ($cmd, $var, $eqs) = @_; |
88
|
24
|
50
|
66
|
|
|
142
|
croak qq{Can't process "$cmd $var $eqs" line} if $cmd ne 'var' && $cmd ne 'ro'; |
89
|
24
|
50
|
|
|
|
100
|
unless ($var =~ /^[\$\@\%][_[:alpha:]]\w+/) |
90
|
|
|
|
|
|
|
{ |
91
|
0
|
0
|
0
|
|
|
0
|
croak qq{May not declare individual hash or array elements with $cmd} |
92
|
|
|
|
|
|
|
if $var =~ /\[[^\]]\]/ || $var =~ /\{[^\}]+\}/; |
93
|
0
|
0
|
|
|
|
0
|
croak qq{May not declare globs with $cmd ("$var")} if substr($var,0,1) eq '*'; |
94
|
0
|
|
|
|
|
0
|
croak qq{Invalid variable name "$var"}; |
95
|
|
|
|
|
|
|
} |
96
|
24
|
50
|
66
|
|
|
108
|
croak qq{Can't process "$cmd $var" line} if $eqs ne '=' && $eqs ne ';'; |
97
|
|
|
|
|
|
|
|
98
|
24
|
|
|
|
|
103
|
my $res = <
|
99
|
|
|
|
|
|
|
use vars qw($usevars$var);$isa |
100
|
|
|
|
|
|
|
push \@$export, qw($var); |
101
|
|
|
|
|
|
|
USE_AND_EXPORT |
102
|
|
|
|
|
|
|
|
103
|
24
|
50
|
66
|
|
|
92
|
if ($cmd eq 'ro' && $RO_ok) |
104
|
|
|
|
|
|
|
{ |
105
|
0
|
|
|
|
|
0
|
$res .= "Readonly::Readonly \\$var"; |
106
|
0
|
0
|
|
|
|
0
|
$res .= ' => ' if $eqs eq '='; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
else |
109
|
|
|
|
|
|
|
{ |
110
|
24
|
100
|
100
|
|
|
2447
|
carp "Readonly not available, making $var read/write" if $cmd eq 'ro' && !$nowarn; |
111
|
24
|
|
|
|
|
62
|
$res .= $var; |
112
|
24
|
100
|
|
|
|
68
|
$res .= ' = ' if $eqs eq '='; |
113
|
|
|
|
|
|
|
} |
114
|
24
|
100
|
|
|
|
61
|
$res .= $eqs if $eqs eq ';'; |
115
|
24
|
|
|
|
|
42
|
$usevars = $isa = ''; |
116
|
24
|
|
|
|
|
167
|
return $res; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
1; # Modules must return true, for silly historical reasons. |
121
|
|
|
|
|
|
|
__END__ |