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