Quantity/Time/DurationDays.pm untested

filter: Statementstmt 0.0% 0 / 34 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 7 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 63 CC 3 SCAR 15.0
CC
3
Cov
0%
readable
12.0
scale
2.0
type
2.0
CRAP 4.5
1 package Data::Quantity::Time::DurationDays;
2  
3 require 5;
4 use strict;
5 use Carp;
6  
7 use vars qw( $VERSION );
8 $VERSION = 0.001;
9  
10 use Data::Quantity::Number::Integer '-isasubclass';
11  
12 # undef = Data::Quantity::Time::DurationDays->scale();
13 sub scale {
14 return 'Days';
15 }
16  
17 sub type {
18 return 'temporal', 'duration';
19 }
20  
21 use vars qw( $default_readable_format );
22 $default_readable_format ||= 'D days';
23  
24 # $value = Data::Quantity::Time::DurationDays->readable_value($number)
25 # $value = Data::Quantity::Time::DurationDays->readable_value($number, $style)
26 sub readable_value {
27 my $class_or_item = shift;
28 my $value = shift;
29 $class_or_item->new($value)->readable(@_);
30 }
31  
32 # $string = $quantity->readable( @_ );
33 sub readable {
34 my $duration_q = shift;
35 my $style = shift;
36 $style ||= $default_readable_format;
37 my $days = $duration_q->value or return;
38
39 if ( $style eq 'Y yrs' ) {
40 my $years = int( $days / 365 );
41 return "$years yrs";
42 } elsif ( $style eq 'D days' ) {
43 return "$days days";
44 } else {
45 croak "Unkown duration readable format: '$style'";
46 }
47 }
48  
49 1;