File Coverage

blib/lib/Rubric/WebApp/URI.pm
Criterion Covered Total %
statement 65 68 95.5
branch 22 32 68.7
condition 8 17 47.0
subroutine 19 20 95.0
pod 16 16 100.0
total 130 153 84.9


line stmt bran cond sub pod time code
1 5     5   3756 use strict;
  5         8  
  5         110  
2 5     5   19 use warnings;
  5         10  
  5         144  
3             # ABSTRACT: URIs for Rubric web requests
4              
5             #pod =head1 DESCRIPTION
6             #pod
7             #pod This module provides methods for generating the URIs for Rubric requests.
8             #pod
9             #pod =cut
10              
11             use Rubric::Config;
12 5     5   24 use Scalar::Util ();
  5         7  
  5         23  
13 5     5   24  
  5         7  
  5         3600  
14             #pod =head1 METHODS
15             #pod
16             #pod =head2 root
17             #pod
18             #pod the URI for the root of the Rubric; taken from uri_root in config
19             #pod
20             #pod =cut
21              
22              
23 434     434 1 1978 #pod =head2 stylesheet
24             #pod
25             #pod the URI for the stylesheet
26             #pod
27             #pod =cut
28              
29             my $href = Rubric::Config->css_href;
30             return $href if $href;
31             return Rubric::Config->uri_root . '/style/rubric.css';
32 85     85 1 2424 }
33 85 50       168  
34 85         188 #pod =head2 logout
35             #pod
36             #pod URI to log out
37             #pod
38             #pod =cut
39              
40              
41             #pod =head2 login
42             #pod
43 13     13 1 119 #pod URI to form for log in
44             #pod
45             #pod =cut
46              
47             my $uri = Rubric::Config->uri_root . '/login';
48             $uri =~ s/^http:/https:/i if Rubric::Config->secure_login;
49             return $uri;
50             }
51              
52 36     36 1 378 #pod =head2 reset_password
53 36 50       106 #pod
54 36         113 #pod URI to reset user password
55             #pod
56             #pod =cut
57              
58             my ($class, $arg) = @_;
59             my $uri = Rubric::Config->uri_root . '/reset_password';
60             if ($arg->{user} and defined $arg->{reset_code}) {
61             $uri .= "/$arg->{user}/$arg->{reset_code}";
62             }
63             return $uri;
64 6     6 1 65 }
65 6         20  
66 6 50 33     27 #pod =head2 newuser
67 0         0 #pod
68             #pod URI to form for new user registration form; returns false if registration is
69 6         23 #pod closed.
70             #pod
71             #pod =cut
72              
73             return if Rubric::Config->registration_closed;
74             return Rubric::Config->uri_root . '/newuser';
75             }
76              
77             #pod =head2 entries(\%arg)
78             #pod
79             #pod URI for entry listing; valid keys for C<%arg>:
80 60 50   60 1 593 #pod
81 60         106 #pod user - entries for one user
82             #pod tags - arrayref of tag names
83             #pod
84             #pod =cut
85              
86             my ($class, $arg) = @_;
87             $arg->{tags} ||= {};
88             $arg->{tags} = { map { $_ => undef } @{$arg->{tags}} }
89             if ref $arg->{tags} eq 'ARRAY';
90              
91             my $format = delete $arg->{format};
92              
93             my $uri = $class->root . '/entries';
94 387     387 1 180526 $uri .= "/user/$arg->{user}" if $arg->{user};
95 387   100     1582 $uri .= '/tags/' . join('+', keys %{$arg->{tags}}) if %{$arg->{tags}};
96 221         773 for (qw(has_body has_link)) {
  212         462  
97 387 100       1099 $uri .= "/$_/" . ($arg->{$_} ? 1 : 0)
98             if (defined $arg->{$_} and $arg->{$_} ne '');
99 387         993 }
100             $uri .= "/urimd5/$arg->{urimd5}" if $arg->{urimd5};
101 387         1175 $uri .= "?format=$format" if $format;
102 387 100       1028 return $uri;
103 387 100       31743 }
  238         975  
  387         1120  
104 387         839  
105             #pod =head2 entry($entry)
106 774 0 66     2129 #pod
    50          
107             #pod URI to view entry
108 387 100       834 #pod
109 387 100       842 #pod =cut
110 387         2472  
111             my ($class, $entry) = @_;
112             return unless Scalar::Util::blessed($entry) && $entry->isa('Rubric::Entry');
113              
114             return Rubric::Config->uri_root . "/entry/" . $entry->id;
115             }
116              
117             #pod =head2 edit_entry($entry)
118             #pod
119             #pod URI to edit entry
120 45     45 1 609 #pod
121 45 50 33     445 #pod =cut
122              
123 45         232 my ($class, $entry) = @_;
124             return unless Scalar::Util::blessed($entry) && $entry->isa('Rubric::Entry');
125              
126             return Rubric::Config->uri_root . "/edit/" . $entry->id;
127             }
128              
129             #pod =head2 delete_entry($entry)
130             #pod
131             #pod URI to delete entry
132             #pod
133 3     3 1 40 #pod =cut
134 3 50 33     31  
135             my ($class, $entry) = @_;
136 3         13 return unless Scalar::Util::blessed($entry) && $entry->isa('Rubric::Entry');
137              
138             return Rubric::Config->uri_root . "/delete/" . $entry->id;
139             }
140              
141             #pod =head2 post_entry
142             #pod
143             #pod URI for new entry form
144             #pod
145             #pod =cut
146 1     1 1 12  
147 1 50 33     10  
148             #pod =head2 by_date
149 1         5 #pod
150             #pod URI for by_date
151             #pod
152             #pod =cut
153              
154             my ($class) = @_;
155             shift;
156             my $year = shift;
157             my $month = shift;
158 33     33 1 710 my $uri = '/calendar';
159             $uri .= "/$year" if ($year);
160             $uri .= "/$month" if ($month);
161              
162             Rubric::Config->uri_root . $uri;
163             }
164              
165              
166              
167 44     44 1 461 #pod =head2 tag_cloud
168 44         74 #pod
169 44         58 #pod URI for all tags / tag cloud
170 44         73 #pod
171 44         75 #pod =cut
172 44 100       112  
173 44 100       102 my ($class) = @_;
174             Rubric::Config->uri_root . "/tag_cloud";
175 44         90 }
176              
177             #pod =head2 preferences
178             #pod
179             #pod URI for preferences form
180             #pod
181             #pod =cut
182              
183              
184              
185             #pod =head2 verify_user
186             #pod
187 42     42 1 402 #pod URI for new entry form
188 42         101 #pod
189             #pod =cut
190              
191             my ($class, $user) = @_;
192             Rubric::Config->uri_root . "/verify/$user/" . $user->verification_code;
193             }
194              
195             #pod =head2 doc($doc_page)
196             #pod
197             #pod URI for documentation page.
198 12     12 1 125 #pod
199             #pod =cut
200              
201             my ($class, $doc_page) = @_;
202             Rubric::Config->uri_root . "/doc/" . $doc_page;
203             }
204              
205             1;
206              
207 0     0 1 0  
208 0         0 =pod
209              
210             =encoding UTF-8
211              
212             =head1 NAME
213              
214             Rubric::WebApp::URI - URIs for Rubric web requests
215              
216             =head1 VERSION
217              
218 42     42 1 574 version 0.157
219 42         116  
220             =head1 DESCRIPTION
221              
222             This module provides methods for generating the URIs for Rubric requests.
223              
224             =head1 PERL VERSION
225              
226             This code is effectively abandonware. Although releases will sometimes be made
227             to update contact info or to fix packaging flaws, bug reports will mostly be
228             ignored. Feature requests are even more likely to be ignored. (If someone
229             takes up maintenance of this code, they will presumably remove this notice.)
230             This means that whatever version of perl is currently required is unlikely to
231             change -- but also that it might change at any new maintainer's whim.
232              
233             =head1 METHODS
234              
235             =head2 root
236              
237             the URI for the root of the Rubric; taken from uri_root in config
238              
239             =head2 stylesheet
240              
241             the URI for the stylesheet
242              
243             =head2 logout
244              
245             URI to log out
246              
247             =head2 login
248              
249             URI to form for log in
250              
251             =head2 reset_password
252              
253             URI to reset user password
254              
255             =head2 newuser
256              
257             URI to form for new user registration form; returns false if registration is
258             closed.
259              
260             =head2 entries(\%arg)
261              
262             URI for entry listing; valid keys for C<%arg>:
263              
264             user - entries for one user
265             tags - arrayref of tag names
266              
267             =head2 entry($entry)
268              
269             URI to view entry
270              
271             =head2 edit_entry($entry)
272              
273             URI to edit entry
274              
275             =head2 delete_entry($entry)
276              
277             URI to delete entry
278              
279             =head2 post_entry
280              
281             URI for new entry form
282              
283             =head2 by_date
284              
285             URI for by_date
286              
287             =head2 tag_cloud
288              
289             URI for all tags / tag cloud
290              
291             =head2 preferences
292              
293             URI for preferences form
294              
295             =head2 verify_user
296              
297             URI for new entry form
298              
299             =head2 doc($doc_page)
300              
301             URI for documentation page.
302              
303             =head1 AUTHOR
304              
305             Ricardo SIGNES <rjbs@semiotic.systems>
306              
307             =head1 COPYRIGHT AND LICENSE
308              
309             This software is copyright (c) 2004 by Ricardo SIGNES.
310              
311             This is free software; you can redistribute it and/or modify it under
312             the same terms as the Perl 5 programming language system itself.
313              
314             =cut