Message/Field/Date.pm

filter: Statementstmt 46.1% 24 / 52 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 50.0% 5 / 10 Podpod 100% 5 / 5 totaltotal 36.5% 34 / 93 SCAR 42.1
CC
13
Cov
32%
parse
110.0
time
20.0
produceBody
2.0
CRAP 67.1
« Message/Field/Full.pm ↑ Summary Message/Field/Addresses.pm »
1 # Copyrights 2001-2023 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 distribution Mail-Message. Meta-POD processed with
6 # OODoc into POD and HTML manual-pages. See README.md
7 # Copyright Mark Overmeer. Licensed under the same terms as Perl itself.
8  
9 package Mail::Message::Field::Date;
10 24 ▶use vars '$VERSION';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 24 $VERSION = '3.013';
12  
13 24 ▶use base 'Mail::Message::Field::Structured';
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 24 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 24 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 24 ▶use POSIX qw/mktime tzset/;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20  
21 24 my $dayname = qr/Mon|Tue|Wed|Thu|Fri|Sat|Sun/;
22 24 my @months = qw/Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec/;
23 24 my %monthnr; { my $i; $monthnr{$_} = ++$i for @months }
24 24 my %tz = qw/EDT -0400 EST -0500 CDT -0500 CST -0600
25 MDT -0600 MST -0700 PDT -0700 PST -0800
26 UT +0000 GMT +0000/;
27  
28 sub parse($)
29 0 ▶{ my ($self, $string) = @_;
Subroutine parse: not called CC=10 SCAR=47.0
Pod documented
30  
31 0 ▶ my ($dn, $d, $mon, $y, $h, $min, $s, $z) = $string =~
Branch: 1 branch
BranchTrueFalseTotal
() = $string =~ / ^ \s* (?: ($dayname) \s* \, \s* )? ( 0?[1-9] | [12][0-9] | 3[01] ) \s* # day \s+ ( [A-Z][a-z][a-z]|[0-9][0-9] ) \s+ # month ( (?: 19 | 20 | ) [0-9][0-9] ) \s+ # year ( [0-1]?[0-9] | 2[0-3] ) \s* # hour [:.] ( [0-5][0-9] ) \s* # minute (?: [:.] ( [0-5][0-9] ) )? \s+ # second ( [+-][0-9]{4} | [A-Z]+ )? # zone \s* /x or return undef 0 0 0
32 m/ ^ \s*
33 (?: ($dayname) \s* \, \s* )?
34 ( 0?[1-9] | [12][0-9] | 3[01] ) \s* # day
35 \s+ ( [A-Z][a-z][a-z]|[0-9][0-9] ) \s+ # month
36 ( (?: 19 | 20 | ) [0-9][0-9] ) \s+ # year
37 ( [0-1]?[0-9] | 2[0-3] ) \s* # hour
38 [:.] ( [0-5][0-9] ) \s* # minute
39 (?: [:.] ( [0-5][0-9] ) )? \s+ # second
40 ( [+-][0-9]{4} | [A-Z]+ )? # zone
41 \s* /x
42 or return undef;
43  
44 0 ▶ defined $dn or $dn = '';
Branch: 1 branch
BranchTrueFalseTotal
defined $dn or $dn = "" 0 0 0
45 0 $dn =~ s/\s+//g;
46 0 ▶ $mon = $months[$mon-1] if $mon =~ /[0-9]+/; # Broken mail clients
Branch: 1 branch
BranchTrueFalseTotal
if $mon =~ /[0-9]+/ 0 0 0
47  
48 0 ▶ $y += 2000 if $y < 50;
Branch: 1 branch
BranchTrueFalseTotal
if $y < 50 0 0 0
49 0 ▶ $y += 1900 if $y < 100;
Branch: 1 branch
BranchTrueFalseTotal
if $y < 100 0 0 0
50  
51 0 ▶ $z ||= '-0000';
Condition0%0/2
$z ||= "-0000"
l!l
00
MC/DC0%0/1
$z ||= "-0000"
$z
Truth table0%0/2
A
A= $z
Aresult
11
00
52 0 ▶ $z = $tz{$z} || '-0000'
Branch: 1 branch
BranchTrueFalseTotal
if $z =~ /[A-Z]/ 0 0 0
Condition0%0/2
$tz{$z} || '-0000'
l!l
00
MC/DC0%0/1
$tz{$z} || '-0000'
$tz{$z}
Truth table0%0/2
A
A= $tz{$z}
Aresult
11
00
53 if $z =~ m/[A-Z]/;
54  
55 0 ▶ $self->{MMFD_date} = sprintf "%s%s%02d %s %04d %02d:%02d:%02d %s"
Branch: 1 branch
BranchTrueFalseTotal
length $dn ? : 0 0 0
56 , $dn, (length $dn ? ', ' : ''), $d, $mon, $y, $h, $min, $s, $z;
57  
58 0 $self;
59 }
60  
61 0 ▶sub produceBody() { shift->{MMFD_date} }
Subroutine produceBody: not called CC=1 SCAR=6.9
Pod documented
62 0 ▶sub date() { shift->{MMFD_date} }
Subroutine date: not called CC=1 SCAR=6.9
Pod documented
63  
64 #------------------------------------------
65  
66  
67 sub addAttribute($;@)
68 0 ▶{ my $self = shift;
Subroutine addAttribute: not called CC=1 SCAR=6.9
Pod documented
69 0 $self->log(ERROR => 'No attributes for date fields.');
70 0 $self;
71 }
72  
73  
74 sub time()
75 0 ▶{ my $date = shift->{MMFD_date};
Subroutine time: not called CC=4 SCAR=30.0
Pod documented
76 0 my ($d, $mon, $y, $h, $min, $s, $z)
77 = $date =~ m/^ (?:\w\w\w\,\s+)? (\d\d)\s+(\w+)\s+(\d\d\d\d)
78 \s+ (\d\d)\:(\d\d)\:(\d\d) \s+ ([+-]\d\d\d\d)? \s*$ /x;
79  
80 0 my $oldtz = $ENV{TZ};
81 0 $ENV{TZ} = 'UTC';
82 0 tzset;
83 0 my $timestamp = mktime $s, $min, $h, $d, $monthnr{$mon}-1, $y-1900;
84 0 ▶ if(defined $oldtz) { $ENV{TZ} = $oldtz } else { delete $ENV{TZ} }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $oldtz) { } 0 0 0
85 0 tzset;
86  
87 0 ▶ $timestamp += ($1 eq '-' ? 1 : -1) * ($2*3600 + $3*60)
Branch: 2 branches
BranchTrueFalseTotal
if $z =~ /^([+-])(\d\d)(\d\d)$/ 0 0 0
$1 eq '-' ? : 0 0 0
88 if $z =~ m/^([+-])(\d\d)(\d\d)$/;
89 0 $timestamp;
90 }
91  
92 #------------------------------------------
93  
94  
95 24 1;
« Message/Field/Full.pm ↑ Summary Message/Field/Addresses.pm »