File Coverage

blib/lib/Sieve/Generator/Element/QstrList.pm
Criterion Covered Total %
statement 18 18 100.0
branch 1 2 50.0
condition 1 2 50.0
subroutine 4 4 100.0
pod 0 1 0.0
total 24 27 88.8


line stmt bran cond sub pod time code
1 1     1   9 use v5.36.0;
  1         4  
2             package Sieve::Generator::Element::QstrList 0.003;
3             # ABSTRACT: a Sieve string list (a bracketed list of quoted strings)
4              
5 1     1   5 use Moo;
  1         1  
  1         4  
6             with 'Sieve::Generator::Element';
7              
8             #pod =head1 DESCRIPTION
9             #pod
10             #pod A C renders a list of Perl strings as a Sieve string list -- a
11             #pod comma-separated sequence of quoted strings enclosed in square brackets, as
12             #pod defined in RFC 5228 section 2.4.2.
13             #pod
14             #pod =attr strs
15             #pod
16             #pod This attribute holds the arrayref of strings to be encoded.
17             #pod
18             #pod =cut
19              
20             has strs => (is => 'ro', init_arg => 'strs', required => 1);
21              
22 17     17 0 18 sub as_sieve ($self, $i = undef) {
  17         16  
  17         17  
  17         17  
23 17   50     19 $i //= 0;
24              
25 17         28 state $JSON = JSON::MaybeXS->new->utf8(0)->allow_nonref;
26              
27 17         41 my $str = join q{, }, map {;
28 34 50       44 defined || Carp::confess("can't encode undef"); # XXX
29 34         80 $JSON->encode("$_")
30             } $self->strs->@*;
31              
32 17         40 return (q{ } x $i) . "[ $str ]";
33             }
34              
35 1     1   418 no Moo;
  1         2  
  1         3  
36             1;
37              
38             __END__