| 1 | package Dancer::Plugin::Formatter; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 3 | our @ISA = qw(); | |||||||||||||||||||
| 4 | 3 | our $VERSION = '0.04'; | |||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | 3 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 3 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | 3 | ▶ | use Dancer ':syntax'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 3 | ▶ | use Dancer::Plugin; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | 3 | ▶ | use Date::Parse; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 13 | 3 | ▶ | use POSIX; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | # see man 3 strftime | ||||||||||||||||||||
| 16 | 3 | our $default_date_format = '%x'; # The preferred date representation for the current locale without the time. | |||||||||||||||||||
| 17 | 3 | our $default_time_format = '%c'; # The preferred date and time representation for the current locale. | |||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | register 'format_date' => sub { | ||||||||||||||||||||
| 20 | 2 | ▶ | my $format = shift // $default_date_format; | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
Condition33%1/3
shift() // $Dancer::Plugin::Formatter::default_date_format
MC/DC0%0/2
shift() // $Dancer::Plugin::Formatter::default_date_format
shift()
$Dancer::Plugin::Formatter::default_date_format
Truth table33%1/3
A // B
A= shift()B= $Dancer::Plugin::Formatter::default_date_format
| |||||||||||||||||||||
| 21 | return sub { | ||||||||||||||||||||
| 22 | 3 | ▶ | my $date = shift; | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||
| 23 | 3 | ▶ | return undef unless defined $date; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 24 | 2 | ▶ | return '' if $date eq ''; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | 1 | ▶ | my @parts = map { $_ //= 0 } strptime $date; | ||||||||||||||||||
|
Condition100%2/2
$_ //= 0
MC/DC100%1/1
$_ //= 0
$_
Truth table100%2/2
A
A= $_
| |||||||||||||||||||||
| 27 | # undefined parts set to 0 to prevent error | ||||||||||||||||||||
| 28 | # Use of uninitialized value in subroutine entry | ||||||||||||||||||||
| 29 | 1 | return POSIX::strftime $format, @parts; | |||||||||||||||||||
| 30 | } | ||||||||||||||||||||
| 31 | 2 | }; | |||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | register 'format_time' => sub { | ||||||||||||||||||||
| 34 | 0 | ▶ | my $format = shift // $default_time_format; | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=16.8
Condition0%0/3
shift() // $Dancer::Plugin::Formatter::default_time_format
MC/DC0%0/2
shift() // $Dancer::Plugin::Formatter::default_time_format
shift()
$Dancer::Plugin::Formatter::default_time_format
Truth table0%0/3
A // B
A= shift()B= $Dancer::Plugin::Formatter::default_time_format
| |||||||||||||||||||||
| 35 | return sub { | ||||||||||||||||||||
| 36 | 0 | ▶ | my $time = shift; | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||||||||
| 37 | 0 | ▶ | return undef unless defined $time; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 38 | 0 | ▶ | return '' if $time eq ''; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | 0 | ▶ | my @parts = map { $_ //= 0 } strptime $time; | ||||||||||||||||||
|
Condition0%0/2
$_ //= 0
MC/DC0%0/1
$_ //= 0
$_
Truth table0%0/2
A
A= $_
| |||||||||||||||||||||
| 41 | # undefined parts set to 0 to prevent error | ||||||||||||||||||||
| 42 | # Use of uninitialized value in subroutine entry | ||||||||||||||||||||
| 43 | 0 | return POSIX::strftime $format, @parts; | |||||||||||||||||||
| 44 | } | ||||||||||||||||||||
| 45 | 0 | }; | |||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | register 'set_default_date_format' => sub { | ||||||||||||||||||||
| 48 | 0 | ▶ | $default_date_format = shift; | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 49 | 0 | return; | |||||||||||||||||||
| 50 | 3 | }; | |||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | register 'set_default_time_format' => sub { | ||||||||||||||||||||
| 53 | 0 | ▶ | $default_time_format = shift; | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 54 | 0 | return; | |||||||||||||||||||
| 55 | 3 | }; | |||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | register 'format' => sub { | ||||||||||||||||||||
| 59 | 0 | ▶ | my $format = shift; | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 60 | return sub { | ||||||||||||||||||||
| 61 | 0 | ▶ | return sprintf $format, @_; | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 62 | 0 | }; | |||||||||||||||||||
| 63 | 3 | }; | |||||||||||||||||||
| 64 | |||||||||||||||||||||
| 65 | 3 | register_plugin; | |||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | 3 | 1; | |||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | __END__ | ||||||||||||||||||||