File Coverage

blib/lib/Config/Onion/Simple.pm
Criterion Covered Total %
statement 17 17 100.0
branch n/a
condition 2 3 66.6
subroutine 7 7 100.0
pod 2 2 100.0
total 28 29 96.5


line stmt bran cond sub pod time code
1             package Config::Onion::Simple;
2              
3 2     2   32961 use strict;
  2         5  
  2         73  
4 2     2   11 use warnings;
  2         3  
  2         83  
5              
6             our $VERSION = 1.004;
7              
8 2     2   549 use Config::Onion;
  2         5  
  2         75  
9              
10 2     2   15 use base 'Exporter';
  2         4  
  2         335  
11             BEGIN {
12 2     2   6 our @EXPORT = ();
13 2         5 our @EXPORT_OK = qw(
14             cfg
15             cfg_obj
16             );
17 2         250 our %EXPORT_TAGS = (
18             all => [ @EXPORT, @EXPORT_OK ],
19             );
20             }
21              
22             my $cfg_obj;
23              
24 1     1 1 846 sub cfg { cfg_obj()->get }
25              
26 2   66 2 1 29 sub cfg_obj { $cfg_obj ||= Config::Onion->new }
27              
28             1;
29              
30             =pod
31              
32             =head1 NAME
33              
34             Config::Onion::Simple - Simple interface to a Config::Onion singleton
35              
36             =head1 VERSION
37              
38             version 1.004
39              
40             =head1 SYNOPSIS
41              
42             use Config::Onion::Simple qw( cfg cfg_obj );
43              
44             cfg_obj->load('myapp');
45             my $setting = cfg->{setting};
46              
47             =head1 DESCRIPTION
48              
49             It is often useful for a single master configuration to be shared across
50             multiple modules in an application. Config::Onion::Simple provides an
51             interface to do this without requiring any of those modules to know about
52             each other.
53              
54             =head1 EXPORTABLE FUNCTIONS
55              
56             Config::Onion::Simple exports nothing by default. The following functions
57             are exported only on request.
58              
59             =head2 cfg
60              
61             Returns a reference to the complete configuration hash managed by the
62             Config::Onion singleton. This hash should be treated as read-only, as any
63             changes will be lost if the configuration is altered using the underlying
64             Config::Onion instance's methods.
65              
66             Calling C is equivalent to calling C<< cfg_obj->get >>.
67              
68             =head2 cfg_obj
69              
70             Returns a reference to the Config::Onion singleton. Use this object's methods
71             to make any changes to the configuration.
72              
73             =head1 SEE ALSO
74              
75             L
76              
77             =head1 AUTHOR
78              
79             Dave Sherohman
80              
81             =head1 COPYRIGHT AND LICENSE
82              
83             This software is copyright (c) 2014 by Lund University Library.
84              
85             This is free software; you can redistribute it and/or modify it under
86             the same terms as the Perl 5 programming language system itself.
87              
88             =cut
89              
90             __END__