| 1 | package CGI::Lazy::Config; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | 1 | ▶ | use JSON; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 1 | ▶ | use CGI::Lazy::Globals; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | #------------------------------------------------------------------------------- | ||||||||||
| 10 | 6 | ▶ | sub AUTOLOAD { | ||||||||
|
Subroutine
AUTOLOAD: called CC=3 SCAR=11.4
| |||||||||||
| 11 | 6 | my $self = shift; | |||||||||
| 12 | |||||||||||
| 13 | 6 | my $name = our $AUTOLOAD; | |||||||||
| 14 | 6 | ▶ | return if $name =~ /::DESTROY$/; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 15 | 6 | my @list = split "::", $name; | |||||||||
| 16 | 6 | my $value = pop @list; | |||||||||
| 17 | |||||||||||
| 18 | 6 | ▶ | if (@_) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 19 | 0 | return $self->{_config}->{$value} = shift; | |||||||||
| 20 | } else { | ||||||||||
| 21 | 6 | return $self->{_config}->{$value}; | |||||||||
| 22 | } | ||||||||||
| 23 | } | ||||||||||
| 24 | |||||||||||
| 25 | #------------------------------------------------------------------------------- | ||||||||||
| 26 | 0 | ▶ | sub configfile { | ||||||||
|
Subroutine
configfile: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 27 | 0 | my $self = shift; | |||||||||
| 28 | |||||||||||
| 29 | 0 | return $self->{_configfile}; | |||||||||
| 30 | } | ||||||||||
| 31 | |||||||||||
| 32 | #------------------------------------------------------------------------------- | ||||||||||
| 33 | 0 | ▶ | sub get { | ||||||||
|
Subroutine
get: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 34 | 0 | my $self = shift; | |||||||||
| 35 | 0 | my $prop = shift; | |||||||||
| 36 | |||||||||||
| 37 | 0 | return $self->{_config}{$prop}; | |||||||||
| 38 | } | ||||||||||
| 39 | |||||||||||
| 40 | #------------------------------------------------------------------------------- | ||||||||||
| 41 | 1 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=7 SCAR=31.3
Pod
documented
| |||||||||||
| 42 | 1 | my $class = shift; | |||||||||
| 43 | 1 | my $q = shift; | |||||||||
| 44 | 1 | my $filename = shift; | |||||||||
| 45 | |||||||||||
| 46 | 1 | my $json; | |||||||||
| 47 | my $conf; | ||||||||||
| 48 | |||||||||||
| 49 | 1 | ▶ | if (ref $filename) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 50 | 1 | $conf = $filename; | |||||||||
| 51 | } else { | ||||||||||
| 52 | 0 | eval { | |||||||||
| 53 | 0 | ▶ | open IF, "< $CONFIGROOT/$filename" or croak $!; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 54 | |||||||||||
| 55 | 0 | ▶ | while (<IF>) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 56 | 0 | ▶ | $json .= $_ unless ($_ =~ /^\s*#/); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 57 | } | ||||||||||
| 58 | 0 | close IF; | |||||||||
| 59 | }; | ||||||||||
| 60 | |||||||||||
| 61 | 0 | ▶ | if ($@) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 62 | 0 | $q->errorHandler->noConfig($filename); | |||||||||
| 63 | } | ||||||||||
| 64 | |||||||||||
| 65 | 0 | eval { | |||||||||
| 66 | 0 | $conf = from_json($json); | |||||||||
| 67 | }; | ||||||||||
| 68 | |||||||||||
| 69 | 0 | ▶ | if ($@) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 70 | 0 | $q->errorHandler->badConfig($filename); | |||||||||
| 71 | } | ||||||||||
| 72 | } | ||||||||||
| 73 | |||||||||||
| 74 | 1 | my $self = {_q => $q, _config =>$conf, _configfile => $filename}; | |||||||||
| 75 | |||||||||||
| 76 | 1 | bless $self, $class; | |||||||||
| 77 | |||||||||||
| 78 | 1 | return $self; | |||||||||
| 79 | } | ||||||||||
| 80 | |||||||||||
| 81 | #------------------------------------------------------------------------------- | ||||||||||
| 82 | 0 | ▶ | sub set { | ||||||||
|
Subroutine
set: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 83 | 0 | my $self = shift; | |||||||||
| 84 | 0 | my $name = shift; | |||||||||
| 85 | 0 | my $value = shift; | |||||||||
| 86 | |||||||||||
| 87 | 0 | $self->{_config}{$name} = $value; | |||||||||
| 88 | } | ||||||||||
| 89 | |||||||||||
| 90 | 1 | 1 | |||||||||
| 91 | |||||||||||
| 92 | __END__ | ||||||||||