line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::TimeAgo; |
2
|
4
|
|
|
4
|
|
352860
|
use Mojo::Base 'Mojolicious::Plugin'; |
|
4
|
|
|
|
|
13002
|
|
|
4
|
|
|
|
|
40
|
|
3
|
|
|
|
|
|
|
our $VERSION = 0.03; |
4
|
|
|
|
|
|
|
|
5
|
4
|
|
|
4
|
|
12209
|
use DateTimeX::Format::Ago; |
|
4
|
|
|
|
|
5738
|
|
|
4
|
|
|
|
|
1360
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
sub register { |
8
|
3
|
|
|
3
|
1
|
192
|
my ( $self, $app, $attrs ) = @_; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# attributes |
11
|
3
|
|
100
|
|
|
24
|
my $default_lang = $attrs->{default} || 'en'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
$app->hook( |
15
|
|
|
|
|
|
|
$app->hook( |
16
|
|
|
|
|
|
|
before_dispatch => sub { |
17
|
6
|
|
|
6
|
|
279375
|
my $self = shift; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# setting default lang |
20
|
6
|
50
|
|
|
|
50
|
$self->stash( lang_default => $default_lang ) |
21
|
|
|
|
|
|
|
unless $self->stash('lang_default'); |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
) |
24
|
3
|
|
|
|
|
60
|
); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# add "time_ago" helper |
27
|
|
|
|
|
|
|
$app->helper( |
28
|
|
|
|
|
|
|
time_ago => sub { |
29
|
2
|
|
|
2
|
|
9305
|
my ( $self, $dt ) = @_; |
30
|
|
|
|
|
|
|
|
31
|
2
|
|
|
|
|
10
|
my $ago = |
32
|
|
|
|
|
|
|
DateTimeX::Format::Ago->new( |
33
|
|
|
|
|
|
|
language => $self->stash('lang_default') ); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
#return DateTimeX::Format::Ago->format_datetime($dt) |
36
|
2
|
100
|
66
|
|
|
75
|
return $ago->format_datetime($dt) if $dt && $dt->isa('DateTime'); |
37
|
|
|
|
|
|
|
} |
38
|
3
|
|
|
|
|
314
|
); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
1; |
42
|
|
|
|
|
|
|
__END__ |