line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Config::IOD::Expr; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
47
|
use 5.010; |
|
2
|
|
|
|
|
8
|
|
4
|
2
|
|
|
2
|
|
10
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
59
|
|
5
|
2
|
|
|
2
|
|
9
|
use warnings; |
|
2
|
|
|
|
|
12
|
|
|
2
|
|
|
|
|
1311
|
|
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.344'; # 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
|
|
|
|
1498
|
return [400, 'Not a valid expr'] unless $str =~ m{\A$EXPR_RE\z}o; |
82
|
2
|
|
|
2
|
|
13
|
my $res = eval "package Config::IOD::Expr::_Compiled; no strict; no warnings; $str"; ## no critic: BuiltinFunctions::ProhibitStringyEval |
|
2
|
|
|
2
|
|
4
|
|
|
2
|
|
|
2
|
|
44
|
|
|
2
|
|
|
2
|
|
9
|
|
|
2
|
|
|
1
|
|
6
|
|
|
2
|
|
|
1
|
|
81
|
|
|
2
|
|
|
|
|
11
|
|
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
51
|
|
|
2
|
|
|
|
|
11
|
|
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
55
|
|
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
29
|
|
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
28
|
|
|
5
|
|
|
|
|
298
|
|
83
|
5
|
50
|
|
|
|
14
|
return [500, "Died when evaluating expr: $@"] if $@; |
84
|
5
|
|
|
|
|
33
|
[200, "OK", $res]; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
1; |
88
|
|
|
|
|
|
|
# ABSTRACT: Parse expression |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
__END__ |