| 1 | package Config::SL; | ||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||
| 6 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||
| 8 | Config::SL - Configuration file abstraction for Silver Lining applications | ||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||
| 10 | =head1 ABSTRACT | ||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||
| 12 | use Config::SL; | ||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||
| 14 | $cfg = Config::SL->new; | ||||||||||||||||||||||||||||||||||||||||
| 15 | $val = $cfg->key; | ||||||||||||||||||||||||||||||||||||||||
| 16 | @vals = $cfg->key; | ||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||
| 18 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||
| 20 | This package is responsible for handling Silver Lining configuration data. | ||||||||||||||||||||||||||||||||||||||||
| 21 | It should make our lives less complex. | ||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||
| 23 | It is an abstraction of Config::ApacheFormat, and looks for the configuration | ||||||||||||||||||||||||||||||||||||||||
| 24 | file sl.conf in various locations. | ||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||
| 26 | =cut | ||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||
| 28 | 1 | our $VERSION = 0.01; | |||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||
| 30 | 1 | our ( $config, $conf_dir ); | |||||||||||||||||||||||||||||||||||||||
| 31 | 1 | our $file = 'sl.conf'; | |||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||
| 33 | 1 | ▶ | use base 'Config::ApacheFormat'; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 34 | 1 | ▶ | use FindBin; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||
| 36 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=11 SCAR=33.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 37 | 1 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||
| 39 | 1 | ▶ | return $config if $config; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||
| 41 | 1 | my @config_files; | |||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||
| 43 | # check the local conf dir first | ||||||||||||||||||||||||||||||||||||||||
| 44 | 1 | ▶ | if ( -d "./conf" && ( -e "./conf/$file" ) ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
Condition33%1/3
-d "./conf" and -e "./conf/$Config::SL::file"
MC/DC0%0/2
-d "./conf" and -e "./conf/$Config::SL::file"
-d "./conf"
-e "./conf/$Config::SL::file"
Truth table33%1/3
A and B
A= -d "./conf"B= -e "./conf/$Config::SL::file"
| |||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||
| 46 | 1 | $conf_dir = "./conf"; | |||||||||||||||||||||||||||||||||||||||
| 47 | 1 | @config_files = ("$conf_dir/$file"); | |||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||
| 50 | ▶ | elsif ( -d "$FindBin::Bin/../conf" && ( -e "$FindBin::Bin/../conf/$file" ) ) | |||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
-d "$FindBin::Bin/../conf" and -e "$FindBin::Bin/../conf/$Config::SL::file"
MC/DC0%0/2
-d "$FindBin::Bin/../conf" and -e "$FindBin::Bin/../conf/$Config::SL::file"
-d "$FindBin::Bin/../conf"
-e "$FindBin::Bin/../conf/$Config::SL::file"
Truth table0%0/3
A and B
A= -d "$FindBin::Bin/../conf"B= -e "$FindBin::Bin/../conf/$Config::SL::file"
| |||||||||||||||||||||||||||||||||||||||||
| 51 | { | ||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||
| 53 | # development | ||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | $conf_dir = "$FindBin::Bin/../conf"; | |||||||||||||||||||||||||||||||||||||||
| 55 | 0 | @config_files = ( "$conf_dir/$file", "$conf_dir/../$file" ); | |||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||
| 57 | # then check for a global conf file | ||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||
| 59 | elsif ( -e "/etc/sl/$file" ) { | ||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||
| 61 | # global sl dir | ||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | $conf_dir = "/etc/sl"; | |||||||||||||||||||||||||||||||||||||||
| 63 | 0 | @config_files = ("$conf_dir/$file"); | |||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||
| 65 | elsif ( -e "/etc/$file" ) { | ||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||
| 67 | # global etc | ||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | $conf_dir = "/etc"; | |||||||||||||||||||||||||||||||||||||||
| 69 | 0 | @config_files = ("$conf_dir/$file"); | |||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||
| 71 | else { | ||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | die "\nNo file $file found in " | |||||||||||||||||||||||||||||||||||||||
| 73 | . "$FindBin::Bin/../conf/ or /etc/sl/!\n"; | ||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||
| 76 | # we have a configuration file to work with, so get to work | ||||||||||||||||||||||||||||||||||||||||
| 77 | 1 | $config = $class->SUPER::new(); | |||||||||||||||||||||||||||||||||||||||
| 78 | 1 | my $read; | |||||||||||||||||||||||||||||||||||||||
| 79 | 1 | foreach my $config_file (@config_files) { | |||||||||||||||||||||||||||||||||||||||
| 80 | 1 | ▶ | next unless ( -e $config_file ); | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 81 | 1 | $config->read($config_file); | |||||||||||||||||||||||||||||||||||||||
| 82 | 1 | $read++; | |||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||
| 84 | 1 | ▶ | die "\nNo config files read! conf_dir $conf_dir\n" unless $read; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||
| 86 | 1 | $config->autoload_support(1); | |||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||
| 88 | 1 | return $config; | |||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | ▶ | sub sl_debug { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
sl_debug: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | my $config = shift; | |||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | return $ENV{SL_DEBUG}; | |||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | ▶ | sub conf_dir { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
conf_dir: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||
| 99 | 0 | return $conf_dir; | |||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||
| 102 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||
| 104 | Copyright 2010 Silver Lining Networks - All Rights Reserved. | ||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||
| 106 | This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||
| 108 | =cut | ||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||
| 110 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||