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