Data/Sah/Filter/perl/Str/maybe_eval.pm

filter: Statementstmt 61.1% 11 / 18 Branchbran n/a Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 50.0% 2 / 4 Podpod 0.0% 0 / 2 totaltotal 48.1% 13 / 27 CC 2 SCAR 11.6
CC
2
Cov
55%
filter
6.0
meta
2.0
BEGIN
1.0
CRAP 3.2
« Sah/Schema/str_or_re_or_code.pm ↑ Summary Data/Sah/Filter/perl/Str/maybe_convert_to_re.pm »
1 package Data::Sah::Filter::perl::Str::maybe_eval;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
7 1 our $DATE = '2024-02-06'; # DATE
8 1 our $DIST = 'Sah-Schemas-Str'; # DIST
9 1 our $VERSION = '0.018'; # VERSION
10  
11 0 ▶sub meta {
Subroutine meta: not called CC=1 SCAR=6.9
Pod undocumented
12 +{
13 0 v => 1,
14 summary => "Eval string if in the form of 'sub { ... }'",
15 might_fail => 1,
16 args => {
17 # XXX namespace
18 # XXX use strict?
19 # XXX use warnings?
20 },
21 };
22 }
23  
24 0 ▶sub filter {
Subroutine filter: not called CC=2 SCAR=17.9
Pod undocumented
25 0 my %fargs = @_;
26  
27 0 my $dt = $fargs{data_term};
28 0 ▶ my $gen_args = $fargs{args} // {};
Condition0%0/2
$fargs{"args"} // {}
l!l
00
MC/DC0%0/1
$fargs{"args"} // {}
$fargs{"args"}
Truth table0%0/2
A
A= $fargs{"args"}
Aresult
11
00
29  
30 0 my $res = {};
31 0 $res->{expr_filter} = join(
32 "",
33 "do {", (
34 "my \$tmp = $dt; ",
35 "if (ref(\$tmp) || \$tmp !~ qr/\\Asub\\s*\\{.*\\}\\z/s) { ", (
36 "[undef, \$tmp] "), # pass through
37 "} else { ", (
38 "my \$code = eval qq(package main; \$tmp); if (\$@) { [\"Error in compiling code: \$@\", \$tmp] } else { [undef, \$code] } ",
39 "}"),
40 ),
41 "}",
42 );
43  
44 0 $res;
45 }
46  
47 1 1;
48 # ABSTRACT: Eval string if in the form of 'sub { ... }'
49  
50 __END__
« Sah/Schema/str_or_re_or_code.pm ↑ Summary Data/Sah/Filter/perl/Str/maybe_convert_to_re.pm »