line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Email::Simple::Markdown; |
2
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:YANICK'; |
3
|
|
|
|
|
|
|
# ABSTRACT: simple email creation with auto text and html multipart body |
4
|
|
|
|
|
|
|
$Email::Simple::Markdown::VERSION = '0.7.1'; |
5
|
5
|
|
|
5
|
|
70663
|
use strict; |
|
5
|
|
|
|
|
6
|
|
|
5
|
|
|
|
|
124
|
|
6
|
5
|
|
|
5
|
|
74
|
use warnings; |
|
5
|
|
|
|
|
5
|
|
|
5
|
|
|
|
|
114
|
|
7
|
|
|
|
|
|
|
|
8
|
5
|
|
|
5
|
|
19
|
use Carp; |
|
5
|
|
|
|
|
8
|
|
|
5
|
|
|
|
|
355
|
|
9
|
|
|
|
|
|
|
|
10
|
5
|
|
|
5
|
|
2034
|
use Email::Abstract; |
|
5
|
|
|
|
|
112796
|
|
|
5
|
|
|
|
|
165
|
|
11
|
5
|
|
|
5
|
|
3121
|
use Email::MIME; |
|
5
|
|
|
|
|
202140
|
|
|
5
|
|
|
|
|
134
|
|
12
|
5
|
|
|
5
|
|
32
|
use Email::Simple; |
|
5
|
|
|
|
|
6
|
|
|
5
|
|
|
|
|
114
|
|
13
|
|
|
|
|
|
|
|
14
|
5
|
|
|
5
|
|
17
|
use List::Util qw/ first pairmap /; |
|
5
|
|
|
|
|
5
|
|
|
5
|
|
|
|
|
435
|
|
15
|
5
|
|
|
5
|
|
21
|
use Module::Runtime qw/ use_module /; |
|
5
|
|
|
|
|
5
|
|
|
5
|
|
|
|
|
42
|
|
16
|
|
|
|
|
|
|
|
17
|
5
|
|
|
5
|
|
2640
|
use Moo; |
|
5
|
|
|
|
|
35186
|
|
|
5
|
|
|
|
|
20
|
|
18
|
|
|
|
|
|
|
extends 'Email::Simple'; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub BUILDARGS { |
21
|
8
|
|
|
8
|
0
|
7099
|
return {}; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
around create => sub { |
25
|
|
|
|
|
|
|
my ( $orig, $self, %arg ) = @_; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
my @local_args = qw/ css markdown_engine pre_markdown_filter charset /; |
28
|
|
|
|
|
|
|
my %md_arg; |
29
|
|
|
|
|
|
|
@md_arg{@local_args} = delete @arg{@local_args}; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
my $email = $orig->( $self, %arg ); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
$email->markdown_engine_set( |
34
|
|
|
|
|
|
|
$md_arg{markdown_engine}||'auto' |
35
|
|
|
|
|
|
|
); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
$email->charset_set( $md_arg{charset} ) if $md_arg{charset}; |
38
|
|
|
|
|
|
|
$email->css_set($md_arg{css}) if $md_arg{css}; |
39
|
|
|
|
|
|
|
$email->pre_markdown_filter_set($md_arg{pre_markdown_filter}) |
40
|
|
|
|
|
|
|
if $md_arg{pre_markdown_filter}; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
return $email; |
43
|
|
|
|
|
|
|
}; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
our @SUPPORTED_ENGINES = qw/ Text::MultiMarkdown Text::Markdown /; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
has markdown_engine => ( |
48
|
|
|
|
|
|
|
is => 'rw', |
49
|
|
|
|
|
|
|
lazy => 1, |
50
|
|
|
|
|
|
|
default => sub { $_[0]->find_markdown_engine }, |
51
|
|
|
|
|
|
|
clearer => 1, |
52
|
|
|
|
|
|
|
coerce => sub { |
53
|
|
|
|
|
|
|
my( $value ) = @_; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
return $value eq 'auto' |
56
|
|
|
|
|
|
|
? __PACKAGE__->find_markdown_engine |
57
|
|
|
|
|
|
|
: $value; |
58
|
|
|
|
|
|
|
}, |
59
|
|
|
|
|
|
|
trigger => sub{ |
60
|
|
|
|
|
|
|
my( $self, $engine ) = @_; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
die "engine '$engine' not implementing a 'markdown' method\n" |
63
|
|
|
|
|
|
|
unless use_module($engine)->can('markdown'); |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
$self->clear_markdown_object; |
66
|
|
|
|
|
|
|
}, |
67
|
|
|
|
|
|
|
writer => 'markdown_engine_set', |
68
|
|
|
|
|
|
|
); |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
has markdown_object => ( |
71
|
|
|
|
|
|
|
is => 'rw', |
72
|
|
|
|
|
|
|
lazy => 1, |
73
|
|
|
|
|
|
|
clearer => 1, |
74
|
|
|
|
|
|
|
default => sub { $_[0]->{markdown_engine}->new }, |
75
|
|
|
|
|
|
|
handles => { |
76
|
|
|
|
|
|
|
_markdown => 'markdown', |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
); |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub find_markdown_engine { |
81
|
10
|
|
|
10
|
|
14
|
first { eval { use_module($_) } } @SUPPORTED_ENGINES |
|
10
|
|
|
|
|
36
|
|
82
|
10
|
50
|
|
10
|
0
|
108
|
or die "No supported markdown engine found" |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
has markdown_css => ( |
86
|
|
|
|
|
|
|
is => 'rw', |
87
|
|
|
|
|
|
|
reader => 'css', |
88
|
|
|
|
|
|
|
writer => 'css_set', |
89
|
|
|
|
|
|
|
coerce => sub { |
90
|
|
|
|
|
|
|
my $css = shift; |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
if ( ref $css eq 'ARRAY' ) { |
93
|
|
|
|
|
|
|
my @css = @$css; |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
croak "number of argument is not even" if @css % 2; |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
$css = join "\n", pairmap { "$a { $b }" } @css; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
$css; |
101
|
|
|
|
|
|
|
}, |
102
|
|
|
|
|
|
|
); |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
has markdown_filter => ( |
105
|
|
|
|
|
|
|
is => 'rw', |
106
|
|
|
|
|
|
|
writer => 'pre_markdown_filter_set', |
107
|
|
|
|
|
|
|
); |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
has markdown_charset => ( |
110
|
|
|
|
|
|
|
is => 'rw', |
111
|
|
|
|
|
|
|
writer => 'charset_set', |
112
|
|
|
|
|
|
|
); |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub with_markdown { |
115
|
11
|
|
|
11
|
1
|
1116
|
my $self = shift; |
116
|
|
|
|
|
|
|
|
117
|
11
|
|
|
|
|
56
|
my $body = $self->body; |
118
|
|
|
|
|
|
|
|
119
|
11
|
|
|
|
|
85
|
my $mail = Email::Abstract->new($self->SUPER::as_string) |
120
|
|
|
|
|
|
|
->cast('Email::MIME'); |
121
|
|
|
|
|
|
|
|
122
|
11
|
|
|
|
|
5406
|
$mail->content_type_set('multipart/alternative'); |
123
|
|
|
|
|
|
|
|
124
|
11
|
|
|
|
|
1939
|
$mail->parts_set([ |
125
|
|
|
|
|
|
|
Email::MIME->create( |
126
|
|
|
|
|
|
|
attributes => { |
127
|
|
|
|
|
|
|
content_type => 'text/plain', |
128
|
|
|
|
|
|
|
charset => $self->markdown_charset |
129
|
|
|
|
|
|
|
}, |
130
|
|
|
|
|
|
|
body => $body, |
131
|
|
|
|
|
|
|
), |
132
|
|
|
|
|
|
|
Email::MIME->create( |
133
|
|
|
|
|
|
|
attributes => { |
134
|
|
|
|
|
|
|
content_type => 'text/html', |
135
|
|
|
|
|
|
|
charset => $self->markdown_charset, |
136
|
|
|
|
|
|
|
encoding => 'quoted-printable', |
137
|
|
|
|
|
|
|
}, |
138
|
|
|
|
|
|
|
body => $self->markdown_part, |
139
|
|
|
|
|
|
|
) |
140
|
|
|
|
|
|
|
]); |
141
|
|
|
|
|
|
|
|
142
|
11
|
|
|
|
|
24978
|
return Email::Abstract->new($mail); |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
sub markdown_part { |
146
|
11
|
|
|
11
|
0
|
5909
|
my $self = shift; |
147
|
|
|
|
|
|
|
|
148
|
11
|
|
|
|
|
23
|
my $markdown = $self->body; |
149
|
|
|
|
|
|
|
|
150
|
11
|
100
|
|
|
|
77
|
if( my $filter = $self->markdown_filter ) { |
151
|
1
|
|
|
|
|
1
|
local $_ = $markdown; |
152
|
1
|
|
|
|
|
7
|
$filter->(); |
153
|
1
|
|
|
|
|
6
|
$markdown = $_; |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
|
156
|
11
|
|
|
|
|
132
|
$markdown = $self->_markdown($markdown); |
157
|
11
|
100
|
|
|
|
13657
|
$markdown = '' |
160
|
|
|
|
|
|
|
. $markdown |
161
|
|
|
|
|
|
|
if $self->css; |
162
|
|
|
|
|
|
|
|
163
|
11
|
|
|
|
|
39
|
return $markdown; |
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
|
166
|
6
|
|
|
6
|
1
|
936
|
sub as_string { $_[0]->with_markdown->as_string } |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
1; |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
__END__ |