File Coverage

blib/lib/Sieve/Generator/Element/Qstr.pm
Criterion Covered Total %
statement 16 16 100.0
branch 1 2 50.0
condition 2 2 100.0
subroutine 4 4 100.0
pod 0 1 0.0
total 23 25 92.0


line stmt bran cond sub pod time code
1 1     1   9 use v5.36.0;
  1         2  
2             package Sieve::Generator::Element::Qstr 0.003;
3             # ABSTRACT: a Sieve quoted string
4              
5 1     1   28 use Moo;
  1         2  
  1         9  
6             with 'Sieve::Generator::Element';
7              
8             #pod =head1 DESCRIPTION
9             #pod
10             #pod A C renders a single Perl string as a Sieve quoted string.
11             #pod
12             #pod =attr str
13             #pod
14             #pod This attribute holds the string to be quoted.
15             #pod
16             #pod =cut
17              
18             has str => (is => 'ro', init_arg => 'str', required => 1);
19              
20 35     35 0 35 sub as_sieve ($self, $i = undef) {
  35         34  
  35         38  
  35         29  
21 35   100     61 $i //= 0;
22              
23             # Sieve strings and string lists are compatible with JSON
24             # https://tools.ietf.org/html/rfc5228#section-2.4.2
25             #
26             # Keep everything as a unicode string
27 35         35 state $JSON = JSON::MaybeXS->new->utf8(0)->allow_nonref;
28 35 50       70 Carp::confess("can't encode undef") unless defined $self->str; # XXX
29              
30 35         148 return (q{ } x $i) . $JSON->encode("" . $self->str);
31             }
32              
33 1     1   388 no Moo;
  1         1  
  1         3  
34             1;
35              
36             __END__