| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Sah::Schema::code_from_str; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
310238
|
use strict; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
152
|
|
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY |
|
6
|
|
|
|
|
|
|
our $DATE = '2023-12-20'; # DATE |
|
7
|
|
|
|
|
|
|
our $DIST = 'Sah-Schemas-Code'; # DIST |
|
8
|
|
|
|
|
|
|
our $VERSION = '0.003'; # VERSION |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $schema = [ |
|
11
|
|
|
|
|
|
|
code => { |
|
12
|
|
|
|
|
|
|
summary => 'Coderef from eval\`ed string', |
|
13
|
|
|
|
|
|
|
description => <<'MARKDOWN', |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
This schema accepts coderef or string which will be eval'ed to coderef. Note |
|
16
|
|
|
|
|
|
|
that this means allowing your user to provide arbitrary Perl code for you to |
|
17
|
|
|
|
|
|
|
execute! Make sure first and foremost that security-wise this is acceptable in |
|
18
|
|
|
|
|
|
|
your case. |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
By default `eval()` is performed in the `main` namespace and without stricture |
|
21
|
|
|
|
|
|
|
or warnings. See the parameterized version if |
|
22
|
|
|
|
|
|
|
you want to customize the `eval()`. |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
What's the difference between this schema and `str_or_code` (from |
|
25
|
|
|
|
|
|
|
)? Both this schema and `str_or_code` accept string, but |
|
26
|
|
|
|
|
|
|
this schema will directly compile any input string while `str_or_code` will only |
|
27
|
|
|
|
|
|
|
convert string to code if it is in the form of `sub { ... }`. In other words, |
|
28
|
|
|
|
|
|
|
this schema will always produce coderef, while `str_or_code` can produce strings |
|
29
|
|
|
|
|
|
|
also. |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
MARKDOWN |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
prefilters => [ ['Code::eval'=>{}] ], |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
examples => [ |
|
36
|
|
|
|
|
|
|
], |
|
37
|
|
|
|
|
|
|
}, |
|
38
|
|
|
|
|
|
|
]; |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
1; |
|
41
|
|
|
|
|
|
|
# ABSTRACT: Coderef from string |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
__END__ |