Mail/Field/Date.pm untested

filter: Statementstmt 0.0% 0 / 37 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 67 CC 4 SCAR 16.4
CC
4
Cov
0%
set
12.0
time
6.0
parse
2.0
CRAP 5.2
1 # Copyrights 1995-2024 by [Mark Overmeer <markov@cpan.org>].
2 # For other contributors see ChangeLog.
3 # See the manual pages for details on the licensing terms.
4 # Pod stripped from pm file by OODoc 2.03.
5 # This code is part of the bundle MailTools. Meta-POD processed with
6 # OODoc into POD and HTML manual-pages. See README.md for Copyright.
7 # Licensed under the same terms as Perl itself.
8  
9 package Mail::Field::Date;{
10 our $VERSION = '2.22';
11 }
12  
13 use base 'Mail::Field';
14  
15 use strict;
16  
17 use Date::Format qw(time2str);
18 use Date::Parse qw(str2time);
19  
20 (bless [])->register('Date');
21  
22  
23 sub set()
24 { my $self = shift;
25 my $arg = @_ == 1 ? shift : { @_ };
26  
27 foreach my $s (qw(Time TimeStr))
28 { if(exists $arg->{$s})
29 { $self->{$s} = $arg->{$s} }
30 else { delete $self->{$s} }
31 }
32  
33 $self;
34 }
35  
36 sub parse($)
37 { my $self = shift;
38 delete $self->{Time};
39 $self->{TimeStr} = shift;
40 $self;
41 }
42  
43  
44 sub time(;$)
45 { my $self = shift;
46  
47 if(@_)
48 { delete $self->{TimeStr};
49 return $self->{Time} = shift;
50 }
51  
52 $self->{Time} ||= str2time $self->{TimeStr};
53 }
54  
55 sub stringify
56 { my $self = shift;
57 $self->{TimeStr} ||= time2str("%a, %e %b %Y %T %z", $self->time);
58 }
59  
60 sub reformat
61 { my $self = shift;
62 $self->time($self->time);
63 $self->stringify;
64 }
65  
66 1;