| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
2
|
|
|
2
|
|
1547
|
use strict; |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
75
|
|
|
2
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
127
|
|
|
3
|
|
|
|
|
|
|
package Rubric::WebApp::Entries; |
|
4
|
|
|
|
|
|
|
# ABSTRACT: process the /entries run method |
|
5
|
|
|
|
|
|
|
$Rubric::WebApp::Entries::VERSION = '0.155'; |
|
6
|
|
|
|
|
|
|
# =head1 DESCRIPTION |
|
7
|
|
|
|
|
|
|
# |
|
8
|
|
|
|
|
|
|
# Rubric::WebApp::Entries implements a URI parser that builds a query based |
|
9
|
|
|
|
|
|
|
# on a query URI, passes it to Rubric::Entries, and returns the rendered report |
|
10
|
|
|
|
|
|
|
# on the results. |
|
11
|
|
|
|
|
|
|
# |
|
12
|
|
|
|
|
|
|
# =cut |
|
13
|
|
|
|
|
|
|
|
|
14
|
2
|
|
|
2
|
|
1149
|
use Date::Span 1.12; |
|
|
2
|
|
|
|
|
1591
|
|
|
|
2
|
|
|
|
|
152
|
|
|
15
|
2
|
|
|
2
|
|
14
|
use Digest::MD5 qw(md5_hex); |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
79
|
|
|
16
|
|
|
|
|
|
|
|
|
17
|
2
|
|
|
2
|
|
51
|
use Rubric::Config; |
|
|
2
|
|
|
|
|
17
|
|
|
|
2
|
|
|
|
|
48
|
|
|
18
|
2
|
|
|
2
|
|
13
|
use Rubric::Entry; |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
91
|
|
|
19
|
2
|
|
|
2
|
|
53
|
use Rubric::Renderer; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
64
|
|
|
20
|
2
|
|
|
2
|
|
12
|
use Rubric::WebApp::URI; |
|
|
2
|
|
|
|
|
6
|
|
|
|
2
|
|
|
|
|
2608
|
|
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# =head1 METHODS |
|
23
|
|
|
|
|
|
|
# |
|
24
|
|
|
|
|
|
|
# =head2 entries($webapp) |
|
25
|
|
|
|
|
|
|
# |
|
26
|
|
|
|
|
|
|
# This method is called by Rubric::WebApp. It returns the rendered template for |
|
27
|
|
|
|
|
|
|
# return to the user's browser. |
|
28
|
|
|
|
|
|
|
# |
|
29
|
|
|
|
|
|
|
# =cut |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub entries { |
|
32
|
30
|
|
|
30
|
1
|
76
|
my ($self, $webapp) = @_; |
|
33
|
30
|
|
|
|
|
63
|
my %arg; |
|
34
|
|
|
|
|
|
|
|
|
35
|
30
|
|
|
|
|
142
|
while (my $param = $webapp->next_path_part) { |
|
36
|
22
|
|
|
|
|
378
|
my $value = $webapp->next_path_part; |
|
37
|
22
|
|
|
|
|
354
|
$arg{$param} = $self->get_arg($param, $value); |
|
38
|
|
|
|
|
|
|
} |
|
39
|
30
|
50
|
|
|
|
629
|
if (my $uri = $webapp->query->param('uri')) { |
|
40
|
0
|
0
|
|
|
|
0
|
$arg{urimd5} = md5_hex($uri) unless $arg{urimd5}; |
|
41
|
|
|
|
|
|
|
} |
|
42
|
|
|
|
|
|
|
|
|
43
|
30
|
|
|
|
|
991
|
for (qw(like desc_like body_like)) { |
|
44
|
90
|
50
|
|
|
|
1387
|
if (my $param = $webapp->query->param($_)) { |
|
45
|
0
|
|
|
|
|
0
|
$arg{$_} = $self->get_arg($_, $param); |
|
46
|
|
|
|
|
|
|
} |
|
47
|
|
|
|
|
|
|
} |
|
48
|
|
|
|
|
|
|
|
|
49
|
30
|
100
|
|
|
|
733
|
unless (%arg) { |
|
50
|
9
|
|
|
|
|
106
|
$webapp->param(recent_tags => Rubric::Entry->recent_tags_counted); |
|
51
|
9
|
50
|
|
|
|
252
|
$arg{first_only} = 1 unless %arg; |
|
52
|
|
|
|
|
|
|
} |
|
53
|
|
|
|
|
|
|
|
|
54
|
30
|
|
|
|
|
114
|
my $user = $webapp->param('current_user'); |
|
55
|
30
|
|
|
|
|
455
|
my $order_by = $webapp->query->param('order_by'); |
|
56
|
|
|
|
|
|
|
|
|
57
|
30
|
|
|
|
|
1087
|
my $entries = Rubric::Entry->query(\%arg, |
|
58
|
|
|
|
|
|
|
{ user => $user, order_by => $order_by }); |
|
59
|
30
|
|
|
|
|
25603
|
$webapp->param(query_description => $self->describe_query(\%arg)); |
|
60
|
|
|
|
|
|
|
|
|
61
|
30
|
|
|
|
|
943
|
$webapp->page_entries($entries)->render_entries(\%arg); |
|
62
|
|
|
|
|
|
|
} |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
# =head2 describe_query(\%arg) |
|
65
|
|
|
|
|
|
|
# |
|
66
|
|
|
|
|
|
|
# returns a human-readable description of the query described by C<%args> |
|
67
|
|
|
|
|
|
|
# |
|
68
|
|
|
|
|
|
|
# =cut |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub describe_query { |
|
71
|
30
|
|
|
30
|
1
|
70
|
my ($self, $arg) = @_; |
|
72
|
30
|
|
|
|
|
52
|
my $desc; |
|
73
|
30
|
100
|
|
|
|
125
|
$desc .= "$arg->{user}'s " if $arg->{user}; |
|
74
|
30
|
|
|
|
|
1589
|
$desc .= "entries"; |
|
75
|
30
|
|
|
|
|
89
|
for (qw(body link)) { |
|
76
|
60
|
50
|
|
|
|
226
|
if (defined $arg->{"has_$_"}) { |
|
77
|
0
|
0
|
|
|
|
0
|
$desc .= " with" . ($arg->{"has_$_"} ? "" : "out") . " a $_,"; |
|
78
|
|
|
|
|
|
|
} |
|
79
|
|
|
|
|
|
|
} |
|
80
|
30
|
50
|
66
|
|
|
240
|
if ($arg->{exact_tags}) { |
|
|
13
|
100
|
|
|
|
98
|
|
|
81
|
0
|
0
|
|
|
|
0
|
if (%{ $arg->{exact_tags} }) { |
|
|
0
|
|
|
|
|
0
|
|
|
82
|
0
|
0
|
|
|
|
0
|
$desc .= " filed under { " |
|
83
|
|
|
|
|
|
|
. join(', ', |
|
84
|
0
|
|
|
|
|
0
|
map { defined $arg->{exact_tags}{$_} |
|
85
|
|
|
|
|
|
|
? "$_:$arg->{exact_tags}{$_}" |
|
86
|
|
|
|
|
|
|
: $_ } |
|
87
|
0
|
|
|
|
|
0
|
keys %{$arg->{exact_tags}}) . " } exactly"; |
|
88
|
|
|
|
|
|
|
} else { |
|
89
|
0
|
|
|
|
|
0
|
$desc .= " without tags" |
|
90
|
|
|
|
|
|
|
} |
|
91
|
|
|
|
|
|
|
} elsif ($arg->{tags} and %{ $arg->{tags} }) { |
|
92
|
13
|
50
|
|
|
|
92
|
$desc .= " filed under { " |
|
93
|
|
|
|
|
|
|
. join(', ', |
|
94
|
13
|
|
|
|
|
106
|
map { defined $arg->{tags}{$_} ? "$_:$arg->{tags}{$_}" : $_ } |
|
95
|
13
|
|
|
|
|
44
|
keys %{$arg->{tags}}) . " }"; |
|
96
|
|
|
|
|
|
|
} |
|
97
|
30
|
|
|
|
|
117
|
$desc =~ s/,\Z//; |
|
98
|
30
|
|
|
|
|
155
|
return $desc; |
|
99
|
|
|
|
|
|
|
} |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
# =head2 get_arg($param => $value) |
|
102
|
|
|
|
|
|
|
# |
|
103
|
|
|
|
|
|
|
# Given a name/value pair from the path, this method will attempt to |
|
104
|
|
|
|
|
|
|
# generate part of hash to send to << Rubric::Entry->query >>. To do this, it |
|
105
|
|
|
|
|
|
|
# looks for and calls a method called "arg_for_NAME" where NAME is the passed |
|
106
|
|
|
|
|
|
|
# value of C<$param>. If no clause can be generated, it returns undef. |
|
107
|
|
|
|
|
|
|
# |
|
108
|
|
|
|
|
|
|
# =cut |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub get_arg { |
|
111
|
22
|
|
|
22
|
1
|
67
|
my ($self, $param, $value) = @_; |
|
112
|
|
|
|
|
|
|
|
|
113
|
22
|
50
|
|
|
|
209
|
return unless my $code = $self->can("arg_for_$param"); |
|
114
|
22
|
|
|
|
|
91
|
$code->($self, $value); |
|
115
|
|
|
|
|
|
|
} |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
# =head2 arg_for_NAME |
|
118
|
|
|
|
|
|
|
# |
|
119
|
|
|
|
|
|
|
# Each of these functions returns the proper value to put in the hash passed to |
|
120
|
|
|
|
|
|
|
# C<< Rubric::Entries->query >>. If given an invalid argument, they will return |
|
121
|
|
|
|
|
|
|
# undef. |
|
122
|
|
|
|
|
|
|
# |
|
123
|
|
|
|
|
|
|
# =head3 arg_for_user($username) |
|
124
|
|
|
|
|
|
|
# |
|
125
|
|
|
|
|
|
|
# Given a username, this method returns the associated Rubric::User object. |
|
126
|
|
|
|
|
|
|
# |
|
127
|
|
|
|
|
|
|
# =cut |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
sub arg_for_user { |
|
130
|
8
|
|
|
8
|
1
|
21
|
my ($self, $user) = @_; |
|
131
|
8
|
50
|
|
|
|
33
|
return unless $user; |
|
132
|
8
|
|
33
|
|
|
67
|
return Rubric::User->retrieve($user) || (); |
|
133
|
|
|
|
|
|
|
} |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
# =head3 arg_for_tags($tagstring) |
|
136
|
|
|
|
|
|
|
# |
|
137
|
|
|
|
|
|
|
# =head3 arg_for_exact_tags($tagstring) |
|
138
|
|
|
|
|
|
|
# |
|
139
|
|
|
|
|
|
|
# Given "happy fuzzy bunnies" this returns C< [ qw(happy fuzzy bunnies) ] > |
|
140
|
|
|
|
|
|
|
# |
|
141
|
|
|
|
|
|
|
# =cut |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
sub arg_for_tags { |
|
144
|
13
|
|
|
13
|
1
|
41
|
my ($self, $tagstring) = @_; |
|
145
|
|
|
|
|
|
|
|
|
146
|
13
|
|
|
|
|
25
|
my $tags; |
|
147
|
13
|
|
|
|
|
32
|
eval { $tags = Rubric::Entry->tags_from_string($tagstring) }; |
|
|
13
|
|
|
|
|
135
|
|
|
148
|
13
|
|
|
|
|
3091
|
return $tags; |
|
149
|
|
|
|
|
|
|
} |
|
150
|
|
|
|
|
|
|
|
|
151
|
0
|
|
|
0
|
1
|
0
|
sub arg_for_exact_tags { (shift)->arg_for_tags(@_) } |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
# =head3 arg_for_desc_like |
|
154
|
|
|
|
|
|
|
# |
|
155
|
|
|
|
|
|
|
# =cut |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
sub arg_for_desc_like { |
|
158
|
0
|
|
|
0
|
1
|
0
|
my ($self, $value) = @_; |
|
159
|
0
|
|
|
|
|
0
|
return $value; |
|
160
|
|
|
|
|
|
|
} |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
# =head3 arg_for_body_like |
|
163
|
|
|
|
|
|
|
# |
|
164
|
|
|
|
|
|
|
# =cut |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
sub arg_for_body_like { |
|
167
|
0
|
|
|
0
|
1
|
0
|
my ($self, $value) = @_; |
|
168
|
0
|
|
|
|
|
0
|
return $value; |
|
169
|
|
|
|
|
|
|
} |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
# =head3 arg_for_like |
|
172
|
|
|
|
|
|
|
# |
|
173
|
|
|
|
|
|
|
# =cut |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
sub arg_for_like { |
|
176
|
0
|
|
|
0
|
1
|
0
|
my ($self, $value) = @_; |
|
177
|
0
|
|
|
|
|
0
|
return $value; |
|
178
|
|
|
|
|
|
|
} |
|
179
|
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
# =head3 arg_for_has_body($bool) |
|
181
|
|
|
|
|
|
|
# |
|
182
|
|
|
|
|
|
|
# Returns the given boolean as 0 or 1. |
|
183
|
|
|
|
|
|
|
# |
|
184
|
|
|
|
|
|
|
# =cut |
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
sub arg_for_has_body { |
|
187
|
0
|
|
|
0
|
1
|
0
|
my ($self, $bool) = @_; |
|
188
|
0
|
0
|
|
|
|
0
|
return $bool ? 1 : 0; |
|
189
|
|
|
|
|
|
|
} |
|
190
|
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
# =head3 arg_for_has_link($bool) |
|
192
|
|
|
|
|
|
|
# |
|
193
|
|
|
|
|
|
|
# Returns the given boolean as 0 or 1. |
|
194
|
|
|
|
|
|
|
# |
|
195
|
|
|
|
|
|
|
# =cut |
|
196
|
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
sub arg_for_has_link { |
|
198
|
0
|
|
|
0
|
1
|
0
|
my ($self, $bool) = @_; |
|
199
|
0
|
0
|
|
|
|
0
|
return $bool ? 1 : 0; |
|
200
|
|
|
|
|
|
|
} |
|
201
|
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
# =head3 arg_for_first_only($bool) |
|
203
|
|
|
|
|
|
|
# |
|
204
|
|
|
|
|
|
|
# Returns the given boolean as 0 or 1. |
|
205
|
|
|
|
|
|
|
# |
|
206
|
|
|
|
|
|
|
# =cut |
|
207
|
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
sub arg_for_first_only { |
|
209
|
0
|
|
|
0
|
1
|
0
|
my ($self, $bool) = @_; |
|
210
|
0
|
0
|
|
|
|
0
|
return $bool ? 1 : 0; |
|
211
|
|
|
|
|
|
|
} |
|
212
|
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
# =head3 arg_for_urimd5($md5sum) |
|
214
|
|
|
|
|
|
|
# |
|
215
|
|
|
|
|
|
|
# This method returns the passed value, if that value is a valid 32-character |
|
216
|
|
|
|
|
|
|
# md5sum. |
|
217
|
|
|
|
|
|
|
# |
|
218
|
|
|
|
|
|
|
# =cut |
|
219
|
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
sub arg_for_urimd5 { |
|
221
|
1
|
|
|
1
|
1
|
4
|
my ($self, $md5) = @_; |
|
222
|
1
|
50
|
|
|
|
8
|
return unless $md5 =~ /\A[a-z0-9]{32}\Z/i; |
|
223
|
1
|
|
|
|
|
8
|
return $md5; |
|
224
|
|
|
|
|
|
|
} |
|
225
|
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
# =head3 arg_for_{timefield}_{preposition}($datetime) |
|
227
|
|
|
|
|
|
|
# |
|
228
|
|
|
|
|
|
|
# These methods correspond to those described in L. |
|
229
|
|
|
|
|
|
|
# |
|
230
|
|
|
|
|
|
|
# They return the passed string unchanged. |
|
231
|
|
|
|
|
|
|
# |
|
232
|
|
|
|
|
|
|
# =cut |
|
233
|
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
## more date-arg handling code |
|
235
|
|
|
|
|
|
|
{ |
|
236
|
|
|
|
|
|
|
## no critic (ProhibitNoStrict) |
|
237
|
2
|
|
|
2
|
|
15
|
no strict 'refs'; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
226
|
|
|
238
|
|
|
|
|
|
|
for my $field (qw(created modified)) { |
|
239
|
|
|
|
|
|
|
for my $prep (qw(after before on)) { |
|
240
|
|
|
|
|
|
|
*{"arg_for_${field}_${prep}"} = sub { |
|
241
|
0
|
|
|
0
|
|
|
my ($self, $datetime) = @_; |
|
242
|
0
|
|
|
|
|
|
return $datetime; |
|
243
|
|
|
|
|
|
|
} |
|
244
|
|
|
|
|
|
|
} |
|
245
|
|
|
|
|
|
|
} |
|
246
|
|
|
|
|
|
|
} |
|
247
|
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
1; |
|
249
|
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
__END__ |