| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Bryar::Document; |
|
2
|
4
|
|
|
4
|
|
5781
|
use Time::Piece; |
|
|
4
|
|
|
|
|
60875
|
|
|
|
4
|
|
|
|
|
28
|
|
|
3
|
4
|
|
|
4
|
|
403
|
use 5.006; |
|
|
4
|
|
|
|
|
15
|
|
|
|
4
|
|
|
|
|
157
|
|
|
4
|
4
|
|
|
4
|
|
24
|
use strict; |
|
|
4
|
|
|
|
|
6
|
|
|
|
4
|
|
|
|
|
156
|
|
|
5
|
4
|
|
|
4
|
|
22
|
use warnings; |
|
|
4
|
|
|
|
|
196
|
|
|
|
4
|
|
|
|
|
173
|
|
|
6
|
4
|
|
|
4
|
|
25
|
use Carp; |
|
|
4
|
|
|
|
|
7
|
|
|
|
4
|
|
|
|
|
3485
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '1.0'; |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 NAME |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
Bryar::Document - Represents a blog post |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
$self->new(...); |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
$self->content(); # Get content |
|
18
|
|
|
|
|
|
|
$self->title(); # Get title |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
$self->epoch(); # Get epoch |
|
21
|
|
|
|
|
|
|
$self->timepiece(); # Get the date as a Time::Piece object |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
$self->category(); # Get category |
|
24
|
|
|
|
|
|
|
$self->author(); # Get author |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
$self->keywords(...); # Return keywords relating to this document |
|
27
|
|
|
|
|
|
|
$self->id # Unique identifier |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
$self->comments(); # Get comments |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
This encapsulates a blog post, as returned from a search on a data |
|
34
|
|
|
|
|
|
|
source. |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head1 METHODS |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head2 new |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
$self->new(%params) |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
Creates a new Bryar::Document instance. |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=cut |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub new { |
|
48
|
6
|
|
|
6
|
1
|
849
|
my $class = shift; |
|
49
|
6
|
|
|
|
|
28
|
my %args = @_; |
|
50
|
6
|
|
100
|
|
|
56
|
my $self = bless { |
|
51
|
|
|
|
|
|
|
epoch => $args{epoch} , |
|
52
|
|
|
|
|
|
|
content => $args{content} , |
|
53
|
|
|
|
|
|
|
author => $args{author} , |
|
54
|
|
|
|
|
|
|
category => $args{category} , |
|
55
|
|
|
|
|
|
|
title => $args{title} , |
|
56
|
|
|
|
|
|
|
id => $args{id}, |
|
57
|
|
|
|
|
|
|
comments => ($args{comments} || []) |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
}, $class; |
|
60
|
6
|
|
|
|
|
151
|
return $self; |
|
61
|
|
|
|
|
|
|
} |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head2 content |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
$self->content(); # Get content |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
Gets the value of the document's content |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=cut |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub content { |
|
73
|
4
|
|
|
4
|
1
|
2553
|
my $self = shift; |
|
74
|
4
|
|
|
|
|
23
|
return $self->{content}; |
|
75
|
|
|
|
|
|
|
} |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head2 title |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
$self->title(); # Get title |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
Gets the value of the document's title |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=cut |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub title { |
|
87
|
4
|
|
|
4
|
1
|
45738
|
my $self = shift; |
|
88
|
4
|
|
|
|
|
22
|
return $self->{title}; |
|
89
|
|
|
|
|
|
|
} |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head2 epoch |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
$self->epoch(); # Get epoch |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
Gets the value of the document's epoch |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=cut |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub epoch { |
|
101
|
14
|
|
|
14
|
1
|
576
|
my $self = shift; |
|
102
|
14
|
|
|
|
|
87
|
return $self->{epoch}; |
|
103
|
|
|
|
|
|
|
} |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head2 timepiece |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
Returns the date of the document as a Time::Piece object. |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=cut |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub timepiece { |
|
112
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
|
113
|
0
|
|
|
|
|
0
|
return Time::Piece->new($self->{epoch}); |
|
114
|
|
|
|
|
|
|
} |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head2 datetime |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
Returns the date of the document as a DateTime object |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=cut |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
sub datetime { |
|
123
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
|
124
|
0
|
|
|
|
|
0
|
return DateTime->from_epoch( epoch => $self->{epoch}, time_zone => "local" ); |
|
125
|
|
|
|
|
|
|
} |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head2 category |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
$self->category(); # Get category |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
Gets the value of the document's category |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=cut |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
sub category { |
|
138
|
1
|
|
|
1
|
1
|
399
|
my $self = shift; |
|
139
|
1
|
|
|
|
|
4
|
return $self->{category}; |
|
140
|
|
|
|
|
|
|
} |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=head2 author |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
$self->author(); # Get author |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
Gets the value of the document's author |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=cut |
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
sub author { |
|
152
|
1
|
|
|
1
|
1
|
425
|
my $self = shift; |
|
153
|
1
|
|
|
|
|
3
|
return $self->{author}; |
|
154
|
|
|
|
|
|
|
} |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=head2 keywords |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
$self->keywords |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
Returns the keywords for this blog entry, using C |
|
162
|
|
|
|
|
|
|
if it's installed. May be computationally expensive! |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=cut |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
sub keywords { |
|
167
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
|
168
|
0
|
|
|
|
|
0
|
eval { require Lingua::EN::Keywords; }; |
|
|
0
|
|
|
|
|
0
|
|
|
169
|
0
|
0
|
|
|
|
0
|
return "" if $@; |
|
170
|
0
|
|
|
|
|
0
|
return Lingua::EN::Keywords::keywords($self->content); |
|
171
|
|
|
|
|
|
|
# Goodbye, CPU time! |
|
172
|
|
|
|
|
|
|
} |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=head2 id |
|
175
|
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
$self->id(); # Get id |
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
Returns a unique identifier for the document. |
|
179
|
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=cut |
|
181
|
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
sub id { |
|
183
|
1
|
|
|
1
|
1
|
2
|
my $self = shift; |
|
184
|
1
|
|
|
|
|
6
|
return $self->{id}; |
|
185
|
|
|
|
|
|
|
} |
|
186
|
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=head2 url |
|
188
|
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
$self->url; |
|
190
|
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
Returns the post url relative to $bryar->config->baseurl. |
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=cut |
|
194
|
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
sub url { |
|
196
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
197
|
|
|
|
|
|
|
|
|
198
|
0
|
|
|
|
|
|
my $id = $self->{id}; |
|
199
|
0
|
|
|
|
|
|
$id =~ s#^.*/##; |
|
200
|
0
|
|
|
|
|
|
my $url = ''; |
|
201
|
0
|
0
|
|
|
|
|
$url = '/' . $self->{category} if $self->{category} ne 'main'; |
|
202
|
0
|
|
|
|
|
|
return $url . '/id_' . $id; |
|
203
|
|
|
|
|
|
|
} |
|
204
|
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
=head2 comments |
|
206
|
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
@comments = $self->comments(); |
|
208
|
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
Returns a list of L objects attached to this document. |
|
210
|
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
=cut |
|
212
|
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
sub comments { |
|
214
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
215
|
0
|
|
|
|
|
|
return @{$self->{comments}}; |
|
|
0
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
} |
|
217
|
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
=head2 excerpt |
|
219
|
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
my $excerpt = $self->excerpt(20); # get a 20 word excerpt |
|
221
|
|
|
|
|
|
|
my $excerpt = $self->excerpt( ); # get excerpt as long as the excerpt_words config variable |
|
222
|
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
=cut |
|
224
|
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
sub excerpt { |
|
226
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
227
|
0
|
|
0
|
|
|
|
my $num_words = shift || 40; |
|
228
|
|
|
|
|
|
|
|
|
229
|
0
|
|
|
|
|
|
my $content = $self->{content}; |
|
230
|
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
# NOTE: I lifted this from MT, but in reality, i will be making it more flexible and neater. |
|
232
|
|
|
|
|
|
|
# Now if only this document had some sense of the Bryar environment so it could pull the |
|
233
|
|
|
|
|
|
|
# default $num_words from the config. |
|
234
|
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
# $text = remove_html($text); |
|
236
|
0
|
|
|
|
|
|
my @words = split /\s+/, $content; |
|
237
|
0
|
0
|
|
|
|
|
my $max_words = @words > $num_words ? $num_words : @words; |
|
238
|
0
|
|
|
|
|
|
return join ' ', @words[0..$max_words-1]; |
|
239
|
|
|
|
|
|
|
} |
|
240
|
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
=head1 LICENSE |
|
242
|
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
This module is free software, and may be distributed under the same |
|
244
|
|
|
|
|
|
|
terms as Perl itself. |
|
245
|
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
=head1 AUTHOR |
|
247
|
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
Copyright (C) 2003, Simon Cozens C |
|
249
|
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
251
|
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
=cut |
|
253
|
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
1; |