File Coverage

blib/lib/Sieve/Generator/Text/QstrList.pm
Criterion Covered Total %
statement 17 17 100.0
branch 1 2 50.0
condition 2 2 100.0
subroutine 4 4 100.0
pod 0 1 0.0
total 24 26 92.3


line stmt bran cond sub pod time code
1 1     1   9 use v5.36.0;
  1         3  
2             package Sieve::Generator::Text::QstrList 0.001;
3             # ABSTRACT: a Sieve string list (a bracketed list of quoted strings)
4              
5 1     1   4 use Moo;
  1         1  
  1         5  
6             with 'Sieve::Generator::Text';
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 9     9 0 15 sub as_sieve ($self, $i = undef) {
  9         13  
  9         13  
  9         15  
23 9         26 state $JSON = JSON::MaybeXS->new->utf8(0)->allow_nonref;
24              
25 9         50 my $str = join q{, }, map {;
26 18 50       51 defined || Carp::confess("can't encode undef"); # XXX
27 18         72 $JSON->encode("$_")
28             } $self->strs->@*;
29              
30 9   100     54 return (q{ } x ($i // 0)) . "[ $str ]";
31             }
32              
33 1     1   423 no Moo;
  1         14  
  1         3  
34             1;
35              
36             __END__