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