File Coverage

blib/lib/BBS/Perm/Config.pm
Criterion Covered Total %
statement 40 43 93.0
branch 4 6 66.6
condition 1 3 33.3
subroutine 10 10 100.0
pod 5 5 100.0
total 60 67 89.5


line stmt bran cond sub pod time code
1             package BBS::Perm::Config;
2              
3 2     2   58506 use warnings;
  2         4  
  2         74  
4 2     2   9 use strict;
  2         4  
  2         60  
5 2     2   10 use Carp;
  2         7  
  2         277  
6              
7             BEGIN {
8 2     2   4 local $@;
9 2         4 eval { require YAML::Syck; };
  2         893  
10 2 50       2074 if ($@) {
11 0         0 require YAML;
12 0         0 *_LoadFile = *YAML::LoadFile;
13 0         0 *_DumpFile = *YAML::DumpFile;
14             }
15             else {
16 2         7 *_LoadFile = *YAML::Syck::LoadFile;
17 2         688 *_DumpFile = *YAML::Syck::DumpFile;
18             }
19             }
20              
21             sub new {
22 3     3 1 436 my $class = shift;
23 3         8 my $self = {};
24 3   33     24 bless $self, ref $class || $class;
25 3         10 my %opt = @_;
26 3 100       10 if ( $opt{file} ) {
27 2         10 $self->{file} = $opt{file};
28 2         8 $self->load( $opt{file} );
29             }
30 3         11 return $self;
31             }
32              
33             sub load {
34 3     3 1 445 my $self = shift;
35 3         13 $self->{config} = _LoadFile(shift);
36 3         1420 $self->_tidy;
37             }
38              
39             sub _tidy {
40 3     3   6 my $self = shift;
41 3         5 for my $site ( grep { $_ ne 'global' } keys %{ $self->{config} } ) {
  9         20  
  3         12  
42 6         9 for ( keys %{ $self->{config}{global} } ) {
  6         18  
43 24 50       98 $self->{config}{$site}{$_} = $self->{config}{global}{$_}
44             unless defined $self->{config}{$site}{$_};
45             }
46             }
47             }
48              
49             sub sites {
50 3     3 1 1139 my $self = shift;
51 3         4 return grep { $_ ne 'global' } keys %{ $self->{config} };
  9         53  
  3         9  
52             }
53              
54             sub setting {
55 4     4 1 2253 my ( $self, $site ) = @_;
56 4         18 return $self->{config}{$site};
57             }
58              
59             sub file {
60 1     1 1 6 return shift->{file};
61             }
62              
63             1;
64              
65             __END__