line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Config::IOD::Expr; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
53
|
use 5.010; |
|
2
|
|
|
|
|
6
|
|
4
|
2
|
|
|
2
|
|
12
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
77
|
|
5
|
2
|
|
|
2
|
|
12
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
1327
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY |
8
|
|
|
|
|
|
|
our $DATE = '2022-05-02'; # DATE |
9
|
|
|
|
|
|
|
our $DIST = 'Config-IOD-Reader'; # DIST |
10
|
|
|
|
|
|
|
our $VERSION = '0.345'; # VERSION |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
my $EXPR_RE = qr{ |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
(?&ANSWER) |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
(?(DEFINE) |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
(? (?&ADD)) |
19
|
|
|
|
|
|
|
(? (?&MULT) | (?&MULT) (?: \s* ([+.-]) \s* (?&MULT) )+) |
20
|
|
|
|
|
|
|
(? (?&UNARY) | (?&UNARY) (?: \s* ([*/x%]) \s* (?&UNARY))+) |
21
|
|
|
|
|
|
|
(? (?&POWER) | [!~+-] (?&POWER)) |
22
|
|
|
|
|
|
|
(? (?&TERM) | (?&TERM) (?: \s* \*\* \s* (?&TERM))+) |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
(? |
25
|
|
|
|
|
|
|
(?&NUM) |
26
|
|
|
|
|
|
|
| (?&STR_SINGLE) |
27
|
|
|
|
|
|
|
| (?&STR_DOUBLE) |
28
|
|
|
|
|
|
|
| undef |
29
|
|
|
|
|
|
|
| (?&VAR) |
30
|
|
|
|
|
|
|
| (?&FUNC) |
31
|
|
|
|
|
|
|
| \( \s* ((?&ANSWER)) \s* \) |
32
|
|
|
|
|
|
|
) |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
(? val \s* \( (?&TERM) \)) |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
(? |
37
|
|
|
|
|
|
|
( |
38
|
|
|
|
|
|
|
-? |
39
|
|
|
|
|
|
|
(?: 0 | [1-9][0-9]* ) |
40
|
|
|
|
|
|
|
(?: \. [0-9]+ )? |
41
|
|
|
|
|
|
|
(?: [eE] [-+]? [0-9]+ )? |
42
|
|
|
|
|
|
|
) |
43
|
|
|
|
|
|
|
) |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
(? \$[A-Za-z_][A-Za-z0-9_]{0,63}) |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
(? |
48
|
|
|
|
|
|
|
( |
49
|
|
|
|
|
|
|
' |
50
|
|
|
|
|
|
|
(?: |
51
|
|
|
|
|
|
|
[^\\']+ |
52
|
|
|
|
|
|
|
| |
53
|
|
|
|
|
|
|
\\ ['\\] |
54
|
|
|
|
|
|
|
| |
55
|
|
|
|
|
|
|
\\ |
56
|
|
|
|
|
|
|
)* |
57
|
|
|
|
|
|
|
' |
58
|
|
|
|
|
|
|
) |
59
|
|
|
|
|
|
|
) |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
(? |
62
|
|
|
|
|
|
|
( |
63
|
|
|
|
|
|
|
" |
64
|
|
|
|
|
|
|
(?: |
65
|
|
|
|
|
|
|
[^\\"]+ |
66
|
|
|
|
|
|
|
| |
67
|
|
|
|
|
|
|
\\ ["'\\\$tnrfbae] |
68
|
|
|
|
|
|
|
# octal, hex, wide hex |
69
|
|
|
|
|
|
|
)* |
70
|
|
|
|
|
|
|
" |
71
|
|
|
|
|
|
|
) |
72
|
|
|
|
|
|
|
) |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
) # DEFINE |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
}msx; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub _parse_expr { |
79
|
6
|
|
|
6
|
|
11
|
my $str = shift; |
80
|
|
|
|
|
|
|
|
81
|
6
|
100
|
|
|
|
1522
|
return [400, 'Not a valid expr'] unless $str =~ m{\A$EXPR_RE\z}o; |
82
|
2
|
|
|
2
|
|
15
|
my $res = eval "package Config::IOD::Expr::_Compiled; no strict; no warnings; $str"; ## no critic: BuiltinFunctions::ProhibitStringyEval |
|
2
|
|
|
2
|
|
3
|
|
|
2
|
|
|
2
|
|
50
|
|
|
2
|
|
|
2
|
|
10
|
|
|
2
|
|
|
1
|
|
4
|
|
|
2
|
|
|
1
|
|
92
|
|
|
2
|
|
|
|
|
10
|
|
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
66
|
|
|
2
|
|
|
|
|
11
|
|
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
61
|
|
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
28
|
|
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
28
|
|
|
5
|
|
|
|
|
364
|
|
83
|
5
|
50
|
|
|
|
17
|
return [500, "Died when evaluating expr: $@"] if $@; |
84
|
5
|
|
|
|
|
36
|
[200, "OK", $res]; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
1; |
88
|
|
|
|
|
|
|
# ABSTRACT: Parse expression |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
__END__ |