File Coverage

blib/lib/Sieve/Generator/Element/Heredoc.pm
Criterion Covered Total %
statement 20 20 100.0
branch 4 4 100.0
condition 2 2 100.0
subroutine 4 4 100.0
pod 0 1 0.0
total 30 31 96.7


line stmt bran cond sub pod time code
1 1     1   9 use v5.36.0;
  1         3  
2             package Sieve::Generator::Element::Heredoc 0.003;
3             # ABSTRACT: a Sieve multiline string (heredoc)
4              
5 1     1   5 use Moo;
  1         1  
  1         4  
6             with 'Sieve::Generator::Element';
7              
8             #pod =head1 DESCRIPTION
9             #pod
10             #pod A heredoc renders a block of text as a Sieve multiline string using the
11             #pod C/C<.> syntax defined in RFC 5228. It is typically used as an
12             #pod argument to a command when the content is too large or complex for a simple
13             #pod quoted string.
14             #pod
15             #pod =attr text
16             #pod
17             #pod This attribute holds the text content of the multiline string. A trailing
18             #pod newline is added automatically if absent, and any line beginning with C<.>
19             #pod is escaped to C<..>.
20             #pod
21             #pod =cut
22              
23             has text => (is => 'ro', required => 1);
24              
25             #pod =attr comment
26             #pod
27             #pod This attribute holds an optional hash comment that appears on the C
28             #pod line, as allowed by RFC 5228. If set, it renders as C.
29             #pod
30             #pod =cut
31              
32             has comment => (is => 'ro');
33              
34 7     7 0 1900 sub as_sieve ($self, $i = undef) {
  7         7  
  7         10  
  7         7  
35 7   100     19 $i //= 0;
36              
37 7         11 my $indent = q{ } x $i;
38 7         8 my $str = "${indent}text:";
39 7 100       16 $str .= " # " . $self->comment if defined $self->comment;
40 7         14 $str .= "\n" . $self->text;
41 7 100       19 $str .= "\n" unless $str =~ /\n\z/;
42 7         12 $str =~ s/^\./../mg;
43 7         14 return "$str.\n";
44             }
45              
46 1     1   438 no Moo;
  1         1  
  1         4  
47             1;
48              
49             __END__