| 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 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | package Config::Vars; | ||||||||||||||||||||||||||||
| 13 | 5 | ▶ | use vars qw/$VERSION @CARP_NOT/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 5 | $VERSION = 0.01; | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 5 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 5 | ▶ | use Filter::Simple; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 5 | @CARP_NOT = qw(Filter::Simple); | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | # Can we use Readonly? | ||||||||||||||||||||||||||||
| 21 | 5 | ▶ | use vars '$RO_ok'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | 5 | my $nowarn; # if true, don't kvetch about Readonly not being available | |||||||||||||||||||||||||||
| 23 | my $export; # Exporter array name | ||||||||||||||||||||||||||||
| 24 | 5 | eval { require 'Readonly.pm' }; | |||||||||||||||||||||||||||
| 25 | 5 | ▶ | $RO_ok = 1 unless $@; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | # These get set by import() at the begining of each module; reset by xform. | ||||||||||||||||||||||||||||
| 28 | 5 | my $usevars; | |||||||||||||||||||||||||||
| 29 | my $isa; | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | sub import | ||||||||||||||||||||||||||||
| 33 | 16 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
import: called CC=6 SCAR=18.3
| |||||||||||||||||||||||||||||
| 34 | 16 | my $pkg = shift; | |||||||||||||||||||||||||||
| 35 | 16 | my @errs; | |||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | # Module-by-module init | ||||||||||||||||||||||||||||
| 38 | 16 | $nowarn = 0; | |||||||||||||||||||||||||||
| 39 | 16 | $export = 'EXPORT_OK'; | |||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 16 | foreach my $opt (@_) | |||||||||||||||||||||||||||
| 42 | { | ||||||||||||||||||||||||||||
| 43 | 2 | ▶ | if ($opt eq 'nowarn') | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 44 | { | ||||||||||||||||||||||||||||
| 45 | 1 | $nowarn = 1; | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | elsif ($opt eq 'exportall') | ||||||||||||||||||||||||||||
| 48 | { | ||||||||||||||||||||||||||||
| 49 | 1 | $export = 'EXPORT'; | |||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | else | ||||||||||||||||||||||||||||
| 52 | { | ||||||||||||||||||||||||||||
| 53 | 0 | push @errs, $opt; | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | 16 | ▶ | my $s = @errs > 1? 's' : ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | 16 | ▶ | croak "Unknown Config::Vars option$s (@errs)" if @errs; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 16 | $usevars = "\@$export \@ISA "; | |||||||||||||||||||||||||||
| 60 | 16 | $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 | 16 | ▶ | code => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 73 | # print STDERR "BEFORE: [$_]\n"; | ||||||||||||||||||||||||||||
| 74 | 16 | 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 | 24 | /xform($1,$2,$3)/gemx; | |||||||||||||||||||||||||||
| 81 | # print STDERR "AFTER: [$_]\n"; | ||||||||||||||||||||||||||||
| 82 | 5 | }; | |||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | sub xform | ||||||||||||||||||||||||||||
| 86 | 24 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
xform: called CC=16 SCAR=34.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 87 | 24 | my ($cmd, $var, $eqs) = @_; | |||||||||||||||||||||||||||
| 88 | 24 | ▶ | croak qq{Can't process "$cmd $var $eqs" line} if $cmd ne 'var' && $cmd ne 'ro'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$cmd ne "var" and $cmd ne "ro"
MC/DC0%0/2
$cmd ne "var" and $cmd ne "ro"
$cmd ne "var"
$cmd ne "ro"
Truth table66%2/3
A and B
A= $cmd ne "var"B= $cmd ne "ro"
| |||||||||||||||||||||||||||||
| 89 | 24 | ▶ | unless ($var =~ /^[\$\@\%][_[:alpha:]]\w+/) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | { | ||||||||||||||||||||||||||||
| 91 | 0 | ▶ | croak qq{May not declare individual hash or array elements with $cmd} | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$var =~ /\[[^\]]\]/ or $var =~ /\{[^\}]+\}/
MC/DC0%0/2
$var =~ /\[[^\]]\]/ or $var =~ /\{[^\}]+\}/
$var =~ /\[[^\]]\]/
$var =~ /\{[^\}]+\}/
Truth table0%0/3
A or B
A= $var =~ /\[[^\]]\]/B= $var =~ /\{[^\}]+\}/
| |||||||||||||||||||||||||||||
| 92 | if $var =~ /\[[^\]]\]/ || $var =~ /\{[^\}]+\}/; | ||||||||||||||||||||||||||||
| 93 | 0 | ▶ | croak qq{May not declare globs with $cmd ("$var")} if substr($var,0,1) eq '*'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | 0 | croak qq{Invalid variable name "$var"}; | |||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | 24 | ▶ | croak qq{Can't process "$cmd $var" line} if $eqs ne '=' && $eqs ne ';'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$eqs ne "=" and $eqs ne ";"
MC/DC0%0/2
$eqs ne "=" and $eqs ne ";"
$eqs ne "="
$eqs ne ";"
Truth table66%2/3
A and B
A= $eqs ne "="B= $eqs ne ";"
| |||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 24 | my $res = <<USE_AND_EXPORT; | |||||||||||||||||||||||||||
| 99 | use vars qw($usevars$var);$isa | ||||||||||||||||||||||||||||
| 100 | push \@$export, qw($var); | ||||||||||||||||||||||||||||
| 101 | USE_AND_EXPORT | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 24 | ▶ | if ($cmd eq 'ro' && $RO_ok) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$cmd eq "ro" and $Config::Vars::RO_ok
MC/DC0%0/2
$cmd eq "ro" and $Config::Vars::RO_ok
$cmd eq "ro"
$Config::Vars::RO_ok
Truth table66%2/3
A and B
A= $cmd eq "ro"B= $Config::Vars::RO_ok
| |||||||||||||||||||||||||||||
| 104 | { | ||||||||||||||||||||||||||||
| 105 | 0 | $res .= "Readonly::Readonly \\$var"; | |||||||||||||||||||||||||||
| 106 | 0 | ▶ | $res .= ' => ' if $eqs eq '='; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | else | ||||||||||||||||||||||||||||
| 109 | { | ||||||||||||||||||||||||||||
| 110 | 24 | ▶ | carp "Readonly not available, making $var read/write" if $cmd eq 'ro' && !$nowarn; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$cmd eq "ro" and not $nowarn
MC/DC100%2/2
$cmd eq "ro" and not $nowarn
$cmd eq "ro"
not $nowarn
Truth table100%3/3
A and not(B)
A= $cmd eq "ro"B= not $nowarn
| |||||||||||||||||||||||||||||
| 111 | 24 | $res .= $var; | |||||||||||||||||||||||||||
| 112 | 24 | ▶ | $res .= ' = ' if $eqs eq '='; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||
| 114 | 24 | ▶ | $res .= $eqs if $eqs eq ';'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 115 | 24 | $usevars = $isa = ''; | |||||||||||||||||||||||||||
| 116 | 24 | return $res; | |||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 5 | 1; # Modules must return true, for silly historical reasons. | |||||||||||||||||||||||||||
| 121 | __END__ | ||||||||||||||||||||||||||||