blib/lib/Email/Simple/Test/TraceHeaders.pm

filter: Statementstmt 100% 53 / 53 Branchbran 91.6% 11 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 13 / 13 Podpod 100% 2 / 2 totaltotal 98.7% 79 / 80 SCAR 22.0
CC
9
Cov
98%
trace_headers
9.0
BEGIN
1.0
BEGIN
1.0
CRAP 9.0
↑ Summary
1 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 package Email::Simple::Test::TraceHeaders;
4 {
5 2 $Email::Simple::Test::TraceHeaders::VERSION = '0.091702';
6 }
7 # ABSTRACT: generate sample trace headers for testing
8  
9 2 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use Email::Date::Format ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use Email::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use Email::Simple::Creator;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use Sub::Exporter::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 2 use Sub::Exporter -setup => {
16 exports => [ prev => \'_build_prev' ],
17 groups => [ helpers => [ qw(prev) ] ],
18 2 ▶};
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 # For now, we'll only generate one style of Received header: postfix
21 # It's what I encounter the most, and it's simple and straightforward.
22 # In the future, we'll be flexible, maybe. -- rjbs, 2009-06-19
23 2 my %POSTFIX_FMT = (
24 for => q{from %s (%s [%s]) by %s (Postfix) with ESMTP id %s for <%s>; %s},
25 nofor => q{from %s (%s [%s]) by %s (Postfix) with ESMTP id %s%s; %s},
26 );
27  
28  
29 sub trace_headers {
30 1 ▶ my ($self, $arg) = @_;
Subroutine trace_headers: called CC=9 SCAR=22.0
Pod documented
31  
32 1 ▶ Carp::confess("no hops provided") unless $arg->{hops};
Branch: 1 branch
BranchTrueFalseTotal
unless $arg->{"hops"} 0 1 1
33  
34 1 my @received;
35 my %last;
36 1 for my $hop (@{ $arg->{hops} }) {
37 3 my %hop = (%$hop);
38  
39 3 for my $key (keys %hop) {
40 20 ▶ if (ref $hop->{$key} eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $hop->{$key} eq "CODE") 3 17 20
41 3 $hop{ $key } = $hop{$key}->(\%last);
42 }
43 }
44  
45 my $env_to = ref $hop{env_to} ? $hop{env_to}
46 3 ▶ : $hop{env_to} ? [ $hop{env_to} ]
Branch: 2 branches
BranchTrueFalseTotal
ref $hop{'env_to'} ? : 1 2 3
$hop{'env_to'} ? : 1 1 2
47 : [ ];
48  
49 3 ▶ my $fmt = @$env_to == 1 ? $POSTFIX_FMT{for} : $POSTFIX_FMT{nofor};
Branch: 1 branch
BranchTrueFalseTotal
@$env_to == 1 ? : 2 1 3
50  
51 push @received, sprintf $fmt,
52 $hop{from_helo},
53 $hop{from_rdns},
54 $hop{from_ip},
55 $hop{by_name}, # by_ip someday?
56 $hop{queue_id},
57 @$env_to == 1 ? $env_to->[0] : '',
58 3 ▶ (Email::Date::Format::email_gmdate($hop{time}) . ' (GMT)');
Branch: 1 branch
BranchTrueFalseTotal
@$env_to == 1 ? : 2 1 3
59  
60 3 %last = %hop;
61 }
62  
63 1 return [ reverse @received ];
64 }
65  
66  
67 sub create_email {
68 1 ▶ my ($self, $arg) = @_;
Subroutine create_email: called CC=1 SCAR=0.0
Pod documented
69  
70 my $email = Email::Simple->create(
71 header => [
72 1 (map {; Received => $_ } @{ $self->trace_headers($arg) }),
73  
74 From => '"X. Ample" <xa@example.com>',
75 To => '"E. Xampe" <ex@example.org>',
76 ],
77 body => "This is a test message.\n",
78 );
79  
80 1 return $email;
81 }
82  
83  
84 sub _build_prev {
85 1 ▶ my ($self) = @_;
Subroutine _build_prev: called CC=1 SCAR=0.0
86  
87 sub {
88 3 ▶ my ($name) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
89  
90 sub {
91 3 ▶ my ($last) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
92 3 $last->{ $name };
93 }
94 3 }
95 1 }
96  
97 2 1;
98  
99 __END__
↑ Summary