File Coverage

blib/lib/Sieve/Generator/Element.pm
Criterion Covered Total %
statement 20 20 100.0
branch 2 2 100.0
condition n/a
subroutine 5 5 100.0
pod 2 2 100.0
total 29 29 100.0


line stmt bran cond sub pod time code
1 1     1   8672 use v5.36.0;
  1         3  
2             package Sieve::Generator::Element 0.003;
3             # ABSTRACT: role for objects that render as Sieve code
4              
5 1     1   4 use Moo::Role;
  1         1  
  1         5  
6              
7             #pod =head1 DESCRIPTION
8             #pod
9             #pod This role is consumed by all objects that can render themselves as Sieve code.
10             #pod It requires a single method, C.
11             #pod
12             #pod =method as_sieve
13             #pod
14             #pod my $sieve_text = $element->as_sieve;
15             #pod my $sieve_text = $element->as_sieve($indent_level);
16             #pod
17             #pod This method renders the object as a string of Sieve code. The optional
18             #pod C<$indent_level> argument is a non-negative integer controlling the
19             #pod indentation depth; each level adds two spaces. If not given, no indenting is
20             #pod added.
21             #pod
22             #pod =method children
23             #pod
24             #pod my @children = $element->children;
25             #pod
26             #pod Returns all child Elements of this node. Leaf nodes return an empty list.
27             #pod Container nodes return their direct children. This is used by
28             #pod C to walk the tree.
29             #pod
30             #pod =cut
31              
32 16     16 1 16 sub children ($self) { () }
  16         14  
  16         13  
  16         19  
33              
34             #pod =method find_elements
35             #pod
36             #pod my @found = $element->find_elements(\&predicate);
37             #pod
38             #pod Walks the element tree depth-first, returning all elements (including
39             #pod C<$element> itself) for which the predicate returns true. Descends into
40             #pod matching nodes, so all matches at any depth are returned.
41             #pod
42             #pod =cut
43              
44 52     52 1 2877 sub find_elements ($self, $code) {
  52         50  
  52         46  
  52         47  
45 52         48 my @found;
46 52 100       57 push @found, $self if $code->($self);
47 52         272 push @found, $_->find_elements($code) for $self->children;
48 52         75 return @found;
49             }
50              
51             requires 'as_sieve';
52              
53 1     1   541 no Moo::Role;
  1         1  
  1         4  
54             1;
55              
56             __END__