line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Config::Plugin::Tiny; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
2794
|
use strict; |
|
2
|
|
|
|
|
10
|
|
|
2
|
|
|
|
|
78
|
|
4
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
67
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
11
|
use Carp; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
195
|
|
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
1015
|
use Config::Tiny; |
|
2
|
|
|
|
|
2129
|
|
|
2
|
|
|
|
|
87
|
|
9
|
|
|
|
|
|
|
|
10
|
2
|
|
|
2
|
|
15
|
use vars qw(@EXPORT @ISA); |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
397
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
@EXPORT = ('config_tiny'); |
13
|
|
|
|
|
|
|
@ISA = ('Exporter'); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our $VERSION = '1.02'; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# -------------------------------------------------- |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub config_tiny |
20
|
|
|
|
|
|
|
{ |
21
|
1
|
|
|
1
|
1
|
116
|
my($self, $file_name) = @_; |
22
|
1
|
|
50
|
|
|
3
|
$file_name ||= ''; |
23
|
1
|
|
|
|
|
7
|
my($config) = Config::Tiny -> read($file_name); |
24
|
|
|
|
|
|
|
|
25
|
1
|
50
|
|
|
|
213
|
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 Repository |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
L |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=head1 See Also |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
L |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
The following are all part of this set of distros: |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
L - A almost back-compat fork of CGI::Application |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
L - A template-free demo of CGI::Snapp using just 1 run mode |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
L - A template-free demo of CGI::Snapp using N run modes |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
L - A template-free demo of CGI::Snapp using CGI::Snapp::Plugin::Forward |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
L - A template-free demo of CGI::Snapp using Log::Handler::Plugin::DBI |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
L - A wrapper around CGI::Snapp::Demo::Four, to simplify using Log::Handler::Plugin::DBI |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
L - A plugin which uses Config::Tiny |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
L - A plugin which uses Config::Tiny with 1 of N sections |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
L - Persistent session data management |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
L - A plugin for Log::Handler using Log::Hander::Output::DBI |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
L - A helper for Log::Hander::Output::DBI to create your 'log' table |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=head1 Machine-Readable Change Log |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
The file CHANGES was converted into Changelog.ini by L. |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=head1 Version Numbers |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
Version numbers < 1.00 represent development versions. From 1.00 up, they are production versions. |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=head1 Credits |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
Please read L, since a lot of the ideas for this module were copied from |
187
|
|
|
|
|
|
|
L. |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=head1 Support |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
Bugs should be reported via the CPAN bug tracker at |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
L. |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
=head1 Author |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
L was written by Ron Savage Iron@savage.net.auE> in 2012. |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
Home page: L. |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=head1 Copyright |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
Australian copyright (c) 2012, Ron Savage. |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
All Programs of mine are 'OSI Certified Open Source Software'; |
206
|
|
|
|
|
|
|
you can redistribute them and/or modify them under the terms of |
207
|
|
|
|
|
|
|
The Artistic License, a copy of which is available at: |
208
|
|
|
|
|
|
|
http://www.opensource.org/licenses/index.html |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
=cut |