File Coverage

blib/lib/Sieve/Generator/Text/Qstr.pm
Criterion Covered Total %
statement 15 15 100.0
branch 1 2 50.0
condition 2 2 100.0
subroutine 4 4 100.0
pod 0 1 0.0
total 22 24 91.6


line stmt bran cond sub pod time code
1 1     1   10 use v5.36.0;
  1         3  
2             package Sieve::Generator::Text::Qstr 0.001;
3             # ABSTRACT: a Sieve quoted string
4              
5 1     1   3 use Moo;
  1         2  
  1         8  
6             with 'Sieve::Generator::Text';
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 26     26 0 39 sub as_sieve ($self, $i = undef) {
  26         37  
  26         37  
  26         36  
21             # Sieve strings and string lists are compatible with JSON
22             # https://tools.ietf.org/html/rfc5228#section-2.4.2
23             #
24             # Keep everything as a unicode string
25 26         69 state $JSON = JSON::MaybeXS->new->utf8(0)->allow_nonref;
26 26 50       102 Carp::confess("can't encode undef") unless defined $self->str; # XXX
27              
28 26   100     284 return (q{ } x ($i // 0)) . $JSON->encode("" . $self->str);
29             }
30              
31 1     1   374 no Moo;
  1         1  
  1         3  
32             1;
33              
34             __END__