File Coverage

blib/lib/Config/Plugin/Tiny.pm
Criterion Covered Total %
statement 20 20 100.0
branch 1 2 50.0
condition 1 2 50.0
subroutine 6 6 100.0
pod 1 1 100.0
total 29 31 93.5


line stmt bran cond sub pod time code
1             package Config::Plugin::Tiny;
2              
3 1     1   2890 use strict;
  1         3  
  1         29  
4 1     1   4 use warnings;
  1         2  
  1         20  
5              
6 1     1   5 use Carp;
  1         2  
  1         153  
7              
8 1     1   840 use Config::Tiny;
  1         1086  
  1         34  
9              
10 1     1   5 use vars qw(@EXPORT @ISA);
  1         2  
  1         304  
11              
12             @EXPORT = ('config_tiny');
13             @ISA = ('Exporter');
14              
15             our $VERSION = '1.01';
16              
17             # --------------------------------------------------
18              
19             sub config_tiny
20             {
21 1     1 1 64 my($self, $file_name) = @_;
22 1   50     4 $file_name ||= '';
23 1         11 my($config) = Config::Tiny -> read($file_name);
24              
25 1 50       269 croak 'Error: ' . Config::Tiny -> errstr . "\n" if (Config::Tiny -> errstr);
26              
27 1         9 return $config;
28              
29             } # End of config_tiny.
30              
31             # --------------------------------------------------
32              
33             1;
34              
35             =pod
36              
37             =head1 NAME
38              
39             Config::Plugin::Tiny - A plugin which uses Config::Tiny
40              
41             =head1 Synopsis
42              
43             package My::App;
44              
45             use strict;
46             use warnings;
47              
48             use Config::Plugin::Tiny; # For config_tiny().
49              
50             use File::Spec;
51              
52             # ------------------------------------------------
53              
54             sub marine
55             {
56             my($self) = @_;
57             my($config) = $self -> config_tiny(File::Spec -> catfile('some', 'dir', 'config.tiny.ini') );
58              
59             } # End of marine.
60              
61             # --------------------------------------------------
62              
63             1;
64              
65             t/config.tiny.ini ships with the L distro, and is used in the test file t/test.t.
66              
67             =head1 Description
68              
69             When you 'use' this module (as in the Synopsis), it automatically imports into your class the method L to give you access to config data stored in an *.ini file.
70              
71             =head1 Distributions
72              
73             This module is available as a Unix-style distro (*.tgz).
74              
75             See L
76             for help on unpacking and installing distros.
77              
78             =head1 Installation
79              
80             Install L as you would for any C module:
81              
82             Run:
83              
84             cpanm Config::Plugin::Tiny
85              
86             or run:
87              
88             sudo cpan Config::Plugin::Tiny
89              
90             or unpack the distro, and then either:
91              
92             perl Build.PL
93             ./Build
94             ./Build test
95             sudo ./Build install
96              
97             or:
98              
99             perl Makefile.PL
100             make (or dmake or nmake)
101             make test
102             make install
103              
104             =head1 Constructor and Initialization
105              
106             This module does not have, and does not need, a constructor.
107              
108             =head1 Methods
109              
110             =head2 config_tiny($file_name)
111              
112             Returns a *.ini-style config file as a hashref.
113              
114             Here, the [] indicate an optional parameter.
115              
116             The $file_name is passed to L's read($file_name) method.
117              
118             =head1 FAQ
119              
120             =head2 When would I use this module?
121              
122             In your sub-class of L for example, or anywhere else you want effortless access to a *.ini file.
123              
124             For example, if you wish to load a config for use by a module such as L, try Config::Plugin::Tiny or L.
125              
126             =head2 Why didn't you call the exported method config()?
127              
128             Because L allows both L and L to be used in the same code.
129              
130             =head2 Can this module be used in any non-CGI-Snapp module?
131              
132             Yes.
133              
134             =head2 Why don't you 'use Exporter;'?
135              
136             It is not needed; it would be for documentation only.
137              
138             For the record, Exporter V 5.567 ships with Perl 5.8.0. That's what I had in Build.PL and Makefile.PL until I tested the fact I can omit it.
139              
140             =head2 What's the error message format?
141              
142             Every message passed to croak matches /^Error/ and ends with "\n".
143              
144             =head1 See Also
145              
146             L
147              
148             The following are all part of this set of distros:
149              
150             L - A almost back-compat fork of CGI::Application
151              
152             L - A template-free demo of CGI::Snapp using just 1 run mode
153              
154             L - A template-free demo of CGI::Snapp using N run modes
155              
156             L - A template-free demo of CGI::Snapp using CGI::Snapp::Plugin::Forward
157              
158             L - A template-free demo of CGI::Snapp using Log::Handler::Plugin::DBI
159              
160             L - A wrapper around CGI::Snapp::Demo::Four, to simplify using Log::Handler::Plugin::DBI
161              
162             L - A plugin which uses Config::Tiny
163              
164             L - A plugin which uses Config::Tiny with 1 of N sections
165              
166             L - Persistent session data management
167              
168             L - A plugin for Log::Handler using Log::Hander::Output::DBI
169              
170             L - A helper for Log::Hander::Output::DBI to create your 'log' table
171              
172             =head1 Machine-Readable Change Log
173              
174             The file CHANGES was converted into Changelog.ini by L.
175              
176             =head1 Version Numbers
177              
178             Version numbers < 1.00 represent development versions. From 1.00 up, they are production versions.
179              
180             =head1 Credits
181              
182             Please read L, since a lot of the ideas for this module were copied from
183             L.
184              
185             =head1 Support
186              
187             Email the author, or log a bug on RT:
188              
189             L.
190              
191             =head1 Author
192              
193             L was written by Ron Savage Iron@savage.net.auE> in 2012.
194              
195             Home page: L.
196              
197             =head1 Copyright
198              
199             Australian copyright (c) 2012, Ron Savage.
200              
201             All Programs of mine are 'OSI Certified Open Source Software';
202             you can redistribute them and/or modify them under the terms of
203             The Artistic License, a copy of which is available at:
204             http://www.opensource.org/licenses/index.html
205              
206             =cut