Message/Field/Date.pm

filter: Statementstmt 71.1% 37 / 52 Branchbran 35.0% 7 / 20 Conditioncond 62.5% 5 / 8 MC/DCmcdc 50.0% 2 / 4 Subroutinesub 70.0% 7 / 10 Podpod 100% 5 / 5 totaltotal 63.6% 63 / 99 CC 15 SCAR 25.4
CC
15
Cov
61%
time
30.0
parse
13.1
produceBody
2.0
CRAP 12.7
« Message/Head/FieldGroup.pm ↑ Summary Box/FastScalar.pm »
1 # This code is part of Perl distribution Mail-Message version 4.05.
2 # The POD got stripped from this file by OODoc version 3.06.
3 # For contributors see file ChangeLog.
4  
5 # This software is copyright (c) 2001-2026 by Mark Overmeer.
6  
7 # This is free software; you can redistribute it and/or modify it under
8 # the same terms as the Perl 5 programming language system itself.
9 # SPDX-License-Identifier: Artistic-1.0-Perl OR GPL-1.0-or-later
10  
11  
12 package Mail::Message::Field::Date;{
13 28 our $VERSION = '4.05';
14 }
15  
16 28 ▶use parent 'Mail::Message::Field::Structured';
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 28 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 28 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 28 ▶use Log::Report 'mail-message', import => [ qw/__x error/ ];
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 28 ▶use POSIX qw/mktime tzset/;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 #--------------------
26  
27 28 my $dayname = qr/Mon|Tue|Wed|Thu|Fri|Sat|Sun/;
28 28 my @months = qw/Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec/;
29 28 my %monthnr; { my $i; $monthnr{$_} = ++$i for @months }
30 28 my %tz = qw/
31 EDT -0400 EST -0500 CDT -0500 CST -0600
32 MDT -0600 MST -0700 PDT -0700 PST -0800
33 UT +0000 GMT +0000/;
34  
35 sub parse($)
36 5 ▶{ my ($self, $string) = @_;
Subroutine parse: called CC=11 SCAR=25.7
Pod documented
37  
38 5 ▶ my ($dn, $d, $mon, $y, $h, $min, $s, $z) = $string =~ m/
Branch: 1 branch
BranchTrueFalseTotal
() = $string =~ / ^ \s* (?: ($dayname) \s* \, \s* )? # dayname (optional) ( 0?[1-9] | [12][0-9] | 3[01] ) \s+ # day ( [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 (optional) ( [+-][0-9]{4} | [A-Z]+ )? # zone # optionally followed by trash /x or return undef 5 0 5
39 ^ \s*
40 (?: ($dayname) \s* \, \s* )? # dayname (optional)
41 ( 0?[1-9] | [12][0-9] | 3[01] ) \s+ # day
42 ( [A-Z][a-z][a-z]|[0-9][0-9] ) \s+ # month
43 ( (?: 19 | 20 | ) [0-9][0-9] ) \s+ # year
44 ( [0-1]?[0-9] | 2[0-3] ) \s* # hour
45 [:.] ( [0-5][0-9] ) \s* # minute
46 (?: [:.] ( [0-5][0-9] ) )? \s* # second (optional)
47 ( [+-][0-9]{4} | [A-Z]+ )? # zone
48 # optionally followed by trash
49 /x or return undef;
50  
51 5 ▶ $dn //= '';
Condition100%2/2
$dn //= ""
l!l
41
MC/DC100%1/1
$dn //= ""
$dn
Truth table100%2/2
A
A= $dn
Aresult
11
00
52 5 $dn =~ s/\s+//g;
53 5 ▶ $mon = $months[$mon-1] if $mon =~ /[0-9]+/; # Broken mail clients
Branch: 1 branch
BranchTrueFalseTotal
if $mon =~ /[0-9]+/ 0 5 5
54  
55 5 ▶ $y += 2000 if $y < 50;
Branch: 1 branch
BranchTrueFalseTotal
if $y < 50 0 5 5
56 5 ▶ $y += 1900 if $y < 100;
Branch: 1 branch
BranchTrueFalseTotal
if $y < 100 0 5 5
57  
58 5 ▶ $z ||= '-0000';
Condition50%1/2
$z ||= "-0000"
l!l
50
MC/DC0%0/1
$z ||= "-0000"
$z
Truth table50%1/2
A
A= $z
Aresult
11
00
59 5 ▶ $z = $tz{$z} || '-0000' if $z =~ m/[A-Z]/;
Branch: 1 branch
BranchTrueFalseTotal
if $z =~ /[A-Z]/ 0 5 5
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
60  
61 5 ▶ $self->{MMFD_date} = sprintf "%s%02d %s %04d %02d:%02d:%02d %s",
Branch: 1 branch
BranchTrueFalseTotal
length $dn ? : 4 1 5
Condition100%2/2
$s // 0
l!l
41
MC/DC100%1/1
$s // 0
$s
Truth table100%2/2
A
A= $s
Aresult
11
00
62 (length $dn ? "$dn, " : ''), $d, $mon, $y, $h, $min, $s // 0, $z;
63  
64 5 $self;
65 }
66  
67 0 ▶sub produceBody() { $_[0]->{MMFD_date} }
Subroutine produceBody: not called CC=1 SCAR=6.9
Pod documented
68  
69 #--------------------
70  
71 sub addAttribute($;@)
72 0 ▶{ my $self = shift;
Subroutine addAttribute: not called CC=1 SCAR=6.9
Pod documented
73 0 error __x"no attributes for date fields.";
74 }
75  
76  
77 5 ▶sub date() { $_[0]->{MMFD_date} }
Subroutine date: called CC=1 SCAR=0.0
Pod documented
78  
79  
80 sub time()
81 0 ▶{ my $date = shift->date or return;
Subroutine time: not called CC=5 SCAR=34.0
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
my $date = (shift())->date or return 0 0 0
82 0 my ($d, $mon, $y, $h, $min, $s, $z) = $date =~ m/
83 ^ (?:\w\w\w\,\s+)? (\d\d)\s+(\w+)\s+(\d\d\d\d) \s+ (\d\d)\:(\d\d)\:(\d\d) \s+ ([+-]\d\d\d\d)? \s* $
84 /x;
85  
86 0 my $oldtz = $ENV{TZ};
87 0 $ENV{TZ} = 'UTC';
88 0 tzset;
89 0 my $timestamp = mktime $s, $min, $h, $d, $monthnr{$mon}-1, $y-1900;
90 0 ▶ if(defined $oldtz) { $ENV{TZ} = $oldtz } else { delete $ENV{TZ} }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $oldtz) { } 0 0 0
91 0 tzset;
92  
93 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
94 if $z =~ m/^([+-])(\d\d)(\d\d)$/;
95 0 $timestamp;
96 }
97  
98 #--------------------
99  
100 28 1;
« Message/Head/FieldGroup.pm ↑ Summary Box/FastScalar.pm »