File Coverage

blib/lib/Sah/Schema/percent_str.pm
Criterion Covered Total %
statement 6 6 100.0
branch n/a
condition n/a
subroutine 2 2 100.0
pod n/a
total 8 8 100.0


line stmt bran cond sub pod time code
1             package Sah::Schema::percent_str;
2              
3 1     1   352922 use strict;
  1         2  
  1         46  
4              
5 1     1   4808 use Regexp::Pattern::Float;
  1         2126  
  1         251  
6              
7             our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
8             our $DATE = '2024-02-06'; # DATE
9             our $DIST = 'Sah-Schemas-Str'; # DIST
10             our $VERSION = '0.018'; # VERSION
11              
12             our $schema = [str => {
13             summary => 'A number in percent form, e.g. "10.5%"',
14             match => qr/\A$Regexp::Pattern::Float::RE{float_decimal}{pat}%\z/,
15              
16             description => <<'_',
17              
18             This schema accepts floating number followed by percent sign. Unlike the
19             `percent` schema from , The percent sign will not be
20             removed nor the number be converted to decimal (e.g. 50% to 0.5).
21              
22             _
23             examples => [
24             {value=>'', valid=>0, summary=>'No percent sign'},
25             {value=>'1', valid=>0, summary=>'No percent sign'},
26             {value=>'1%', valid=>1},
27             {value=>'1 %', valid=>0, summary=>'Whitespace before percent sign is currently not allowed'},
28             {value=>'-1.23%', valid=>1},
29             {value=>'%', valid=>0, summary=>'Percent sign only'},
30             ],
31              
32             }];
33              
34             1;
35             # ABSTRACT:
36              
37             __END__