| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::TimeAgo; |
|
2
|
4
|
|
|
4
|
|
89707
|
use Mojo::Base 'Mojolicious::Plugin'; |
|
|
4
|
|
|
|
|
6115
|
|
|
|
4
|
|
|
|
|
19
|
|
|
3
|
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
# imports |
|
5
|
4
|
|
|
4
|
|
2327
|
use DateTimeX::Format::Ago; |
|
|
4
|
|
|
|
|
2918
|
|
|
|
4
|
|
|
|
|
605
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
# version |
|
8
|
|
|
|
|
|
|
our $VERSION = 0.06; |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub register { |
|
11
|
3
|
|
|
3
|
1
|
95
|
my ($self, $app, $attrs) = @_; |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# attributes |
|
14
|
3
|
|
100
|
|
|
14
|
my $default_lang = $attrs->{default} || 'en'; |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
$app->hook( |
|
17
|
|
|
|
|
|
|
before_dispatch => sub { |
|
18
|
6
|
50
|
|
6
|
|
37363
|
$_[0]->stash(lang_default => $default_lang) |
|
19
|
|
|
|
|
|
|
unless $_[0]->stash('lang_default'); |
|
20
|
|
|
|
|
|
|
} |
|
21
|
3
|
|
|
|
|
23
|
); |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# add "time_ago" helper |
|
24
|
|
|
|
|
|
|
$app->helper( |
|
25
|
|
|
|
|
|
|
time_ago => sub { |
|
26
|
2
|
|
|
2
|
|
1854
|
my ($c, $dt) = @_; |
|
27
|
|
|
|
|
|
|
|
|
28
|
2
|
|
|
|
|
5
|
my $ago = DateTimeX::Format::Ago->new( |
|
29
|
|
|
|
|
|
|
language => $c->stash('lang_default') |
|
30
|
|
|
|
|
|
|
); |
|
31
|
|
|
|
|
|
|
|
|
32
|
2
|
100
|
66
|
|
|
33
|
return $ago->format_datetime($dt) if $dt && $dt->isa('DateTime'); |
|
33
|
|
|
|
|
|
|
} |
|
34
|
3
|
|
|
|
|
56
|
); |
|
35
|
|
|
|
|
|
|
} |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
1; |
|
38
|
|
|
|
|
|
|
__END__ |