| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package CGI::Application::Standard::Config; |
|
2
|
1
|
|
|
1
|
|
33881
|
use base 'Exporter'; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
91
|
|
|
3
|
1
|
|
|
1
|
|
6
|
use vars (qw/@EXPORT $VERSION/); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
244
|
|
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
$VERSION = '1.01'; |
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
# Note: We are loading the config plugin into our callers |
|
8
|
|
|
|
|
|
|
# namespace, not our own! |
|
9
|
|
|
|
|
|
|
sub import { |
|
10
|
1
|
|
|
1
|
|
6
|
my $class = shift; |
|
11
|
1
|
|
|
|
|
3
|
my $app = caller; |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# Export a stub config if there is not one defined already. |
|
14
|
1
|
50
|
|
|
|
3
|
if (not _meet_config_standard($app) ) { |
|
15
|
1
|
|
|
|
|
9
|
push @EXPORT, (qw/config std_config/); |
|
16
|
|
|
|
|
|
|
} |
|
17
|
|
|
|
|
|
|
} |
|
18
|
|
|
|
|
|
|
|
|
19
|
0
|
|
|
0
|
1
|
0
|
sub config { return undef }; |
|
20
|
0
|
|
|
0
|
1
|
0
|
sub std_config { return 1 }; |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub _meet_config_standard { |
|
23
|
1
|
|
|
1
|
|
2
|
my $app = shift; |
|
24
|
1
|
50
|
33
|
|
|
17
|
if ( $app->can('config') |
|
25
|
|
|
|
|
|
|
# If they declared they meet the standard, we trust 'em. |
|
26
|
|
|
|
|
|
|
and $app->can('std_config') ) { |
|
27
|
0
|
|
|
|
|
0
|
return 1; |
|
28
|
|
|
|
|
|
|
} |
|
29
|
|
|
|
|
|
|
else { |
|
30
|
1
|
|
|
|
|
5
|
return 0; |
|
31
|
|
|
|
|
|
|
} |
|
32
|
|
|
|
|
|
|
} |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=pod |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
Last updated: Sat Feb 18 23:42:29 EST 2006 |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head1 NAME |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
CGI::Application::Standard::Config -- Define a standard configuration API for CGI::Application |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head1 RATIONALE |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
This module defines a minimum standard interface that configuration plugins for |
|
45
|
|
|
|
|
|
|
CGI::Application should meet. Having such a standard allows other plugin |
|
46
|
|
|
|
|
|
|
authors to rely on basic configuration functionality without coding exceptions |
|
47
|
|
|
|
|
|
|
for several configuration modules, or giving up on such integration. |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head2 For Average Users |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
Simply load the config plugin before other modules that might use it: |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
use CGI::Application::Plugin::ConfigAuto; |
|
56
|
|
|
|
|
|
|
use CGI::Application::Plugin::Session; |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head2 For Configuration plugin authors |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
Configuration plugin authors only need to follow the standards documented below. |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head2 For other plugin authors who wish to rely on the standard |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
Plugin authors who want to possibly use this standard can do so by simply |
|
65
|
|
|
|
|
|
|
using this module: |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
package CGI::Application::Plugin::Session; |
|
68
|
|
|
|
|
|
|
use CGI::Application::Standard::Config; |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
If a standards complaint config module hasn't already been loaded a stub for |
|
71
|
|
|
|
|
|
|
L will be added which will safely return C. |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head3 Example use by another plugin |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
Here code first tries to get configuration details first from a |
|
76
|
|
|
|
|
|
|
config file, then from options passed to a plugin-specific config |
|
77
|
|
|
|
|
|
|
method, and finally applies defaults if no configuration options are found. |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
my $session_options = $self->config('Session_options') |
|
80
|
|
|
|
|
|
|
|| $self->session_config() |
|
81
|
|
|
|
|
|
|
|| $self->session_defaults; |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head1 Standard Interface Definition |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
The following defines a minimum standard for configuration plugins to meet. |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
Config plugins are free to provide to additional functionality. |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
Configuration plugins are also encourage to explicity document that |
|
90
|
|
|
|
|
|
|
they are using C. |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
If there are existing methods that follow the standard but have |
|
93
|
|
|
|
|
|
|
different names, you can use this example to always export your method: |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub import { |
|
96
|
|
|
|
|
|
|
my $app = caller; |
|
97
|
|
|
|
|
|
|
no strict 'refs'; |
|
98
|
|
|
|
|
|
|
my $full_name = $app . '::config'; |
|
99
|
|
|
|
|
|
|
# Change cfg to your config()-compliant method name |
|
100
|
|
|
|
|
|
|
*$full_name = \&cfg; |
|
101
|
|
|
|
|
|
|
CGI::Application::Plugin::YourNameHere->export_to_level(1,@_); |
|
102
|
|
|
|
|
|
|
} |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head2 $self->std_config |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
This method should be exported by default to simply declare that you meet the |
|
107
|
|
|
|
|
|
|
standard report which version of the standard you meet. This simple |
|
108
|
|
|
|
|
|
|
implementation is recommended: |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub std_config { return 1; } |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head2 $self->config |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
The intended use is to load to read-only configuration details once |
|
115
|
|
|
|
|
|
|
from a config file at start up time. |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
This service is provided by plugins (list below). They must support at |
|
118
|
|
|
|
|
|
|
at least this syntax: |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
my $value = $self->config('key'); |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
By default, C simply returns undef, making it safe for other |
|
123
|
|
|
|
|
|
|
plugins to directly to check if C<$self->config('key')> returns the |
|
124
|
|
|
|
|
|
|
value it needs. |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
config() must be exported by default. |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
For applications that need little configuration, L is not |
|
129
|
|
|
|
|
|
|
necessary-- using C in an instance script should suffice. |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
Also, the C is the appropriate method to use to set a |
|
132
|
|
|
|
|
|
|
configuration value at run time. |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
Configuration plugins that provide at least this basic API include: |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=over 4 |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=item L. |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=back |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=cut |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head3 Standard config variables |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
Users are encouraged to use these standard config variable names, to |
|
147
|
|
|
|
|
|
|
ease compatibility between plugins: |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
ROOT_URI - A URI corresponding to the project root (http://foo.com/proj ) |
|
150
|
|
|
|
|
|
|
ROOT_DIR - a file system path to the same location ( /home/joe/www/proj ) |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
All-caps are used to denote that config variables are essentially global |
|
153
|
|
|
|
|
|
|
constants. |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
Why URI and not URL? The wikipedia explains: |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
The contemporary point of view among the working group that oversees URIs is |
|
158
|
|
|
|
|
|
|
that the terms URL and URN are context-dependent aspects of URI and rarely |
|
159
|
|
|
|
|
|
|
need to be distinguished. Furthermore, the term URL is increasingly becoming |
|
160
|
|
|
|
|
|
|
obsolete, as it is rarely necessary to differentiate between URLs and URIs, |
|
161
|
|
|
|
|
|
|
in general. |
|
162
|
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=head1 Standard Version |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
This is 1.0 of the CGI::Application L standard. |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=head1 AUTHOR |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
Written by Mark Stosberg with input from the |
|
170
|
|
|
|
|
|
|
CGI::Application community. |
|
171
|
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=head1 COPYRIGHT and LICENSE |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
Copyright (C) 2008, Mark Stosberg. All rights reserved. |
|
175
|
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify it under |
|
177
|
|
|
|
|
|
|
the same terms as Perl itself. |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=cut |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
1; |
|
182
|
|
|
|
|
|
|
|