File Coverage

blib/lib/Rubric/WebApp/URI.pm
Criterion Covered Total %
statement 63 66 95.4
branch 21 30 70.0
condition 8 17 47.0
subroutine 19 20 95.0
pod 16 16 100.0
total 127 149 85.2


line stmt bran cond sub pod time code
1 5     5   12156 use strict;
  5         11  
  5         197  
2 5     5   31 use warnings;
  5         11  
  5         277  
3             package Rubric::WebApp::URI;
4             # ABSTRACT: URIs for Rubric web requests
5             $Rubric::WebApp::URI::VERSION = '0.155';
6             # =head1 DESCRIPTION
7             #
8             # This module provides methods for generating the URIs for Rubric requests.
9             #
10             # =cut
11              
12 5     5   27 use Rubric::Config;
  5         9  
  5         35  
13 5     5   37 use Scalar::Util ();
  5         12  
  5         12499  
14              
15             # =head1 METHODS
16             #
17             # =head2 root
18             #
19             # the URI for the root of the Rubric; taken from uri_root in config
20             #
21             # =cut
22              
23 436     436 1 2131 sub root { Rubric::Config->uri_root }
24              
25             # =head2 stylesheet
26             #
27             # the URI for the stylesheet
28             #
29             # =cut
30              
31             sub stylesheet {
32 85     85 1 6749 my $href = Rubric::Config->css_href;
33 85 50       273 return $href if $href;
34 85         291 return Rubric::Config->uri_root . '/style/rubric.css';
35             }
36              
37             # =head2 logout
38             #
39             # URI to log out
40             #
41             # =cut
42              
43 13     13 1 156 sub logout { Rubric::Config->uri_root . '/logout' }
44              
45             # =head2 login
46             #
47             # URI to form for log in
48             #
49             # =cut
50              
51 36     36 1 535 sub login { Rubric::Config->uri_root . '/login' }
52              
53             # =head2 reset_password
54             #
55             # URI to reset user password
56             #
57             # =cut
58              
59             sub reset_password {
60 6     6 1 66 my ($class, $arg) = @_;
61 6         27 my $uri = Rubric::Config->uri_root . '/reset_password';
62 6 50 33     35 if ($arg->{user} and defined $arg->{reset_code}) {
63 0         0 $uri .= "/$arg->{user}/$arg->{reset_code}";
64             }
65 6         64 return $uri;
66             }
67              
68             # =head2 newuser
69             #
70             # URI to form for new user registration form; returns false if registration is
71             # closed.
72             #
73             # =cut
74              
75             sub newuser {
76 60 50   60 1 874 return if Rubric::Config->registration_closed;
77 60         183 return Rubric::Config->uri_root . '/newuser';
78             }
79              
80             # =head2 entries(\%arg)
81             #
82             # URI for entry listing; valid keys for C<%arg>:
83             #
84             # user - entries for one user
85             # tags - arrayref of tag names
86             #
87             # =cut
88              
89             sub entries {
90 389     389 1 140352 my ($class, $arg) = @_;
91 389   100     1790 $arg->{tags} ||= {};
92 389 100       1396 $arg->{tags} = { map { $_ => undef } @{$arg->{tags}} }
  223         1090  
  214         561  
93             if ref $arg->{tags} eq 'ARRAY';
94              
95 389         1273 my $format = delete $arg->{format};
96              
97 389         1120 my $uri = $class->root . '/entries';
98 389 100       1541 $uri .= "/user/$arg->{user}" if $arg->{user};
99 389 100       27039 $uri .= '/tags/' . join('+', keys %{$arg->{tags}}) if %{$arg->{tags}};
  240         1007  
  389         1422  
100 389         859 for (qw(has_body has_link)) {
101 778 0 66     3272 $uri .= "/$_/" . ($arg->{$_} ? 1 : 0)
    50          
102             if (defined $arg->{$_} and $arg->{$_} ne '');
103             }
104 389 100       1130 $uri .= "/urimd5/$arg->{urimd5}" if $arg->{urimd5};
105 389 100       1786 $uri .= "?format=$format" if $format;
106 389         3580 return $uri;
107             }
108              
109             # =head2 entry($entry)
110             #
111             # URI to view entry
112             #
113             # =cut
114              
115             sub entry {
116 45     45 1 3068 my ($class, $entry) = @_;
117 45 50 33     501 return unless Scalar::Util::blessed($entry) && $entry->isa('Rubric::Entry');
118              
119 45         267 return Rubric::Config->uri_root . "/entry/" . $entry->id;
120             }
121              
122             # =head2 edit_entry($entry)
123             #
124             # URI to edit entry
125             #
126             # =cut
127              
128             sub edit_entry {
129 3     3 1 51 my ($class, $entry) = @_;
130 3 50 33     111 return unless Scalar::Util::blessed($entry) && $entry->isa('Rubric::Entry');
131              
132 3         18 return Rubric::Config->uri_root . "/edit/" . $entry->id;
133             }
134              
135             # =head2 delete_entry($entry)
136             #
137             # URI to delete entry
138             #
139             # =cut
140              
141             sub delete_entry {
142 1     1 1 21 my ($class, $entry) = @_;
143 1 50 33     17 return unless Scalar::Util::blessed($entry) && $entry->isa('Rubric::Entry');
144              
145 1         8 return Rubric::Config->uri_root . "/delete/" . $entry->id;
146             }
147              
148             # =head2 post_entry
149             #
150             # URI for new entry form
151             #
152             # =cut
153              
154 33     33 1 595 sub post_entry { Rubric::Config->uri_root . "/post"; }
155              
156             # =head2 by_date
157             #
158             # URI for by_date
159             #
160             # =cut
161              
162             sub by_date {
163 44     44 1 544 my ($class) = @_;
164 44         87 shift;
165 44         90 my $year = shift;
166 44         130 my $month = shift;
167 44         88 my $uri = '/calendar';
168 44 100       129 $uri .= "/$year" if ($year);
169 44 100       145 $uri .= "/$month" if ($month);
170              
171 44         159 Rubric::Config->uri_root . $uri;
172             }
173              
174              
175              
176             # =head2 tag_cloud
177             #
178             # URI for all tags / tag cloud
179             #
180             # =cut
181              
182             sub tag_cloud {
183 42     42 1 462 my ($class) = @_;
184 42         175 Rubric::Config->uri_root . "/tag_cloud";
185             }
186              
187             # =head2 preferences
188             #
189             # URI for preferences form
190             #
191             # =cut
192              
193              
194 12     12 1 145 sub preferences { Rubric::Config->uri_root . "/preferences"; }
195              
196             # =head2 verify_user
197             #
198             # URI for new entry form
199             #
200             # =cut
201              
202             sub verify_user {
203 0     0 1 0 my ($class, $user) = @_;
204 0         0 Rubric::Config->uri_root . "/verify/$user/" . $user->verification_code;
205             }
206              
207             # =head2 doc($doc_page)
208             #
209             # URI for documentation page.
210             #
211             # =cut
212              
213             sub doc {
214 42     42 1 534 my ($class, $doc_page) = @_;
215 42         153 Rubric::Config->uri_root . "/doc/" . $doc_page;
216             }
217              
218             1;
219              
220             __END__