Rubric/Config.pm

filter: Statementstmt 100% 26 / 26 Branchbran 100% 6 / 6 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 9 / 9 Podpod 100% 1 / 1 totaltotal 95.5% 43 / 45 CC 4 SCAR 4.1
CC
4
Cov
97%
import
2.0
_read_config
2.0
__ANON__
2.0
CRAP 1.5
« Rubric/Entry/Formatter/HTMLEscape.pm ↑ Summary Rubric/WebApp/Login/HTTP.pm »
1 16 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 16 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 package Rubric::Config 0.157;
4 # ABSTRACT: the configuration data for a Rubric
5  
6 16 ▶use parent qw(Class::Accessor);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 #pod =head1 DESCRIPTION
9 #pod
10 #pod Rubric::Config provides access to the configuration data for a Rubric. The
11 #pod basic implementation stores its configuration in YAML in a text file in the
12 #pod current working directory. By default, Rubric::Config looks for C<rubric.yml>,
13 #pod but an alternate filename may be passed when using the module:
14 #pod
15 #pod use Rubric::Config ".rubric_yml";
16 #pod
17 #pod =cut
18  
19 16 ▶use YAML::XS ();
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 16 ▶my $config_filename = $ENV{RUBRIC_CONFIG_FILE} || 'rubric.yml';
Condition50%1/2
$ENV{'RUBRIC_CONFIG_FILE'} || 'rubric.yml'
l!l
016
MC/DC0%0/1
$ENV{'RUBRIC_CONFIG_FILE'} || 'rubric.yml'
$ENV{'RUBRIC_CONFIG_FILE'}
Truth table50%1/2
A
A= $ENV{'RUBRIC_CONFIG_FILE'}
Aresult
11
00
22  
23 70 ▶sub import {
Subroutine import: called CC=2 SCAR=6.9
24 70 my ($class) = shift;
25 70 ▶ $config_filename = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 16 54 70
26 }
27  
28 #pod =head1 SETTINGS
29 #pod
30 #pod These configuration settings can all be retrieved by methods of the same name.
31 #pod
32 #pod =over 4
33 #pod
34 #pod =item * dsn
35 #pod
36 #pod the DSN to be used by Rubric::DBI to connect to the Rubric's database
37 #pod
38 #pod =item * db_user
39 #pod
40 #pod the username to be used by Rubric::DBI to connect to the Rubric's database
41 #pod
42 #pod =item * db_pass
43 #pod
44 #pod the password to be used by Rubric::DBI to connect to the Rubric's database
45 #pod
46 #pod =item * dbi_trace_level
47 #pod
48 #pod level of debug output for DBI
49 #pod
50 #pod =item * dbi_trace_file
51 #pod
52 #pod Where to send DBI debug output if dbi_trace_level
53 #pod
54 #pod =item * session_cipher_key
55 #pod
56 #pod The key to use to encrypt sessions, which are stored in user cookies. This
57 #pod must be set.
58 #pod
59 #pod =item * cookie_secure
60 #pod
61 #pod If true, secure cookie are used. Defaults to false.
62 #pod
63 #pod =item * cookie_httponly
64 #pod
65 #pod If true, HTTP only cookies are used. Defaults to false.
66 #pod
67 #pod =item * secure_login
68 #pod
69 #pod If true, login should only be done via secure means. The login URI will be
70 #pod https, and loading the login page on an insecure connection will redirect.
71 #pod
72 #pod =item * uri_root
73 #pod
74 #pod the absolute URI for the root of the Rubric::WebApp install
75 #pod
76 #pod =item * css_href
77 #pod
78 #pod the absolute URI for the stylesheet to be used by Rubric::WebApp pages
79 #pod
80 #pod =item * basename
81 #pod
82 #pod This is the text to display as the name of this Rubric instance. It defaults
83 #pod to "Rubric".
84 #pod
85 #pod =item * template_path
86 #pod
87 #pod the INCLUDE_PATH passed to Template when creating the template renderers
88 #pod
89 #pod =item * email_from
90 #pod
91 #pod the email address from which Rubric will send email
92 #pod
93 #pod =item * smtp_server
94 #pod
95 #pod the SMTP server used to send email
96 #pod
97 #pod =item * entries_query_class
98 #pod
99 #pod This is the class used to process the C<entries> run method. It defaults to
100 #pod C<Rubric::WebApp::Entries>.
101 #pod
102 #pod =item * login_class
103 #pod
104 #pod This is the class used to check for logins; it should subclass
105 #pod Rubric::WebApp::Login. If not supplied, the default is
106 #pod Rubric::WebApp::Login::Post.
107 #pod
108 #pod =item * skip_newuser_verification
109 #pod
110 #pod If true, users will be created without verification codes, and won't get
111 #pod verification emails.
112 #pod
113 #pod =item * registration_closed
114 #pod
115 #pod true if registration new users can't register for accounts via the web
116 #pod
117 #pod =item * private_system
118 #pod
119 #pod true value if users must have an account to view entries
120 #pod
121 #pod =item * private_tag
122 #pod
123 #pod A tag which, if attached to an entry, makes it private. The default value is
124 #pod C<@private>, and I strongly advise against changing it, since I may change the
125 #pod way these "system tags" work in the future.
126 #pod
127 #pod =item * markup_formatter
128 #pod
129 #pod This entry, if given, should be a mapping of markup names to formatter plugins.
130 #pod For example:
131 #pod
132 #pod markup_formatter:
133 #pod kwid: Rubric::Entry::Formatter::Kwid
134 #pod tex: Rubric::Entry::Formatter::TeX
135 #pod
136 #pod (No. Neither of those exist.)
137 #pod
138 #pod If it is not specified in the config file, an entry for C<_default> is set to
139 #pod the built-in, extremely simple entry formatter.
140 #pod
141 #pod =item * one_entry_per_link
142 #pod
143 #pod if true, each user can have only one entry per link (default: true)
144 #pod
145 #pod =item * allowed_schemes
146 #pod
147 #pod If undef, all URI schemes are allowed in entries. If it's an array reference,
148 #pod it's the list of allowed schemes.
149 #pod
150 #pod =item * display_localtime
151 #pod
152 #pod If true, the local time (of the server) will be displayed for entry
153 #pod create/modify times. Otherwise, all times will be UTC. (This option is
154 #pod probably temporary, until per-user timezones are implemented.)
155 #pod
156 #pod =item * default_page_size
157 #pod
158 #pod The number of entries that are displayed on a page of entries, by default.
159 #pod
160 #pod =item * max_page_size
161 #pod
162 #pod The maximum number of entries that will be displayed on a page of entries. If
163 #pod more are requested, this many will be displayed.
164 #pod
165 #pod =back
166 #pod
167 #pod =head1 METHODS
168 #pod
169 #pod These methods are used by the setting accessors, internally:
170 #pod
171 #pod =head2 _read_config
172 #pod
173 #pod This method returns the config data, if loaded. If it hasn't already been
174 #pod loaded, it finds and parses the configuration file, then returns the data.
175 #pod
176 #pod =cut
177  
178 16 my $config;
179 2625 ▶sub _read_config {
Subroutine _read_config: called CC=2 SCAR=6.9
180 2625 ▶ return $config if $config;
Branch: 1 branch
BranchTrueFalseTotal
if $config 2609 16 2625
181  
182 16 my $config_file = $config_filename;
183 16 $config = YAML::XS::LoadFile($config_file);
184 }
185  
186 #pod =head2 _default
187 #pod
188 #pod This method returns the default configuration has a hashref.
189 #pod
190 #pod =cut
191  
192 16 my $default = {
193 basename => 'Rubric',
194 css_href => undef,
195 db_user => undef,
196 db_pass => undef,
197 dsn => undef,
198 cookie_httponly => 0,
199 cookie_secure => 0,
200 dbi_trace_level => 0,
201 dbi_trace_file => undef,
202 secure_login => 0,
203 email_from => undef,
204 login_class => 'Rubric::WebApp::Login::Post',
205 smtp_server => undef,
206 uri_root => '',
207 private_tag => '@private',
208 private_system => undef,
209 template_path => undef,
210 allowed_schemes => undef,
211 default_page_size => 25,
212 display_localtime => 0,
213 entries_query_class => 'Rubric::WebApp::Entries',
214 max_page_size => 100,
215 markup_formatter => {},
216 one_entry_per_link => 1,
217 registration_closed => undef,
218 session_cipher_key => undef,
219 skip_newuser_verification => undef,
220 };
221 718 ▶sub _default { $default }
Subroutine _default: called CC=1 SCAR=0.0
222  
223 #pod =head2 make_ro_accessor
224 #pod
225 #pod Rubric::Config isa Class::Accessor, and uses this sub to build its setting
226 #pod accessors. For a given field, it returns the value of that field in the
227 #pod configuration, if it exists. Otherwise, it returns the default for that field.
228 #pod
229 #pod =cut
230  
231 432 ▶sub make_ro_accessor {
Subroutine make_ro_accessor: called CC=1 SCAR=0.0
Pod documented
232 432 my ($class, $field) = @_;
233 1647 ▶ sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
234 exists $class->_read_config->{$field}
235 ? $class->_read_config->{$field}
236 1647 ▶ : $class->_default->{$field}
Branch: 1 branch
BranchTrueFalseTotal
exists $class->_read_config->{$field} ? : 978 669 1647
237 }
238 432 }
239  
240 16 __PACKAGE__->mk_ro_accessors(keys %$default);
241  
242 16 1;
243  
244 __END__
« Rubric/Entry/Formatter/HTMLEscape.pm ↑ Summary Rubric/WebApp/Login/HTTP.pm »