File Coverage

blib/lib/DateTimeX/Lite/Overload.pm
Criterion Covered Total %
statement 11 12 91.6
branch 6 8 75.0
condition 6 12 50.0
subroutine 5 5 100.0
pod n/a
total 28 37 75.6


line stmt bran cond sub pod time code
1             package DateTimeX::Lite;
2              
3             use overload (
4 9         78 fallback => 1,
5             '<=>' => '_compare_overload',
6             'cmp' => '_compare_overload',
7             '""' => '_stringify_overload',
8             'eq' => '_string_equals_overload',
9             'ne' => '_string_not_equals_overload',
10 9     9   56 );
  9         18  
11              
12             sub _stringify_overload {
13 51     51   770 my $self = shift;
14              
15 51 50       251 return $self->iso8601 unless $self->{formatter};
16 0         0 return $self->{formatter}->format_datetime($self);
17             }
18              
19             sub _compare_overload
20             {
21             # note: $_[1]->compare( $_[0] ) is an error when $_[1] is not a
22             # DateTime (such as the INFINITY value)
23 901 100   901   5120 return $_[2] ? - $_[0]->compare( $_[1] ) : $_[0]->compare( $_[1] );
24             }
25              
26             sub _string_equals_overload {
27 4 50   4   699 my ( $class, $dt1, $dt2 ) = ref $_[0] ? ( undef, @_ ) : @_;
28              
29             return unless(
30 4 100 33     120 blessed $dt1 && $dt1->can('utc_rd_values') &&
      66        
      66        
31             blessed $dt2 && $dt2->can('utc_rd_values')
32             );
33              
34 2   33     12 $class ||= ref $dt1;
35 2         8 return ! $class->compare( $dt1, $dt2 );
36             }
37              
38             sub _string_not_equals_overload {
39 2     2   9 return ! _string_equals_overload(@_);
40             }
41              
42              
43             1;