File Coverage

blib/lib/Sieve/Generator/Lines/Block.pm
Criterion Covered Total %
statement 21 21 100.0
branch 4 4 100.0
condition n/a
subroutine 4 4 100.0
pod 1 2 50.0
total 30 31 96.7


line stmt bran cond sub pod time code
1 1     1   28 use v5.36.0;
  1         4  
2             package Sieve::Generator::Lines::Block 0.001;
3             # ABSTRACT: a Sieve block (a brace-delimited sequence of statements)
4              
5 1     1   676 use Moo;
  1         8557  
  1         3  
6             with 'Sieve::Generator::Lines';
7              
8             #pod =head1 DESCRIPTION
9             #pod
10             #pod A block is the brace-delimited body of a Sieve C, C, or C
11             #pod clause. It contains an ordered list of things -- commands, nested
12             #pod conditionals, comments, or plain strings -- each rendered on its own indented
13             #pod line.
14             #pod
15             #pod =attr things
16             #pod
17             #pod This attribute holds the list of things that make up the block body. Each
18             #pod may be an object doing either L or
19             #pod L.
20             #pod
21             #pod =cut
22              
23             has _things => (is => 'ro', init_arg => 'things', required => 1);
24 26     26 1 41 sub things ($self) { $self->_things->@* }
  26         39  
  26         32  
  26         82  
25              
26 26     26 0 40 sub as_sieve ($self, $i = 0) {
  26         40  
  26         37  
  26         35  
27 26         44 my $class = ref $self;
28              
29 26         45 my $str = q{};
30 26         50 my $indent = q{ } x $i;
31 26         52 for my $thing ($self->things) {
32 28 100       132 my $text = ref $thing ? $thing->as_sieve($i+1)
33             : "$indent $thing";
34              
35 28 100       141 $text .= "\n" unless $text =~ /\n\z/;
36              
37 28         127 $str .= $text;
38             }
39              
40 26         116 return "{\n$str$indent}\n";
41             }
42              
43             1;
44              
45             __END__