line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Config::Plugin::TinyManifold; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
3097
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
27
|
|
4
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
24
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
4
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
91
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
1202
|
use Config::Tiny; |
|
1
|
|
|
|
|
1331
|
|
|
1
|
|
|
|
|
37
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
6
|
use vars qw(@EXPORT @ISA); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
238
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
@EXPORT = ('config_manifold'); |
13
|
|
|
|
|
|
|
@ISA = ('Exporter'); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our $VERSION = '1.01'; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# -------------------------------------------------- |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub config_manifold |
20
|
|
|
|
|
|
|
{ |
21
|
1
|
|
|
1
|
1
|
25
|
my($self, $file_name) = @_; |
22
|
1
|
|
50
|
|
|
5
|
$file_name ||= ''; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# Check [global]. |
25
|
|
|
|
|
|
|
|
26
|
1
|
|
|
|
|
9
|
my($config) = Config::Tiny -> read($file_name); |
27
|
|
|
|
|
|
|
|
28
|
1
|
50
|
|
|
|
295
|
croak 'Error: ' . Config::Tiny -> errstr . "\n" if (Config::Tiny -> errstr); |
29
|
|
|
|
|
|
|
|
30
|
1
|
|
|
|
|
7
|
my($section) = 'global'; |
31
|
1
|
50
|
|
|
|
10
|
$section = $$config{$section}{'section'} if ($$config{$section}); |
32
|
|
|
|
|
|
|
|
33
|
1
|
50
|
|
|
|
6
|
croak "Error: Config file '$file_name' does not contain the section '$section'\n" if (! $$config{$section}); |
34
|
|
|
|
|
|
|
|
35
|
1
|
|
|
|
|
13
|
return $$config{$section}; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
} # End of config_manifold. |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# -------------------------------------------------- |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
1; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=pod |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head1 NAME |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
Config::Plugin::TinyManifold - A plugin which uses Config::Tiny with 1 of N sections |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head1 Synopsis |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
package My::App; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
use strict; |
54
|
|
|
|
|
|
|
use warnings; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
use Config::Plugin::TinyManifold; # For config_manifold(). |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
use File::Spec; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# ------------------------------------------------ |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub marine |
63
|
|
|
|
|
|
|
{ |
64
|
|
|
|
|
|
|
my($self) = @_; |
65
|
|
|
|
|
|
|
my($config) = $self -> config_manifold(File::Spec -> catfile('some', 'dir', 'config.tiny.manifold.ini') ); |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
} # End of marine. |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# -------------------------------------------------- |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
1; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
t/config.tiny.manifold.ini ships with the L distro, and is used in the test file t/test.t. |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head1 Description |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
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. |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
But more than that, it uses a value from the config file to select 1 of N sections within that file as the whole config. See L for details. |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head1 Distributions |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
This module is available as a Unix-style distro (*.tgz). |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
See L |
86
|
|
|
|
|
|
|
for help on unpacking and installing distros. |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head1 Installation |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
Install L as you would for any C module: |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
Run: |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
cpanm Config::Plugin::TinyManifold |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
or run: |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sudo cpan Config::Plugin::TinyManifold |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
or unpack the distro, and then either: |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
perl Build.PL |
103
|
|
|
|
|
|
|
./Build |
104
|
|
|
|
|
|
|
./Build test |
105
|
|
|
|
|
|
|
sudo ./Build install |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
or: |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
perl Makefile.PL |
110
|
|
|
|
|
|
|
make (or dmake or nmake) |
111
|
|
|
|
|
|
|
make test |
112
|
|
|
|
|
|
|
make install |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head1 Constructor and Initialization |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
This module does not have, and does not need, a constructor. |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 Methods |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head2 config_manifold($file_name) |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
Returns a *.ini-style config file as a hashref. |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
Here, the [] indicate an optional parameter. |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
The $file_name is passed to L's read($file_name) method. |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
It uses a value from the config file to select 1 of N sections within that file as the whole config. |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
Specifically, the name of the global section is hard-coded as '[global]', and the name of the key within that is hard-coded as 'section'. |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
So, a sample config file, which ships as t/config.tiny.manifold.ini is: |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
[global] |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
# The 'section' key: |
137
|
|
|
|
|
|
|
# o Specifies which section to use after the [global] section ends. |
138
|
|
|
|
|
|
|
# o Case-sensitive options are /^(localhost|webhost)$/. |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
section = localhost |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
[localhost] |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
template_path = /home/ron/assets/templates/CGI/Snapp |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
[website] |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
template_path = /dev/shm/html/assets/templates/CGI/Snapp |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
Alternately, you could use sections called [global], [testing] and [production], and so on. |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=head1 FAQ |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=head2 When would I use this module? |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
In your sub-class of L for example, or anywhere else you want effortless access to a *.ini file which contains N alternate sections, and you wish to auto-select 1 of these sections. |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
For example, if you wish to load a config for use by a module such as L, try L or Config::Plugin::TinyManifold. |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=head2 Why didn't you call the exported method config()? |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
Because L allows both L and L to be used in the same code. |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=head2 Why don't you 'use Exporter;'? |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
It is not needed; it would be for documentation only. |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
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. |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=head2 What's the error message format? |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
Every message passed to croak matches /^Error/ and ends with "\n". |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=head2 What does 'manifold' mean, exactly? |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
My paper dictionary lists 8 meanings. The first 2 are: |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=over 4 |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=item 1: of many kinds; numerous and varied: I |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=item 2: having many different parts, elements, features, forms, etc. |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=back |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
So, rather like sections in a *.ini file... |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=head1 See Also |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
L |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
The following are all part of this set of distros: |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
L - A almost back-compat fork of CGI::Application |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
L - A template-free demo of CGI::Snapp using just 1 run mode |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
L - A template-free demo of CGI::Snapp using N run modes |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
L - A template-free demo of CGI::Snapp using CGI::Snapp::Plugin::Forward |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
L - A template-free demo of CGI::Snapp using Log::Handler::Plugin::DBI |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
L - A wrapper around CGI::Snapp::Demo::Four, to simplify using Log::Handler::Plugin::DBI |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
L - A plugin which uses Config::Tiny |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
L - A plugin which uses Config::Tiny with 1 of N sections |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
L - Persistent session data management |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
L - A plugin for Log::Handler using Log::Hander::Output::DBI |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
L - A helper for Log::Hander::Output::DBI to create your 'log' table |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
=head1 Machine-Readable Change Log |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
The file CHANGES was converted into Changelog.ini by L. |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
=head1 Version Numbers |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
Version numbers < 1.00 represent development versions. From 1.00 up, they are production versions. |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
=head1 Credits |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
Please read L, since a lot of the ideas for this module were copied from |
227
|
|
|
|
|
|
|
L. |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
=head1 Support |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
Email the author, or log a bug on RT: |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
L. |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
=head1 Author |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
L was written by Ron Savage Iron@savage.net.auE> in 2012. |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
Home page: L. |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
=head1 Copyright |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
Australian copyright (c) 2012, Ron Savage. |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
All Programs of mine are 'OSI Certified Open Source Software'; |
246
|
|
|
|
|
|
|
you can redistribute them and/or modify them under the terms of |
247
|
|
|
|
|
|
|
The Artistic License, a copy of which is available at: |
248
|
|
|
|
|
|
|
http://www.opensource.org/licenses/index.html |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
=cut |