File Coverage

blib/lib/Sieve/Generator/Lines/Command.pm
Criterion Covered Total %
statement 22 22 100.0
branch 2 2 100.0
condition 1 2 50.0
subroutine 6 6 100.0
pod 1 2 50.0
total 32 34 94.1


line stmt bran cond sub pod time code
1 1     1   11 use v5.36.0;
  1         2  
2             package Sieve::Generator::Lines::Command 0.001;
3             # ABSTRACT: a single Sieve command statement
4              
5 1     1   4 use Moo;
  1         1  
  1         4  
6             with 'Sieve::Generator::Lines';
7              
8 1     1   1173 use Params::Util qw(_ARRAY0);
  1         2  
  1         254  
9              
10             #pod =head1 DESCRIPTION
11             #pod
12             #pod A command is a single semicolon-terminated Sieve statement, such as C,
13             #pod C, or C. It consists of an identifier followed by
14             #pod zero or more arguments.
15             #pod
16             #pod =attr identifier
17             #pod
18             #pod This attribute holds the name of the Sieve command, such as C,
19             #pod C, or C.
20             #pod
21             #pod =cut
22              
23             has identifier => (is => 'ro', required => 1);
24              
25             #pod =attr args
26             #pod
27             #pod This attribute holds the list of arguments to the command. Each argument may
28             #pod be a plain string or an object doing L.
29             #pod
30             #pod =cut
31              
32             has _args => (is => 'ro', required => 1, init_arg => 'args');
33 25     25 1 97 sub args { $_[0]->_args->@* }
34              
35 25     25 0 77 sub as_sieve ($self, $i = undef) {
  25         37  
  25         38  
  25         28  
36 25   50     64 my $indent = q{ } x ($i // 0);
37              
38 25         68 my $str = $indent . $self->identifier;
39 25         37 my $n = 0;
40              
41 25 100       57 $str .= ' ' . (ref $_ ? $_->as_sieve(0) : $_) for $self->args;
42 25         41 $str .= ";\n";
43              
44 25         70 return $str;
45             }
46              
47 1     1   7 no Moo;
  1         2  
  1         4  
48             1;
49              
50             __END__