blib/lib/Email/MIME/Kit/Assembler/TextifyHTML.pm

filter: Statementstmt 96.3% 26 / 27 Branchbran 50.0% 1 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 85.7% 6 / 7 Podpod n/a totaltotal 91.6% 33 / 36 CC 3 SCAR 5.8
CC
3
Cov
93%
__ANON__
3.0
__ANON__
2.0
BEGIN
1.0
CRAP 1.8
↑ Summary
1 package Email::MIME::Kit::Assembler::TextifyHTML 1.005;
2 # ABSTRACT: textify some HTML arguments to assembly
3  
4 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 extends 'Email::MIME::Kit::Assembler::Standard';
6  
7 #pod =head1 SYNOPSIS
8 #pod
9 #pod In your F<manifest.yaml>:
10 #pod
11 #pod alteratives:
12 #pod - type: text/plain
13 #pod path: body.txt
14 #pod assembler:
15 #pod - TextifyHTML
16 #pod - html_args: [ body ]
17 #pod - type: text/html
18 #pod path: body.html
19 #pod
20 #pod Then:
21 #pod
22 #pod my $email = $kit->assemble({
23 #pod body => '<div><p> ... </p></div>',
24 #pod });
25 #pod
26 #pod The C<body> argument will be rendered intact in the the HTML part, but will
27 #pod converted to plaintext before the plaintext part is rendered.
28 #pod
29 #pod This will be done by
30 #pod L<HTML::FormatText::WithLinks|HTML::FormatText::WithLinks>, using the arguments
31 #pod provided in the C<formatter_args> assembler attribute.
32 #pod
33 #pod =head1 BY THE WAY
34 #pod
35 #pod There will probably exist a TextifyHTML renderer, someday, which will first
36 #pod render the part with the parent part's renderer, and then convert the produced
37 #pod HTML to text. This would allow you to use one template for both HTML and text.
38 #pod
39 #pod =cut
40  
41 1 ▶use HTML::FormatText::WithLinks;
Subroutine BEGIN: called CC=1 SCAR=0.0
42  
43 has html_args => (
44 is => 'ro',
45 isa => 'ArrayRef',
46 0 ▶ default => sub { [] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
47 1 );
48  
49 has formatter_args => (
50 is => 'ro',
51 isa => 'HashRef',
52 1 ▶ default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
53 return {
54 1 before_link => '',
55 after_link => ' [%l]',
56 footnote => '',
57 leftmargin => 0,
58 };
59 },
60 1 );
61  
62 has formatter => (
63 is => 'ro',
64 isa => 'HTML::FormatText::WithLinks',
65 lazy => 1,
66 init_arg => undef,
67 1 ▶ default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
68 1 my ($self) = @_;
69 HTML::FormatText::WithLinks->new(
70 1 %{ $self->formatter_args },
71 );
72 }
73 1 );
74  
75 1 ▶around assemble => sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
76 1 my ($orig, $self, $arg) = @_;
77 1 my $local_arg = { %$arg };
78  
79 1 for my $key (@{ $self->html_args }) {
80 1 ▶ next unless defined $local_arg->{ $key };
Branch: 1 branch
BranchTrueFalseTotal
unless defined $local_arg->{$key} 0 1 1
81 1 $local_arg->{ $key } = $self->formatter->parse($local_arg->{ $key });
82 }
83  
84 1 return $self->$orig($local_arg);
85 1 };
86  
87 1 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
88 1 1;
89  
90 __END__
↑ Summary