File Coverage

blib/lib/Sieve/Generator/Element/Junction.pm
Criterion Covered Total %
statement 28 32 87.5
branch 5 6 83.3
condition 1 2 50.0
subroutine 5 6 83.3
pod 1 3 33.3
total 40 49 81.6


line stmt bran cond sub pod time code
1 1     1   9 use v5.36.0;
  1         3  
2             package Sieve::Generator::Element::Junction 0.003;
3             # ABSTRACT: a Sieve allof/anyof/noneof test
4              
5 1     1   3 use Moo;
  1         1  
  1         4  
6             with 'Sieve::Generator::Element';
7              
8             #pod =head1 DESCRIPTION
9             #pod
10             #pod A junction renders a Sieve multi-test expression: C,
11             #pod C, or C (for C). Each contained test is
12             #pod rendered on its own indented line.
13             #pod
14             #pod =attr type
15             #pod
16             #pod This attribute holds the junction type. It must be one of C,
17             #pod C, or C.
18             #pod
19             #pod =cut
20              
21             #pod =attr things
22             #pod
23             #pod This attribute holds the list of tests in the junction. Each may be a plain
24             #pod string or an object doing L.
25             #pod
26             #pod =cut
27              
28             has type => (is => 'ro', required => 1);
29              
30             has _things => (is => 'ro', init_arg => 'things', required => 1);
31 5     5 1 6 sub things ($self) { $self->_things->@* }
  5         6  
  5         5  
  5         12  
32 0     0 0 0 sub children ($self) { $self->things }
  0         0  
  0         0  
  0         0  
33              
34 5     5 0 6 sub as_sieve ($self, $i = undef) {
  5         6  
  5         5  
  5         5  
35 5   50     8 $i //= 0;
36 5         7 my $indent = q{ } x $i;
37              
38 5         10 my $type = $self->type;
39 5 50       15 my $func = $type eq 'anyof' ? 'anyof'
    100          
    100          
40             : $type eq 'allof' ? 'allof'
41             : $type eq 'noneof' ? 'not anyof'
42             : die "unknown junction type";
43              
44 5         6 my $str = "${indent}$func(\n";
45              
46 5         6 my @strs;
47 5         10 for my $thing ($self->things) {
48 10         19 my $substr = $thing->as_sieve($i+1);
49 10         13 push @strs, $substr;
50             }
51              
52 5         12 $str .= join qq{,\n}, @strs;
53 5         7 $str .= "\n${indent})";
54              
55 5         16 return $str;
56             }
57              
58 1     1   513 no Moo;
  1         2  
  1         3  
59             1;
60              
61             __END__