Commit | Line | Data |
89de6a33 |
1 | package Gitalist::Controller::Root; |
42fe5d11 |
2 | use Moose; |
3 | use namespace::autoclean; |
89de6a33 |
4 | |
42fe5d11 |
5 | BEGIN { extends 'Catalyst::Controller' } |
89de6a33 |
6 | |
7 | # |
8 | # Sets the actions in this controller to be registered with no prefix |
9 | # so they function identically to actions created in MyApp.pm |
10 | # |
11 | __PACKAGE__->config->{namespace} = ''; |
12 | |
13 | =head1 NAME |
14 | |
15 | Gitalist::Controller::Root - Root Controller for Gitalist |
16 | |
17 | =head1 DESCRIPTION |
18 | |
19 | [enter your description here] |
20 | |
21 | =head1 METHODS |
22 | |
23 | =cut |
24 | |
25 | =head2 index |
26 | |
27 | =cut |
28 | |
89de6a33 |
29 | use IO::Capture::Stdout; |
d3feefcf |
30 | |
1625cd5f |
31 | =head2 run_gitweb |
32 | |
f71a83ab |
33 | The C<gitweb> shim. It should now only be explicitly accessible by |
34 | modifying the URL. |
1625cd5f |
35 | |
36 | =cut |
37 | |
e66db0fb |
38 | sub run_gitweb { |
86382b95 |
39 | my ( $self, $c ) = @_; |
40 | |
e66db0fb |
41 | # XXX A slippery slope to be sure. |
42 | if($c->req->param('a')) { |
43 | my $capture = IO::Capture::Stdout->new(); |
44 | $capture->start(); |
45 | eval { |
46 | my $action = gitweb::main($c); |
47 | $action->(); |
48 | }; |
49 | $capture->stop(); |
5a2f0948 |
50 | |
e66db0fb |
51 | use Data::Dumper; |
52 | die Dumper($@) |
53 | if $@; |
5a2f0948 |
54 | |
e66db0fb |
55 | my $output = join '', $capture->read; |
56 | $c->stash->{gitweb_output} = $output; |
57 | $c->stash->{template} = 'gitweb.tt2'; |
58 | } |
86382b95 |
59 | } |
60 | |
9dc3b9a5 |
61 | sub _get_commit { |
b4b4d0fd |
62 | my($self, $c, $haveh) = @_; |
9dc3b9a5 |
63 | |
c1f608c8 |
64 | my $h = $haveh || $c->req->param('h') || ''; |
0ee97fec |
65 | my $f = $c->req->param('f'); |
8dbe8024 |
66 | |
67 | # FIXME this can die when everything is migrated |
68 | my ($m, $pd); |
69 | if ($c->stash->{current_model} eq 'GitRepos') { |
70 | $m = $c->model()->project($c->stash->{project}); |
71 | $pd = $m->path; |
72 | } else { |
73 | $m = $c->model(); |
74 | ($pd = $m->project_dir( $m->project )) =~ s{/\.git$}(); |
75 | } |
0ee97fec |
76 | |
9dc3b9a5 |
77 | # Either use the provided h(ash) parameter, the f(ile) parameter or just use HEAD. |
a7cc1ede |
78 | my $hash = ($h =~ /[^a-f0-9]/ ? $m->head_hash($h) : $h) |
79 | || ($f && $m->hash_by_path($f)) |
80 | || $m->head_hash |
9dc3b9a5 |
81 | # XXX This could definitely use more context. |
82 | || Carp::croak("Couldn't find a hash for the commit object!"); |
83 | |
a7cc1ede |
84 | my $commit = $m->get_object($hash) |
85 | or Carp::croak("Couldn't find a commit object for '$hash' in '$pd'!"); |
9dc3b9a5 |
86 | |
87 | return $commit; |
88 | } |
89 | |
1625cd5f |
90 | =head2 index |
91 | |
92 | Provides the project listing. |
93 | |
94 | =cut |
95 | |
86382b95 |
96 | sub index :Path :Args(0) { |
d5cc37a4 |
97 | my ( $self, $c ) = @_; |
7b0f7465 |
98 | $c->stash(current_model => 'GitRepos'); |
e66db0fb |
99 | # Leave actions up to gitweb at this point. |
100 | return $self->run_gitweb($c) |
101 | if $c->req->param('a'); |
102 | |
887260eb |
103 | my $list = $c->model()->list_projects; |
d5cc37a4 |
104 | unless(@$list) { |
7b0f7465 |
105 | die "No projects found in ". $c->model->repo_dir; |
86382b95 |
106 | } |
107 | |
d5cc37a4 |
108 | $c->stash( |
109 | searchtext => $c->req->param('searchtext') || '', |
110 | projects => $list, |
111 | action => 'index', |
112 | ); |
04d1d917 |
113 | } |
114 | |
790ce598 |
115 | =head2 summary |
116 | |
117 | A summary of what's happening in the repo. |
118 | |
119 | =cut |
120 | |
121 | sub summary : Local { |
122 | my ( $self, $c ) = @_; |
123 | |
9dc3b9a5 |
124 | my $commit = $self->_get_commit($c); |
790ce598 |
125 | $c->stash( |
126 | commit => $commit, |
887260eb |
127 | info => $c->model()->project_info($c->model()->project), |
128 | log_lines => [$c->model()->list_revs( |
fde5091f |
129 | sha1 => $commit->sha1, count => Gitalist->config->{paging}{summary} |
130 | )], |
887260eb |
131 | refs => $c->model()->references, |
132 | heads => [$c->model()->heads], |
790ce598 |
133 | action => 'summary', |
134 | ); |
135 | } |
136 | |
137 | =head2 heads |
138 | |
139 | The current list of heads (aka branches) in the repo. |
140 | |
141 | =cut |
142 | |
143 | sub heads : Local { |
144 | my ( $self, $c ) = @_; |
8dbe8024 |
145 | $c->stash( current_model => 'GitRepos' ); |
146 | my $project = $c->model()->project( $c->stash->{project} ); |
790ce598 |
147 | $c->stash( |
9dc3b9a5 |
148 | commit => $self->_get_commit($c), |
8dbe8024 |
149 | heads => [$project->heads], |
790ce598 |
150 | action => 'heads', |
151 | ); |
152 | } |
153 | |
1625cd5f |
154 | =head2 blob |
155 | |
156 | The blob action i.e the contents of a file. |
157 | |
158 | =cut |
159 | |
295c9703 |
160 | sub blob : Local { |
161 | my ( $self, $c ) = @_; |
162 | |
c8870bd3 |
163 | my $h = $c->req->param('h') |
887260eb |
164 | || $c->model()->hash_by_path($c->req->param('f')) |
c8870bd3 |
165 | || die "No file or sha1 provided."; |
166 | my $hb = $c->req->param('hb') |
887260eb |
167 | || $c->model()->head_hash |
c8870bd3 |
168 | || die "Couldn't discern the corresponding head."; |
169 | |
f5da8e7a |
170 | my $filename = $c->req->param('f') || ''; |
171 | |
295c9703 |
172 | $c->stash( |
887260eb |
173 | blob => $c->model()->get_object($h)->content, |
174 | head => $c->model()->get_object($hb), |
f5da8e7a |
175 | filename => $filename, |
176 | # XXX Hack hack hack, see View::SyntaxHighlight |
177 | language => ($filename =~ /\.p[lm]$/ ? 'Perl' : ''), |
c8870bd3 |
178 | action => 'blob', |
295c9703 |
179 | ); |
7e54e579 |
180 | |
c8870bd3 |
181 | $c->forward('View::SyntaxHighlight'); |
295c9703 |
182 | } |
183 | |
6cf4366a |
184 | =head2 blobdiff |
185 | |
186 | Exposes a given diff of a blob. |
187 | |
188 | =cut |
189 | |
190 | sub blobdiff : Local { |
191 | my ( $self, $c ) = @_; |
192 | |
193 | my $commit = $self->_get_commit($c); |
194 | my $filename = $c->req->param('f') |
195 | || croak("No file specified!"); |
887260eb |
196 | my($tree, $patch) = $c->model()->diff( |
ad8884fc |
197 | commit => $commit, |
198 | parent => $c->req->param('hp') || '', |
199 | file => $filename, |
200 | patch => 1, |
6cf4366a |
201 | ); |
202 | $c->stash( |
203 | commit => $commit, |
ad8884fc |
204 | diff => $patch, |
6cf4366a |
205 | # XXX Hack hack hack, see View::SyntaxHighlight |
ad8884fc |
206 | blobs => [$patch->[0]->{diff}], |
6cf4366a |
207 | language => 'Diff', |
208 | action => 'blobdiff', |
209 | ); |
210 | |
211 | $c->forward('View::SyntaxHighlight'); |
212 | } |
213 | |
1625cd5f |
214 | =head2 commit |
215 | |
47495599 |
216 | Exposes a given commit. |
1625cd5f |
217 | |
218 | =cut |
219 | |
1feb3d6b |
220 | sub commit : Local { |
d7c9a32f |
221 | my ( $self, $c ) = @_; |
b7aca93a |
222 | |
9dc3b9a5 |
223 | my $commit = $self->_get_commit($c); |
b7aca93a |
224 | $c->stash( |
790ce598 |
225 | commit => $commit, |
887260eb |
226 | diff_tree => ($c->model()->diff(commit => $commit))[0], |
1fd8159c |
227 | refs => $c->model()->references, |
790ce598 |
228 | action => 'commit', |
b7aca93a |
229 | ); |
d7c9a32f |
230 | } |
231 | |
2247133f |
232 | =head2 commitdiff |
233 | |
234 | Exposes a given diff of a commit. |
235 | |
236 | =cut |
237 | |
238 | sub commitdiff : Local { |
239 | my ( $self, $c ) = @_; |
240 | |
9dc3b9a5 |
241 | my $commit = $self->_get_commit($c); |
887260eb |
242 | my($tree, $patch) = $c->model()->diff( |
ad8884fc |
243 | commit => $commit, |
244 | parent => $c->req->param('hp') || '', |
245 | patch => 1, |
246 | ); |
2247133f |
247 | $c->stash( |
f5da8e7a |
248 | commit => $commit, |
ad8884fc |
249 | diff_tree => $tree, |
250 | diff => $patch, |
f5da8e7a |
251 | # XXX Hack hack hack, see View::SyntaxHighlight |
ad8884fc |
252 | blobs => [map $_->{diff}, @$patch], |
f5da8e7a |
253 | language => 'Diff', |
254 | action => 'commitdiff', |
2247133f |
255 | ); |
f5da8e7a |
256 | |
257 | $c->forward('View::SyntaxHighlight'); |
2247133f |
258 | } |
259 | |
47495599 |
260 | =head2 shortlog |
261 | |
262 | Expose an abbreviated log of a given sha1. |
263 | |
264 | =cut |
265 | |
266 | sub shortlog : Local { |
267 | my ( $self, $c ) = @_; |
268 | |
63e220b9 |
269 | my $commit = $self->_get_commit($c); |
fde5091f |
270 | my %logargs = ( |
271 | sha1 => $commit->sha1, |
272 | count => Gitalist->config->{paging}{log}, |
63e220b9 |
273 | ($c->req->param('f') ? (file => $c->req->param('f')) : ()) |
274 | ); |
fde5091f |
275 | |
276 | my $page = $c->req->param('pg') || 0; |
277 | $logargs{skip} = $c->req->param('pg') * $logargs{count} |
278 | if $c->req->param('pg'); |
279 | |
47495599 |
280 | $c->stash( |
790ce598 |
281 | commit => $commit, |
887260eb |
282 | log_lines => [$c->model()->list_revs(%logargs)], |
283 | refs => $c->model()->references, |
790ce598 |
284 | action => 'shortlog', |
b4b4d0fd |
285 | page => $page, |
47495599 |
286 | ); |
287 | } |
288 | |
790ce598 |
289 | =head2 log |
290 | |
291 | Calls shortlog internally. Perhaps that should be reversed ... |
292 | |
293 | =cut |
294 | sub log : Local { |
295 | $_[0]->shortlog($_[1]); |
296 | $_[1]->stash->{action} = 'log'; |
297 | } |
298 | |
b3fa97cd |
299 | =head2 tree |
300 | |
301 | The tree of a given commit. |
302 | |
303 | =cut |
304 | |
305 | sub tree : Local { |
306 | my ( $self, $c ) = @_; |
307 | |
b4b4d0fd |
308 | my $commit = $self->_get_commit($c, $c->req->param('hb')); |
887260eb |
309 | my $tree = $c->model()->get_object($c->req->param('h') || $commit->tree_sha1); |
b3fa97cd |
310 | $c->stash( |
311 | # XXX Useful defaults needed ... |
790ce598 |
312 | commit => $commit, |
b4b4d0fd |
313 | tree => $tree, |
887260eb |
314 | tree_list => [$c->model()->list_tree($tree->sha1)], |
b4b4d0fd |
315 | path => $c->req->param('f') || '', |
790ce598 |
316 | action => 'tree', |
b3fa97cd |
317 | ); |
318 | } |
319 | |
9dc3b9a5 |
320 | =head2 reflog |
321 | |
322 | Expose the local reflog. This may go away. |
323 | |
324 | =cut |
325 | |
326 | sub reflog : Local { |
327 | my ( $self, $c ) = @_; |
328 | |
887260eb |
329 | my @log = $c->model()->reflog( |
9dc3b9a5 |
330 | '--since=yesterday' |
331 | ); |
332 | |
333 | $c->stash( |
334 | log => \@log, |
335 | action => 'reflog', |
336 | ); |
337 | } |
338 | |
14664e1c |
339 | sub search : Local { |
4df2f62f |
340 | my($self, $c) = @_; |
341 | |
342 | my $commit = $self->_get_commit($c); |
343 | # Lifted from /shortlog. |
344 | my %logargs = ( |
345 | sha1 => $commit->sha1, |
346 | count => Gitalist->config->{paging}{log}, |
347 | ($c->req->param('f') ? (file => $c->req->param('f')) : ()), |
348 | search => { |
349 | type => $c->req->param('type'), |
350 | text => $c->req->param('text'), |
351 | regexp => $c->req->param('regexp') || 0, |
352 | } |
353 | ); |
354 | |
355 | $c->stash( |
356 | commit => $commit, |
887260eb |
357 | results => [$c->model()->list_revs(%logargs)], |
4df2f62f |
358 | action => 'search', |
359 | # This could be added - page => $page, |
360 | ); |
14664e1c |
361 | } |
362 | |
363 | sub search_help : Local { |
364 | Carp::croak "Not implemented."; |
365 | } |
366 | |
1625cd5f |
367 | =head2 auto |
368 | |
369 | Populate the header and footer. Perhaps not the best location. |
370 | |
371 | =cut |
372 | |
04d1d917 |
373 | sub auto : Private { |
4621ecf0 |
374 | my($self, $c) = @_; |
04d1d917 |
375 | |
4621ecf0 |
376 | # XXX Move these to a plugin! |
377 | $c->stash( |
378 | time_since => sub { |
379 | return age_string(time - $_[0]->epoch); |
380 | }, |
381 | short_cmt => sub { |
382 | my $cmt = shift; |
383 | my($line) = split /\n/, $cmt; |
384 | $line =~ s/^(.{70,80}\b).*/$1 …/; |
385 | return $line; |
386 | }, |
387 | ); |
388 | |
389 | # Yes, this is hideous. |
390 | $self->header($c); |
391 | $self->footer($c); |
04d1d917 |
392 | } |
393 | |
c5065c66 |
394 | # XXX This could probably be dropped altogether. |
04d1d917 |
395 | use Gitalist::Util qw(to_utf8); |
04d1d917 |
396 | # Formally git_header_html |
397 | sub header { |
398 | my($self, $c) = @_; |
399 | |
c5065c66 |
400 | my $title = $c->config->{sitename}; |
04d1d917 |
401 | |
402 | my $project = $c->req->param('project') || $c->req->param('p'); |
403 | my $action = $c->req->param('action') || $c->req->param('a'); |
404 | my $file_name = $c->req->param('filename') || $c->req->param('f'); |
c5065c66 |
405 | if(defined $project) { |
406 | $title .= " - " . to_utf8($project); |
407 | if (defined $action) { |
408 | $title .= "/$action"; |
409 | if (defined $file_name) { |
410 | $title .= " - " . $file_name; |
411 | if ($action eq "tree" && $file_name !~ m|/$|) { |
412 | $title .= "/"; |
413 | } |
414 | } |
415 | } |
416 | } |
417 | |
418 | $c->stash->{version} = $c->config->{version}; |
887260eb |
419 | $c->stash->{git_version} = $c->model()->run_cmd('--version'); |
c5065c66 |
420 | $c->stash->{title} = $title; |
04d1d917 |
421 | |
422 | #$c->stash->{baseurl} = $ENV{PATH_INFO} && uri_escape($base_url); |
c5065c66 |
423 | $c->stash->{stylesheet} = $c->config->{stylesheet} || 'gitweb.css'; |
04d1d917 |
424 | |
c5065c66 |
425 | $c->stash->{project} = $project; |
04d1d917 |
426 | my @links; |
c5065c66 |
427 | if($project) { |
428 | my %href_params = $self->feed_info($c); |
429 | $href_params{'-title'} ||= 'log'; |
04d1d917 |
430 | |
c5065c66 |
431 | foreach my $format qw(RSS Atom) { |
432 | my $type = lc($format); |
04d1d917 |
433 | push @links, { |
c5065c66 |
434 | rel => 'alternate', |
435 | title => "$project - $href_params{'-title'} - $format feed", |
436 | |
437 | # XXX A bit hacky and could do with using gitweb::href() features |
438 | href => "?a=$type;p=$project", |
439 | type => "application/$type+xml" |
04d1d917 |
440 | }, { |
c5065c66 |
441 | rel => 'alternate', |
442 | |
443 | # XXX This duplication also feels a bit awkward |
444 | title => "$project - $href_params{'-title'} - $format feed (no merges)", |
445 | href => "?a=$type;p=$project;opt=--no-merges", |
446 | type => "application/$type+xml" |
04d1d917 |
447 | }; |
c5065c66 |
448 | } |
449 | } else { |
04d1d917 |
450 | push @links, { |
c5065c66 |
451 | rel => "alternate", |
452 | title => $c->config->{sitename}." projects list", |
453 | href => '?a=project_index', |
454 | type => "text/plain; charset=utf-8" |
455 | }, { |
456 | rel => "alternate", |
457 | title => $c->config->{sitename}." projects feeds", |
458 | href => '?a=opml', |
459 | type => "text/plain; charset=utf-8" |
460 | }; |
461 | } |
04d1d917 |
462 | |
c5065c66 |
463 | $c->stash->{favicon} = $c->config->{favicon}; |
04d1d917 |
464 | |
c5065c66 |
465 | # </head><body> |
86382b95 |
466 | |
c5065c66 |
467 | $c->stash( |
468 | logo_url => $c->config->{logo_url}, |
469 | logo_label => $c->config->{logo_label}, |
470 | logo_img => $c->config->{logo}, |
471 | home_link => $c->config->{home_link}, |
04d1d917 |
472 | home_link_str => $c->config->{home_link_str}, |
c5065c66 |
473 | ); |
04d1d917 |
474 | |
c5065c66 |
475 | if(defined $project) { |
04d1d917 |
476 | $c->stash( |
14664e1c |
477 | search_text => ( $c->req->param('s') || $c->req->param('searchtext') || ''), |
295c9703 |
478 | search_hash => ( $c->req->param('hb') || $c->req->param('hashbase') |
c5065c66 |
479 | || $c->req->param('h') || $c->req->param('hash') |
480 | || 'HEAD' ), |
481 | ); |
482 | } |
04d1d917 |
483 | } |
484 | |
485 | # Formally git_footer_html |
486 | sub footer { |
487 | my($self, $c) = @_; |
488 | |
c5065c66 |
489 | my $feed_class = 'rss_logo'; |
04d1d917 |
490 | |
491 | my @feeds; |
492 | my $project = $c->req->param('project') || $c->req->param('p'); |
c5065c66 |
493 | if(defined $project) { |
d5cc37a4 |
494 | (my $pstr = $project) =~ s[/?\.git$][]; |
887260eb |
495 | my $descr = $c->model()->project_info($project)->{description}; |
c5065c66 |
496 | $c->stash->{project_description} = defined $descr |
497 | ? $descr |
498 | : ''; |
04d1d917 |
499 | |
c5065c66 |
500 | my %href_params = $self->feed_info($c); |
501 | if (!%href_params) { |
502 | $feed_class .= ' generic'; |
503 | } |
504 | $href_params{'-title'} ||= 'log'; |
04d1d917 |
505 | |
506 | @feeds = [ |
507 | map +{ |
508 | class => $feed_class, |
509 | title => "$href_params{'-title'} $_ feed", |
510 | href => "/?p=$project;a=\L$_", |
511 | name => lc $_, |
c5065c66 |
512 | }, qw(RSS Atom) |
513 | ]; |
514 | } else { |
04d1d917 |
515 | @feeds = [ |
516 | map { |
517 | class => $feed_class, |
c5065c66 |
518 | title => '', |
519 | href => "/?a=$_->[0]", |
520 | name => $_->[1], |
521 | }, [opml=>'OPML'],[project_index=>'TXT'], |
522 | ]; |
523 | } |
89de6a33 |
524 | } |
525 | |
04d1d917 |
526 | # XXX This feels wrong here, should probably be refactored. |
527 | # returns hash to be passed to href to generate gitweb URL |
528 | # in -title key it returns description of link |
529 | sub feed_info { |
530 | my($self, $c) = @_; |
531 | |
c5065c66 |
532 | my $format = shift || 'Atom'; |
533 | my %res = (action => lc($format)); |
04d1d917 |
534 | |
c5065c66 |
535 | # feed links are possible only for project views |
536 | return unless $c->req->param('project'); |
04d1d917 |
537 | |
c5065c66 |
538 | # some views should link to OPML, or to generic project feed, |
539 | # or don't have specific feed yet (so they should use generic) |
540 | return if $c->req->param('action') =~ /^(?:tags|heads|forks|tag|search)$/x; |
541 | |
542 | my $branch; |
04d1d917 |
543 | my $hash = $c->req->param('h') || $c->req->param('hash'); |
544 | my $hash_base = $c->req->param('hb') || $c->req->param('hashbase'); |
c5065c66 |
545 | |
546 | # branches refs uses 'refs/heads/' prefix (fullname) to differentiate |
547 | # from tag links; this also makes possible to detect branch links |
548 | if ((defined $hash_base && $hash_base =~ m!^refs/heads/(.*)$!) || |
549 | (defined $hash && $hash =~ m!^refs/heads/(.*)$!)) { |
550 | $branch = $1; |
551 | } |
552 | |
553 | # find log type for feed description (title) |
554 | my $type = 'log'; |
04d1d917 |
555 | my $file_name = $c->req->param('f') || $c->req->param('filename'); |
c5065c66 |
556 | if (defined $file_name) { |
557 | $type = "history of $file_name"; |
558 | $type .= "/" if $c->req->param('action') eq 'tree'; |
559 | $type .= " on '$branch'" if (defined $branch); |
560 | } else { |
561 | $type = "log of $branch" if (defined $branch); |
562 | } |
563 | |
564 | $res{-title} = $type; |
565 | $res{'hash'} = (defined $branch ? "refs/heads/$branch" : undef); |
566 | $res{'file_name'} = $file_name; |
567 | |
568 | return %res; |
04d1d917 |
569 | } |
d9a9b56b |
570 | |
89de6a33 |
571 | =head2 end |
572 | |
573 | Attempt to render a view, if needed. |
574 | |
575 | =cut |
576 | |
fde5091f |
577 | sub end : ActionClass('RenderView') { |
1fd8159c |
578 | my ($self, $c) = @_; |
579 | # Give project views the current HEAD. |
580 | if ($c->stash->{project}) { |
8dbe8024 |
581 | if ($c->stash->{current_model} eq 'GitRepos') { |
582 | my $project = $c->model()->project($c->stash->{project}); |
583 | $c->stash->{HEAD} = $project->head_hash; |
584 | } else { |
585 | $c->stash->{HEAD} = $c->model()->head_hash; |
586 | } |
1fd8159c |
587 | } |
1fd8159c |
588 | } |
d9a9b56b |
589 | |
1fd8159c |
590 | sub age_string { |
591 | my $age = shift; |
592 | my $age_str; |
593 | |
594 | if ($age > 60*60*24*365*2) { |
595 | $age_str = (int $age/60/60/24/365); |
596 | $age_str .= " years ago"; |
597 | } elsif ($age > 60*60*24*(365/12)*2) { |
598 | $age_str = int $age/60/60/24/(365/12); |
599 | $age_str .= " months ago"; |
600 | } elsif ($age > 60*60*24*7*2) { |
601 | $age_str = int $age/60/60/24/7; |
602 | $age_str .= " weeks ago"; |
603 | } elsif ($age > 60*60*24*2) { |
604 | $age_str = int $age/60/60/24; |
605 | $age_str .= " days ago"; |
606 | } elsif ($age > 60*60*2) { |
607 | $age_str = int $age/60/60; |
608 | $age_str .= " hours ago"; |
609 | } elsif ($age > 60*2) { |
610 | $age_str = int $age/60; |
611 | $age_str .= " min ago"; |
612 | } elsif ($age > 2) { |
613 | $age_str = int $age; |
614 | $age_str .= " sec ago"; |
615 | } else { |
616 | $age_str .= " right now"; |
617 | } |
618 | return $age_str; |
7a88ffa4 |
619 | } |
620 | |
89de6a33 |
621 | =head1 AUTHOR |
622 | |
f71a83ab |
623 | Dan Brook |
89de6a33 |
624 | |
625 | =head1 LICENSE |
626 | |
627 | This library is free software. You can redistribute it and/or modify |
628 | it under the same terms as Perl itself. |
629 | |
630 | =cut |
631 | |
42fe5d11 |
632 | __PACKAGE__->meta->make_immutable; |