Coerce/perl/To_bool/From_str/common_words.pm

filter: Statementstmt 100% 22 / 22 Branchbran 100% 2 / 2 Conditioncond 100% 4 / 4 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 5 / 5 Podpod 0.0% 0 / 2 totaltotal 94.5% 35 / 37 CC 4 SCAR 9.2
CC
4
Cov
100%
coerce
4.0
BEGIN
1.0
BEGIN
1.0
CRAP 2.5
« Coerce/perl/To_duration/From_str/iso8601.pm ↑ Summary Coerce/js/To_date/From_float/epoch.pm »
1 package Data::Sah::Coerce::perl::To_bool::From_str::common_words;
2  
3 3 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 3 our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
8 3 our $DATE = '2023-10-24'; # DATE
9 3 our $DIST = 'Data-Sah-Coerce'; # DIST
10 3 our $VERSION = '0.054'; # VERSION
11  
12 4 ▶sub meta {
Subroutine meta: called CC=1 SCAR=0.0
Pod undocumented
13 +{
14 4 v => 4,
15 summary => 'Convert common true/false words (e.g. "yes","true","on","1" to "1", and "no","false","off","0" to "")',
16 prio => 50,
17 args => {
18 # mostly for testing of args
19 ci => {
20 schema => 'bool*',
21 default => 1,
22 },
23 },
24 };
25 }
26  
27 4 ▶sub coerce {
Subroutine coerce: called CC=4 SCAR=13.9
Pod undocumented
28 4 my %cargs = @_;
29  
30 4 my $dt = $cargs{data_term};
31 4 ▶ my $gen_args = $cargs{args} // {};
Condition100%2/2
$cargs{"args"} // {}
l!l
22
MC/DC100%1/1
$cargs{"args"} // {}
$cargs{"args"}
Truth table100%2/2
A
A= $cargs{"args"}
Aresult
11
00
32  
33 4 my $res = {};
34  
35 4 $res->{expr_match} = join(
36 " && ",
37 "1",
38 );
39  
40 4 ▶ my $modifier = ($gen_args->{ci} // 1) ? "i" : "";
Branch: 1 branch
BranchTrueFalseTotal
$gen_args->{'ci'} // 1 ? : 3 1 4
Condition100%2/2
$gen_args->{"ci"} // 1
l!l
22
MC/DC100%1/1
$gen_args->{"ci"} // 1
$gen_args->{"ci"}
Truth table100%2/2
A
A= $gen_args->{"ci"}
Aresult
11
00
41 4 $res->{expr_coerce} = "$dt =~ /\\A(yes|true|on)\\z/$modifier ? 1 : $dt =~ /\\A(no|false|off|0)\\z/$modifier ? '' : $dt";
42  
43 4 $res;
44 }
45  
46 3 1;
47 # ABSTRACT: Convert common true/false words (e.g. "yes","true","on","1" to "1", and "no","false","off","0" to "")
48  
49 __END__
« Coerce/perl/To_duration/From_str/iso8601.pm ↑ Summary Coerce/js/To_date/From_float/epoch.pm »