lib/Mojolicious/Plugin/TimeAgo.pm

filter: Statementstmt 100% 16 / 16 Branchbran 75.0% 3 / 4 Conditioncond 80.0% 4 / 5 MC/DCmcdc 66.6% 2 / 3 Subroutinesub 100% 5 / 5 Podpod 100% 1 / 1 totaltotal 91.1% 31 / 34 CC 5 SCAR 7.7
CC
5
Cov
92%
__ANON__
3.0
__ANON__
2.1
register
2.0
CRAP 2.2
↑ Summary
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'
l!l
21
MC/DC100%1/1
$attrs->{'default'} || 'en'
$attrs->{'default'}
Truth table100%2/2
A
A= $attrs->{'default'}
Aresult
11
00
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
BranchTrueFalseTotal
unless $_[0]->stash("lang_default") 6 0 6
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
BranchTrueFalseTotal
if $dt and $dt->isa("DateTime") 1 1 2
Condition66%2/3
$dt and $dt->isa("DateTime")
!ll&&!rl&&r
101
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")
ABresult
0X0
100
111
33 }
34 3 );
35 }
36  
37 4 1;
38 __END__
↑ Summary