Markdown.pm

filter: Statementstmt 98.7% 81 / 82 Branchbran 85.0% 17 / 20 Conditioncond 100% 2 / 2 MC/DCmcdc 100% 1 / 1 Subroutinesub 95.4% 21 / 22 Podpod 40.0% 2 / 5 totaltotal 93.9% 124 / 132 SCAR 24.9
CC
12
Cov
96%
__ANON__
5.0
__ANON__
3.0
markdown_part
3.0
CRAP 12.0
↑ Summary Markdown/Stuffer.pm »
1 package Email::Simple::Markdown;
2 7 our $AUTHORITY = 'cpan:YANICK';
3 # ABSTRACT: simple email creation with auto text and html multipart body
4 7 $Email::Simple::Markdown::VERSION = '0.7.2';
5 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 7 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 7 ▶use Email::Abstract;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 7 ▶use Email::MIME;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 7 ▶use Email::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 7 ▶use List::Util 1.29 qw/ first pairmap /;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 7 ▶use Module::Runtime qw/ use_module /;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 7 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 7 extends 'Email::Simple';
19  
20 sub BUILDARGS {
21 8 ▶ return {};
Subroutine BUILDARGS: called CC=1 SCAR=0.0
Pod undocumented
22 }
23  
24 around create => sub {
25 8 ▶ my ( $orig, $self, %arg ) = @_;
Subroutine __ANON__: called CC=5 SCAR=16.1
26  
27 8 my @local_args = qw/ css markdown_engine pre_markdown_filter charset /;
28 8 my %md_arg;
29 8 @md_arg{@local_args} = delete @arg{@local_args};
30  
31 8 my $email = $orig->( $self, %arg );
32  
33 $email->markdown_engine_set(
34 8 ▶ $md_arg{markdown_engine}||'auto'
Condition100%2/2
$md_arg{'markdown_engine'} || 'auto'
l!l
35
MC/DC100%1/1
$md_arg{'markdown_engine'} || 'auto'
$md_arg{'markdown_engine'}
Truth table100%2/2
A
A= $md_arg{'markdown_engine'}
Aresult
11
00
35 );
36  
37 8 ▶ $email->charset_set( $md_arg{charset} ) if $md_arg{charset};
Branch: 1 branch
BranchTrueFalseTotal
if $md_arg{"charset"} 1 7 8
38 8 ▶ $email->css_set($md_arg{css}) if $md_arg{css};
Branch: 1 branch
BranchTrueFalseTotal
if $md_arg{"css"} 2 6 8
39 $email->pre_markdown_filter_set($md_arg{pre_markdown_filter})
40 8 ▶ if $md_arg{pre_markdown_filter};
Branch: 1 branch
BranchTrueFalseTotal
if $md_arg{"pre_markdown_filter"} 1 7 8
41  
42 8 return $email;
43 7 };
44  
45 7 our @SUPPORTED_ENGINES = qw/ Text::MultiMarkdown Text::Markdown /;
46  
47 has markdown_engine => (
48 is => 'rw',
49 lazy => 1,
50 0 ▶ default => sub { $_[0]->find_markdown_engine },
Subroutine __ANON__: not called CC=1 SCAR=6.9
51 clearer => 1,
52 coerce => sub {
53 8 ▶ my( $value ) = @_;
Subroutine __ANON__: called CC=2 SCAR=6.9
54
55 8 ▶ return $value eq 'auto'
Branch: 1 branch
BranchTrueFalseTotal
$value eq 'auto' ? : 5 3 8
56 ? __PACKAGE__->find_markdown_engine
57 : $value;
58 },
59 trigger => sub{
60 8 ▶ my( $self, $engine ) = @_;
Subroutine __ANON__: called CC=2 SCAR=7.1
61
62 8 ▶ die "engine '$engine' not implementing a 'markdown' method\n"
Branch: 1 branch
BranchTrueFalseTotal
unless &use_module($engine)->can("markdown") 0 8 8
63 unless use_module($engine)->can('markdown');
64  
65 8 $self->clear_markdown_object;
66 },
67 7 writer => 'markdown_engine_set',
68 );
69  
70 has markdown_object => (
71 is => 'rw',
72 lazy => 1,
73 clearer => 1,
74 8 ▶ default => sub { $_[0]->{markdown_engine}->new },
Subroutine __ANON__: called CC=1 SCAR=0.0
75 7 handles => {
76 _markdown => 'markdown',
77 }
78 );
79  
80 sub find_markdown_engine {
81 10 ▶ first { eval { use_module($_) } } @SUPPORTED_ENGINES
Subroutine __ANON__: called CC=1 SCAR=0.0
82 10 ▶ or die "No supported markdown engine found"
Subroutine find_markdown_engine: called CC=2 SCAR=7.6
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
&first(sub { eval { do { &use_module($_) } }; } , @Email::Simple::Markdown::SUPPORTED_ENGINES) or die "No supported markdown engine found" 0 10 10
83 }
84  
85 has markdown_css => (
86 is => 'rw',
87 reader => 'css',
88 writer => 'css_set',
89 coerce => sub {
90 2 ▶ my $css = shift;
Subroutine __ANON__: called CC=3 SCAR=11.0
91  
92 2 ▶ if ( ref $css eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $css eq "ARRAY") 1 1 2
93 1 my @css = @$css;
94  
95 1 ▶ croak "number of argument is not even" if @css % 2;
Branch: 1 branch
BranchTrueFalseTotal
if @css % 2 0 1 1
96  
97 1 ▶ $css = join "\n", pairmap { "$a { $b }" } @css;
Subroutine __ANON__: called CC=1 SCAR=0.0
98 }
99  
100 2 $css;
101 },
102 7 );
103  
104 7 has markdown_filter => (
105 is => 'rw',
106 writer => 'pre_markdown_filter_set',
107 );
108  
109 7 has markdown_charset => (
110 is => 'rw',
111 writer => 'charset_set',
112 );
113  
114 sub with_markdown {
115 11 ▶ my $self = shift;
Subroutine with_markdown: called CC=1 SCAR=0.0
Pod documented
116  
117 11 my $body = $self->body;
118
119 11 my $mail = Email::Abstract->new($self->SUPER::as_string)
120 ->cast('Email::MIME');
121  
122 11 $mail->content_type_set('multipart/alternative');
123  
124 11 $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 return Email::Abstract->new($mail);
143 }
144  
145 sub markdown_part {
146 11 ▶ my $self = shift;
Subroutine markdown_part: called CC=3 SCAR=11.0
Pod undocumented
147  
148 11 my $markdown = $self->body;
149  
150 11 ▶ if( my $filter = $self->markdown_filter ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $filter = $self->markdown_filter) 1 10 11
151 1 local $_ = $markdown;
152 1 $filter->();
153 1 $markdown = $_;
154 }
155
156 11 $markdown = $self->_markdown($markdown);
157 11 ▶ $markdown = '<style type="text/css">'
Branch: 1 branch
BranchTrueFalseTotal
if $self->css 2 9 11
158 . $self->css
159 . '</style>'
160 . $markdown
161 if $self->css;
162  
163 11 return $markdown;
164 }
165  
166 6 ▶sub as_string { $_[0]->with_markdown->as_string }
Subroutine as_string: called CC=1 SCAR=0.0
Pod documented
167  
168 7 1;
169  
170 __END__
↑ Summary Markdown/Stuffer.pm »