| 1 | package Mojolicious::Plugin::TimeAgo; | ||||||||||||||||||||||||||||
| 2 | 4 | ▶ | use Mojo::Base 'Mojolicious::Plugin'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | # imports | ||||||||||||||||||||||||||||
| 5 | 4 | ▶ | use DateTimeX::Format::Ago; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | # version | ||||||||||||||||||||||||||||
| 8 | 4 | our $VERSION = 0.06; | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 3 | ▶ | sub register { | ||||||||||||||||||||||||||
|
Subroutine
register: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||
| 11 | 3 | my ($self, $app, $attrs) = @_; | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | # attributes | ||||||||||||||||||||||||||||
| 14 | 3 | ▶ | my $default_lang = $attrs->{default} || 'en'; | ||||||||||||||||||||||||||
|
Condition100%2/2
$attrs->{'default'} || 'en'
MC/DC100%1/1
$attrs->{'default'} || 'en'
$attrs->{'default'}
Truth table100%2/2
A
A= $attrs->{'default'}
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | $app->hook( | ||||||||||||||||||||||||||||
| 17 | 6 | ▶ | before_dispatch => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
| |||||||||||||||||||||||||||||
| 18 | 6 | ▶ | $_[0]->stash(lang_default => $default_lang) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 19 | unless $_[0]->stash('lang_default'); | ||||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||
| 21 | 3 | ); | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | # add "time_ago" helper | ||||||||||||||||||||||||||||
| 24 | $app->helper( | ||||||||||||||||||||||||||||
| 25 | 2 | ▶ | time_ago => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 26 | 2 | my ($c, $dt) = @_; | |||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 2 | my $ago = DateTimeX::Format::Ago->new( | |||||||||||||||||||||||||||
| 29 | language => $c->stash('lang_default') | ||||||||||||||||||||||||||||
| 30 | ); | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 2 | ▶ | return $ago->format_datetime($dt) if $dt && $dt->isa('DateTime'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$dt and $dt->isa("DateTime")
MC/DC50%1/2
$dt and $dt->isa("DateTime")
$dt
$dt->isa("DateTime")
Truth table66%2/3
A and B
A= $dtB= $dt->isa("DateTime")
| |||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | 3 | ); | |||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 4 | 1; | |||||||||||||||||||||||||||
| 38 | __END__ | ||||||||||||||||||||||||||||