File Coverage

blib/lib/Rubric/Config.pm
Criterion Covered Total %
statement 21 21 100.0
branch 6 6 100.0
condition n/a
subroutine 9 9 100.0
pod 1 1 100.0
total 37 37 100.0


line stmt bran cond sub pod time code
1 16     16   1631847 use strict;
  16         147  
  16         370  
2 16     16   62 use warnings;
  16         21  
  16         594  
3             # ABSTRACT: the configuration data for a Rubric
4              
5             use parent qw(Class::Accessor);
6 16     16   4063  
  16         3037  
  16         68  
7             #pod =head1 DESCRIPTION
8             #pod
9             #pod Rubric::Config provides access to the configuration data for a Rubric. The
10             #pod basic implementation stores its configuration in YAML in a text file in the
11             #pod current working directory. By default, Rubric::Config looks for C<rubric.yml>,
12             #pod but an alternate filename may be passed when using the module:
13             #pod
14             #pod use Rubric::Config ".rubric_yml";
15             #pod
16             #pod =cut
17              
18             use YAML::XS ();
19 16     16   33480  
  16         34512  
  16         3458  
20             my $config_filename = $ENV{RUBRIC_CONFIG_FILE} || 'rubric.yml';
21              
22             my ($class) = shift;
23             $config_filename = shift if @_;
24 70     70   611 }
25 70 100       6517  
26             #pod =head1 SETTINGS
27             #pod
28             #pod These configuration settings can all be retrieved by methods of the same name.
29             #pod
30             #pod =over 4
31             #pod
32             #pod =item * dsn
33             #pod
34             #pod the DSN to be used by Rubric::DBI to connect to the Rubric's database
35             #pod
36             #pod =item * db_user
37             #pod
38             #pod the username to be used by Rubric::DBI to connect to the Rubric's database
39             #pod
40             #pod =item * db_pass
41             #pod
42             #pod the password to be used by Rubric::DBI to connect to the Rubric's database
43             #pod
44             #pod =item * dbi_trace_level
45             #pod
46             #pod level of debug output for DBI
47             #pod
48             #pod =item * dbi_trace_file
49             #pod
50             #pod Where to send DBI debug output if dbi_trace_level
51             #pod
52             #pod =item * session_cipher_key
53             #pod
54             #pod The key to use to encrypt sessions, which are stored in user cookies. This
55             #pod must be set.
56             #pod
57             #pod =item * cookie_secure
58             #pod
59             #pod If true, secure cookie are used. Defaults to false.
60             #pod
61             #pod =item * cookie_httponly
62             #pod
63             #pod If true, HTTP only cookies are used. Defaults to false.
64             #pod
65             #pod =item * secure_login
66             #pod
67             #pod If true, login should only be done via secure means. The login URI will be
68             #pod https, and loading the login page on an insecure connection will redirect.
69             #pod
70             #pod =item * uri_root
71             #pod
72             #pod the absolute URI for the root of the Rubric::WebApp install
73             #pod
74             #pod =item * css_href
75             #pod
76             #pod the absolute URI for the stylesheet to be used by Rubric::WebApp pages
77             #pod
78             #pod =item * basename
79             #pod
80             #pod This is the text to display as the name of this Rubric instance. It defaults
81             #pod to "Rubric".
82             #pod
83             #pod =item * template_path
84             #pod
85             #pod the INCLUDE_PATH passed to Template when creating the template renderers
86             #pod
87             #pod =item * email_from
88             #pod
89             #pod the email address from which Rubric will send email
90             #pod
91             #pod =item * smtp_server
92             #pod
93             #pod the SMTP server used to send email
94             #pod
95             #pod =item * entries_query_class
96             #pod
97             #pod This is the class used to process the C<entries> run method. It defaults to
98             #pod C<Rubric::WebApp::Entries>.
99             #pod
100             #pod =item * login_class
101             #pod
102             #pod This is the class used to check for logins; it should subclass
103             #pod Rubric::WebApp::Login. If not supplied, the default is
104             #pod Rubric::WebApp::Login::Post.
105             #pod
106             #pod =item * skip_newuser_verification
107             #pod
108             #pod If true, users will be created without verification codes, and won't get
109             #pod verification emails.
110             #pod
111             #pod =item * registration_closed
112             #pod
113             #pod true if registration new users can't register for accounts via the web
114             #pod
115             #pod =item * private_system
116             #pod
117             #pod true value if users must have an account to view entries
118             #pod
119             #pod =item * private_tag
120             #pod
121             #pod A tag which, if attached to an entry, makes it private. The default value is
122             #pod C<@private>, and I strongly advise against changing it, since I may change the
123             #pod way these "system tags" work in the future.
124             #pod
125             #pod =item * markup_formatter
126             #pod
127             #pod This entry, if given, should be a mapping of markup names to formatter plugins.
128             #pod For example:
129             #pod
130             #pod markup_formatter:
131             #pod kwid: Rubric::Entry::Formatter::Kwid
132             #pod tex: Rubric::Entry::Formatter::TeX
133             #pod
134             #pod (No. Neither of those exist.)
135             #pod
136             #pod If it is not specified in the config file, an entry for C<_default> is set to
137             #pod the built-in, extremely simple entry formatter.
138             #pod
139             #pod =item * one_entry_per_link
140             #pod
141             #pod if true, each user can have only one entry per link (default: true)
142             #pod
143             #pod =item * allowed_schemes
144             #pod
145             #pod If undef, all URI schemes are allowed in entries. If it's an array reference,
146             #pod it's the list of allowed schemes.
147             #pod
148             #pod =item * display_localtime
149             #pod
150             #pod If true, the local time (of the server) will be displayed for entry
151             #pod create/modify times. Otherwise, all times will be UTC. (This option is
152             #pod probably temporary, until per-user timezones are implemented.)
153             #pod
154             #pod =item * default_page_size
155             #pod
156             #pod The number of entries that are displayed on a page of entries, by default.
157             #pod
158             #pod =item * max_page_size
159             #pod
160             #pod The maximum number of entries that will be displayed on a page of entries. If
161             #pod more are requested, this many will be displayed.
162             #pod
163             #pod =back
164             #pod
165             #pod =head1 METHODS
166             #pod
167             #pod These methods are used by the setting accessors, internally:
168             #pod
169             #pod =head2 _read_config
170             #pod
171             #pod This method returns the config data, if loaded. If it hasn't already been
172             #pod loaded, it finds and parses the configuration file, then returns the data.
173             #pod
174             #pod =cut
175              
176             my $config;
177             return $config if $config;
178              
179             my $config_file = $config_filename;
180 2631 100   2631   10670 $config = YAML::XS::LoadFile($config_file);
181             }
182 16         61  
183 16         95 #pod =head2 _default
184             #pod
185             #pod This method returns the default configuration has a hashref.
186             #pod
187             #pod =cut
188              
189             my $default = {
190             basename => 'Rubric',
191             css_href => undef,
192             db_user => undef,
193             db_pass => undef,
194             dsn => undef,
195             cookie_httponly => 0,
196             cookie_secure => 0,
197             dbi_trace_level => 0,
198             dbi_trace_file => undef,
199             secure_login => 0,
200             email_from => undef,
201             login_class => 'Rubric::WebApp::Login::Post',
202             smtp_server => undef,
203             uri_root => '',
204             private_tag => '@private',
205             private_system => undef,
206             template_path => undef,
207             allowed_schemes => undef,
208             default_page_size => 25,
209             display_localtime => 0,
210             entries_query_class => 'Rubric::WebApp::Entries',
211             max_page_size => 100,
212             markup_formatter => {},
213             one_entry_per_link => 1,
214             registration_closed => undef,
215             session_cipher_key => undef,
216             skip_newuser_verification => undef,
217             };
218              
219             #pod =head2 make_ro_accessor
220             #pod
221 718     718   21348 #pod Rubric::Config isa Class::Accessor, and uses this sub to build its setting
222             #pod accessors. For a given field, it returns the value of that field in the
223             #pod configuration, if it exists. Otherwise, it returns the default for that field.
224             #pod
225             #pod =cut
226              
227             my ($class, $field) = @_;
228             sub {
229             exists $class->_read_config->{$field}
230             ? $class->_read_config->{$field}
231             : $class->_default->{$field}
232 432     432 1 12796 }
233             }
234              
235             __PACKAGE__->mk_ro_accessors(keys %$default);
236 1650 100   1650   16159  
237             1;
238 432         1297  
239              
240             =pod
241              
242             =encoding UTF-8
243              
244             =head1 NAME
245              
246             Rubric::Config - the configuration data for a Rubric
247              
248             =head1 VERSION
249              
250             version 0.157
251              
252             =head1 DESCRIPTION
253              
254             Rubric::Config provides access to the configuration data for a Rubric. The
255             basic implementation stores its configuration in YAML in a text file in the
256             current working directory. By default, Rubric::Config looks for C<rubric.yml>,
257             but an alternate filename may be passed when using the module:
258              
259             use Rubric::Config ".rubric_yml";
260              
261             =head1 PERL VERSION
262              
263             This code is effectively abandonware. Although releases will sometimes be made
264             to update contact info or to fix packaging flaws, bug reports will mostly be
265             ignored. Feature requests are even more likely to be ignored. (If someone
266             takes up maintenance of this code, they will presumably remove this notice.)
267             This means that whatever version of perl is currently required is unlikely to
268             change -- but also that it might change at any new maintainer's whim.
269              
270             =head1 SETTINGS
271              
272             These configuration settings can all be retrieved by methods of the same name.
273              
274             =over 4
275              
276             =item * dsn
277              
278             the DSN to be used by Rubric::DBI to connect to the Rubric's database
279              
280             =item * db_user
281              
282             the username to be used by Rubric::DBI to connect to the Rubric's database
283              
284             =item * db_pass
285              
286             the password to be used by Rubric::DBI to connect to the Rubric's database
287              
288             =item * dbi_trace_level
289              
290             level of debug output for DBI
291              
292             =item * dbi_trace_file
293              
294             Where to send DBI debug output if dbi_trace_level
295              
296             =item * session_cipher_key
297              
298             The key to use to encrypt sessions, which are stored in user cookies. This
299             must be set.
300              
301             =item * cookie_secure
302              
303             If true, secure cookie are used. Defaults to false.
304              
305             =item * cookie_httponly
306              
307             If true, HTTP only cookies are used. Defaults to false.
308              
309             =item * secure_login
310              
311             If true, login should only be done via secure means. The login URI will be
312             https, and loading the login page on an insecure connection will redirect.
313              
314             =item * uri_root
315              
316             the absolute URI for the root of the Rubric::WebApp install
317              
318             =item * css_href
319              
320             the absolute URI for the stylesheet to be used by Rubric::WebApp pages
321              
322             =item * basename
323              
324             This is the text to display as the name of this Rubric instance. It defaults
325             to "Rubric".
326              
327             =item * template_path
328              
329             the INCLUDE_PATH passed to Template when creating the template renderers
330              
331             =item * email_from
332              
333             the email address from which Rubric will send email
334              
335             =item * smtp_server
336              
337             the SMTP server used to send email
338              
339             =item * entries_query_class
340              
341             This is the class used to process the C<entries> run method. It defaults to
342             C<Rubric::WebApp::Entries>.
343              
344             =item * login_class
345              
346             This is the class used to check for logins; it should subclass
347             Rubric::WebApp::Login. If not supplied, the default is
348             Rubric::WebApp::Login::Post.
349              
350             =item * skip_newuser_verification
351              
352             If true, users will be created without verification codes, and won't get
353             verification emails.
354              
355             =item * registration_closed
356              
357             true if registration new users can't register for accounts via the web
358              
359             =item * private_system
360              
361             true value if users must have an account to view entries
362              
363             =item * private_tag
364              
365             A tag which, if attached to an entry, makes it private. The default value is
366             C<@private>, and I strongly advise against changing it, since I may change the
367             way these "system tags" work in the future.
368              
369             =item * markup_formatter
370              
371             This entry, if given, should be a mapping of markup names to formatter plugins.
372             For example:
373              
374             markup_formatter:
375             kwid: Rubric::Entry::Formatter::Kwid
376             tex: Rubric::Entry::Formatter::TeX
377              
378             (No. Neither of those exist.)
379              
380             If it is not specified in the config file, an entry for C<_default> is set to
381             the built-in, extremely simple entry formatter.
382              
383             =item * one_entry_per_link
384              
385             if true, each user can have only one entry per link (default: true)
386              
387             =item * allowed_schemes
388              
389             If undef, all URI schemes are allowed in entries. If it's an array reference,
390             it's the list of allowed schemes.
391              
392             =item * display_localtime
393              
394             If true, the local time (of the server) will be displayed for entry
395             create/modify times. Otherwise, all times will be UTC. (This option is
396             probably temporary, until per-user timezones are implemented.)
397              
398             =item * default_page_size
399              
400             The number of entries that are displayed on a page of entries, by default.
401              
402             =item * max_page_size
403              
404             The maximum number of entries that will be displayed on a page of entries. If
405             more are requested, this many will be displayed.
406              
407             =back
408              
409             =head1 METHODS
410              
411             These methods are used by the setting accessors, internally:
412              
413             =head2 _read_config
414              
415             This method returns the config data, if loaded. If it hasn't already been
416             loaded, it finds and parses the configuration file, then returns the data.
417              
418             =head2 _default
419              
420             This method returns the default configuration has a hashref.
421              
422             =head2 make_ro_accessor
423              
424             Rubric::Config isa Class::Accessor, and uses this sub to build its setting
425             accessors. For a given field, it returns the value of that field in the
426             configuration, if it exists. Otherwise, it returns the default for that field.
427              
428             =head1 AUTHOR
429              
430             Ricardo SIGNES <rjbs@semiotic.systems>
431              
432             =head1 COPYRIGHT AND LICENSE
433              
434             This software is copyright (c) 2004 by Ricardo SIGNES.
435              
436             This is free software; you can redistribute it and/or modify it under
437             the same terms as the Perl 5 programming language system itself.
438              
439             =cut