File Coverage

blib/lib/Sieve/Generator/Lines/Document.pm
Criterion Covered Total %
statement 30 30 100.0
branch 4 4 100.0
condition n/a
subroutine 6 6 100.0
pod 2 3 66.6
total 42 43 97.6


line stmt bran cond sub pod time code
1 1     1   10 use v5.36.0;
  1         3  
2             package Sieve::Generator::Lines::Document 0.001;
3             # ABSTRACT: a sequence of Sieve lines forming a complete script or blank line
4              
5 1     1   4 use Moo;
  1         1  
  1         4  
6             with 'Sieve::Generator::Lines';
7              
8             #pod =head1 DESCRIPTION
9             #pod
10             #pod A document is an ordered sequence of things, and renders as a flat sequence of
11             #pod Sieve lines. It serves as the top-level container for a complete Sieve script
12             #pod (when constructed by L) or as an empty separator
13             #pod line (when constructed by L).
14             #pod
15             #pod =attr things
16             #pod
17             #pod This attribute holds the list of things that make up the document. Each may
18             #pod be a string or an object doing L or
19             #pod L.
20             #pod
21             #pod =cut
22              
23             has _things => (is => 'ro', init_arg => 'things', required => 1);
24 8     8 1 15 sub things ($self) { $self->_things->@* }
  8         13  
  8         11  
  8         31  
25              
26             #pod =method append
27             #pod
28             #pod $doc->append(@things);
29             #pod
30             #pod This method adds the given C<@things> to the end of the document's list.
31             #pod
32             #pod =cut
33              
34 1     1 1 24 sub append ($self, @things) {
  1         3  
  1         2  
  1         2  
35 1         5 push $self->_things->@*, @things;
36 1         3 return;
37             }
38              
39 8     8 0 1093 sub as_sieve ($self, $i = 0) {
  8         15  
  8         17  
  8         13  
40 8         18 my $class = ref $self;
41              
42 8         15 my $str = q{};
43 8         24 my $indent = q{ } x $i;
44 8         23 for my $thing ($self->things) {
45 11 100       118 my $text = ref $thing ? $thing->as_sieve($i)
46             : "$indent$thing";
47              
48 11 100       54 $text .= "\n" unless $text =~ /\n\z/;
49              
50 11         29 $str .= $text;
51             }
52              
53 8         41 return $str;
54             }
55              
56 1     1   490 no Moo;
  1         2  
  1         5  
57             1;
58              
59             __END__