line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Bryar::Config; |
2
|
3
|
|
|
3
|
|
7801
|
use UNIVERSAL::require; |
|
3
|
|
|
|
|
7654
|
|
|
3
|
|
|
|
|
31
|
|
3
|
3
|
|
|
3
|
|
115
|
use 5.006; |
|
3
|
|
|
|
|
12
|
|
|
3
|
|
|
|
|
104
|
|
4
|
3
|
|
|
3
|
|
17
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
80
|
|
5
|
3
|
|
|
3
|
|
16
|
use warnings; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
68
|
|
6
|
3
|
|
|
3
|
|
15
|
use Carp; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
3109
|
|
7
|
|
|
|
|
|
|
our $VERSION = '1.1'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 NAME |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
Bryar::Config - A set of configuration settings for Bryar |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 SYNOPSIS |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
Bryar::Config->new(...); |
16
|
|
|
|
|
|
|
Bryar::Config->load(...); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 DESCRIPTION |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
This encapsulates a Bryar configuration. It can be used to load a new |
21
|
|
|
|
|
|
|
configuration from a file, or provide a reasonable set of defaults. |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 METHODS |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head2 new |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
Bryar::Config->new(...) |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
Creates a new Bryar configuration instance. |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=cut |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
our %default_args = ( |
34
|
|
|
|
|
|
|
source => "Bryar::DataSource::FlatFile", |
35
|
|
|
|
|
|
|
name => "My web log", |
36
|
|
|
|
|
|
|
description => "Put a better description here", |
37
|
|
|
|
|
|
|
baseurl => "", |
38
|
|
|
|
|
|
|
datadir => ".", |
39
|
|
|
|
|
|
|
email => 'someone@example.com', |
40
|
|
|
|
|
|
|
depth => 1, |
41
|
|
|
|
|
|
|
recent => 20, |
42
|
|
|
|
|
|
|
renderer => "Bryar::Renderer::TT", |
43
|
|
|
|
|
|
|
collector => "Bryar::Collector", |
44
|
|
|
|
|
|
|
frontend => ((exists $ENV{GATEWAY_INTERFACE} and |
45
|
|
|
|
|
|
|
$ENV{'GATEWAY_INTERFACE'} =~ /^CGI-Perl\//) |
46
|
|
|
|
|
|
|
? "Bryar::Frontend::Mod_perl" |
47
|
|
|
|
|
|
|
: "Bryar::Frontend::CGI") |
48
|
|
|
|
|
|
|
); |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub new { |
51
|
3
|
|
|
3
|
1
|
484
|
my $class = shift; |
52
|
3
|
|
|
|
|
90
|
my %args = (%default_args, @_); # This does need to happen in stages |
53
|
3
|
|
|
|
|
54
|
my $self = bless { %args, %_ }, $class; |
54
|
|
|
|
|
|
|
# Because setting datadir above may affect where the config file is. |
55
|
|
|
|
|
|
|
|
56
|
3
|
|
50
|
|
|
87
|
%args = (%args, $self->load($args{config} || "bryar.conf")); |
57
|
3
|
|
|
|
|
22
|
@{$self}{keys %args} = values %args; |
|
3
|
|
|
|
|
21
|
|
58
|
|
|
|
|
|
|
|
59
|
3
|
|
|
|
|
19
|
foreach my $module (qw(renderer source collector frontend)) { |
60
|
12
|
50
|
|
|
|
67
|
$self->$module->require or die $@; |
61
|
12
|
50
|
33
|
|
|
356
|
$self->$module($self->$module->new(config => $self)) |
62
|
|
|
|
|
|
|
if $self->$module->can('new') or ref $self->$module; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
3
|
|
|
|
|
43
|
return $self; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head2 load |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
$self->load($file) |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
Load the configuration file from somewhere and return the arguments as a |
73
|
|
|
|
|
|
|
hash. |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=cut |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub load { |
78
|
3
|
|
|
3
|
1
|
10
|
my ($self, $file) = @_; |
79
|
3
|
|
|
|
|
7
|
my %args; |
80
|
3
|
|
|
|
|
25
|
my $datadir = $self->{datadir}; |
81
|
3
|
50
|
|
|
|
63
|
if (!-r $file) { |
82
|
3
|
50
|
|
|
|
69
|
if (-r "$datadir/$file") { $file = "$datadir/$file"; } |
|
0
|
|
|
|
|
0
|
|
83
|
3
|
|
|
|
|
36
|
else { return () } |
84
|
|
|
|
|
|
|
} |
85
|
0
|
0
|
|
|
|
0
|
open(my $config, '<:utf8', $file) or return (); |
86
|
0
|
|
|
|
|
0
|
while (<$config>) { |
87
|
0
|
|
|
|
|
0
|
chomp; |
88
|
0
|
0
|
0
|
|
|
0
|
next if /^#/ or /^$/; |
89
|
0
|
|
|
|
|
0
|
my ($k, $v) = split /\s*:\s*/, $_, 2; |
90
|
0
|
|
|
|
|
0
|
$args{$k} = $v; |
91
|
|
|
|
|
|
|
} |
92
|
0
|
|
|
|
|
0
|
close $config; |
93
|
0
|
|
|
|
|
0
|
return %args; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head2 renderer |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
$self->renderer(); # Get renderer |
99
|
|
|
|
|
|
|
$self->renderer(...); # Set renderer |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
The class used to render this blog; defaults to "Bryar::Renderer::TT", |
102
|
|
|
|
|
|
|
the Template Toolkit renderer. |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=cut |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub renderer { |
107
|
11
|
|
|
11
|
1
|
31
|
my $self = shift; |
108
|
11
|
50
|
|
|
|
36
|
if (@_) { $self->{renderer} = shift }; |
|
0
|
|
|
|
|
0
|
|
109
|
|
|
|
|
|
|
|
110
|
11
|
|
|
|
|
158
|
return $self->{renderer}; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head2 frontend |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
$self->frontend(); # Get frontend |
117
|
|
|
|
|
|
|
$self->frontend(...); # Set frontend |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
The class used to handle input and output from the blog; defaults to |
120
|
|
|
|
|
|
|
L if run via the CGI, L |
121
|
|
|
|
|
|
|
from inside Apache. |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=cut |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
sub frontend { |
126
|
11
|
|
|
11
|
1
|
707
|
my $self = shift; |
127
|
11
|
50
|
|
|
|
41
|
if (@_) { $self->{frontend} = shift }; |
|
0
|
|
|
|
|
0
|
|
128
|
|
|
|
|
|
|
|
129
|
11
|
|
|
|
|
209
|
return $self->{frontend}; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head2 collector |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
$self->collector(); # Get collector |
135
|
|
|
|
|
|
|
$self->collector(...); # Set collector |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
The class used to select which documents to output. You probably don't |
138
|
|
|
|
|
|
|
want to mess with this. |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=cut |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
sub collector { |
143
|
10
|
|
|
10
|
1
|
21
|
my $self = shift; |
144
|
10
|
50
|
|
|
|
29
|
if (@_) { $self->{collector} = shift }; |
|
0
|
|
|
|
|
0
|
|
145
|
|
|
|
|
|
|
|
146
|
10
|
|
|
|
|
93
|
return $self->{collector}; |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=head2 source |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
$self->source(); # Get source |
152
|
|
|
|
|
|
|
$self->source(...); # Set source |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
The class which finds the blog posts. Defaults to |
155
|
|
|
|
|
|
|
C, the blosxom-compatible data source. |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=cut |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
sub source { |
160
|
16
|
|
|
16
|
1
|
754
|
my $self = shift; |
161
|
16
|
50
|
|
|
|
54
|
if (@_) { $self->{source} = shift }; |
|
0
|
|
|
|
|
0
|
|
162
|
|
|
|
|
|
|
|
163
|
16
|
|
|
|
|
339
|
return $self->{source}; |
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=head2 cache |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
$self->cache(); # Get cache object |
170
|
|
|
|
|
|
|
$self->cache(new Cache::FileCache()); # Set cache object |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
An instance of a C subclass which will be used to cache |
173
|
|
|
|
|
|
|
the formatted pages. |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=cut |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
sub cache { |
178
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
179
|
0
|
0
|
|
|
|
0
|
if (@_) { $self->{cache} = shift }; |
|
0
|
|
|
|
|
0
|
|
180
|
|
|
|
|
|
|
|
181
|
0
|
|
|
|
|
0
|
return $self->{cache}; |
182
|
|
|
|
|
|
|
} |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=head2 datadir |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
$self->datadir(); # Get datadir |
188
|
|
|
|
|
|
|
$self->datadir(...); # Set datadir |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
Where the templates (and in the case of the flat-file data source, the |
191
|
|
|
|
|
|
|
blog posts) live. |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=cut |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
sub datadir { |
196
|
6
|
|
|
6
|
1
|
632
|
my $self = shift; |
197
|
6
|
50
|
|
|
|
24
|
if (@_) { $self->{datadir} = shift}; |
|
0
|
|
|
|
|
0
|
|
198
|
|
|
|
|
|
|
|
199
|
6
|
|
|
|
|
35
|
return $self->{datadir}; |
200
|
|
|
|
|
|
|
} |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=head2 name |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
$self->name(); # Get name |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
The name of this blog. |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
=cut |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
sub name { |
212
|
1
|
|
|
1
|
1
|
774
|
my $self = shift; |
213
|
1
|
|
|
|
|
4
|
return $self->{name}; |
214
|
|
|
|
|
|
|
} |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
=head2 description |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
$self->description(); # Get description |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
A description for the blog. |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
=cut |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
sub description { |
225
|
1
|
|
|
1
|
1
|
2599
|
my $self = shift; |
226
|
1
|
|
|
|
|
7
|
return $self->{description}; |
227
|
|
|
|
|
|
|
} |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
=head2 depth |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
$self->depth(); # Get depth |
233
|
|
|
|
|
|
|
$self->depth(...); # Set depth |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
How far to recurse into sub-blogs. Default is 1, stay in the current |
236
|
|
|
|
|
|
|
directory. |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
=cut |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
sub depth { |
241
|
4
|
|
|
4
|
1
|
588
|
my $self = shift; |
242
|
4
|
50
|
|
|
|
17
|
if (@_) { $self->{depth} = shift }; |
|
0
|
|
|
|
|
0
|
|
243
|
|
|
|
|
|
|
|
244
|
4
|
|
|
|
|
23
|
return $self->{depth}; |
245
|
|
|
|
|
|
|
} |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
=head2 email |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
$self->email(); # Get email |
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
Get the owner's email address. This is used for spam reporting. |
252
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
=cut |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
sub email { |
256
|
1
|
|
|
1
|
1
|
3
|
my $self = shift; |
257
|
1
|
|
|
|
|
6488
|
return $self->{email}; |
258
|
|
|
|
|
|
|
} |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
=head2 recent |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
$self->recent(); # Get recent |
263
|
|
|
|
|
|
|
$self->recent(...); # Set recent |
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
The number of entries to display if there are no other parameters given. |
266
|
|
|
|
|
|
|
Defaults to 20 entries. |
267
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
=cut |
269
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
sub recent { |
271
|
1
|
|
|
1
|
1
|
4
|
my $self = shift; |
272
|
1
|
50
|
|
|
|
5
|
if (@_) { $self->{recent} = shift }; |
|
0
|
|
|
|
|
0
|
|
273
|
|
|
|
|
|
|
|
274
|
1
|
|
|
|
|
5
|
return $self->{recent}; |
275
|
|
|
|
|
|
|
} |
276
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
=head2 baseurl |
278
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
$self->baseurl(); # Get baseurl |
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
The base URL of this blog. (Needed for setting up links to archived |
282
|
|
|
|
|
|
|
posts, etc.) |
283
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
=cut |
285
|
|
|
|
|
|
|
|
286
|
|
|
|
|
|
|
sub baseurl { |
287
|
1
|
|
|
1
|
1
|
568
|
my $self = shift; |
288
|
1
|
|
|
|
|
3
|
return $self->{baseurl}; |
289
|
|
|
|
|
|
|
} |
290
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
|
292
|
|
|
|
|
|
|
=head1 LICENSE |
293
|
|
|
|
|
|
|
|
294
|
|
|
|
|
|
|
This module is free software, and may be distributed under the same |
295
|
|
|
|
|
|
|
terms as Perl itself. |
296
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
|
298
|
|
|
|
|
|
|
=head1 AUTHOR |
299
|
|
|
|
|
|
|
|
300
|
|
|
|
|
|
|
Copyright (C) 2003, Simon Cozens C |
301
|
|
|
|
|
|
|
|
302
|
|
|
|
|
|
|
some parts Copyright 2007 David Cantrell C |
303
|
|
|
|
|
|
|
|
304
|
|
|
|
|
|
|
|
305
|
|
|
|
|
|
|
=cut |
306
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
1; |