File Coverage

blib/lib/Sieve/Generator/Element/Num.pm
Criterion Covered Total %
statement 17 17 100.0
branch n/a
condition 3 4 75.0
subroutine 5 5 100.0
pod 0 1 0.0
total 25 27 92.5


line stmt bran cond sub pod time code
1 1     1   8 use v5.36.0;
  1         3  
2             package Sieve::Generator::Element::Num 0.003;
3             # ABSTRACT: a Sieve numeric literal
4              
5 1     1   4 use Moo;
  1         1  
  1         4  
6             with 'Sieve::Generator::Element';
7              
8 1     1   287 use Carp ();
  1         2  
  1         243  
9              
10             #pod =head1 DESCRIPTION
11             #pod
12             #pod A C renders a non-negative integer, optionally followed by a size suffix
13             #pod (C, C, or C), as a Sieve number literal per RFC 5228 section 2.4.1.
14             #pod
15             #pod =attr value
16             #pod
17             #pod This attribute holds the non-negative integer value.
18             #pod
19             #pod =cut
20              
21             has value => (
22             is => 'ro',
23             isa => sub {
24             Carp::croak("value must be a non-negative integer")
25             unless defined $_[0] && $_[0] =~ /\A[0-9]+\z/;
26             },
27             required => 1,
28             );
29              
30             #pod =attr suffix
31             #pod
32             #pod This attribute holds an optional size suffix: C, C, or C (case
33             #pod insensitive on input, always rendered uppercase). If not provided, no suffix
34             #pod is appended.
35             #pod
36             #pod =cut
37              
38             has suffix => (
39             is => 'ro',
40             isa => sub {
41             return unless defined $_[0];
42             Carp::croak("suffix must be K, M, or G")
43             unless $_[0] =~ /\A[KMGkmg]\z/;
44             },
45             coerce => sub { defined $_[0] ? uc $_[0] : $_[0] },
46             );
47              
48 3     3 0 24 sub as_sieve ($self, $i = undef) {
  3         5  
  3         4  
  3         5  
49 3   50     6 $i //= 0;
50 3   100     19 return (q{ } x $i) . $self->value . ($self->suffix // '');
51             }
52              
53 1     1   5 no Moo;
  1         2  
  1         2  
54             1;
55              
56             __END__