line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package SolarBeam::Util; |
2
|
3
|
|
|
3
|
|
164494
|
use Mojo::Base -strict; |
|
3
|
|
|
|
|
14
|
|
|
3
|
|
|
|
|
19
|
|
3
|
|
|
|
|
|
|
|
4
|
3
|
|
|
3
|
|
303
|
use Exporter 'import'; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
737
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our @EXPORT_OK = qw(escape escape_chars unescape_chars); |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
my $all = quotemeta('+-&|!(){}[]^~:\\"*?'); |
9
|
|
|
|
|
|
|
my $chars = quotemeta('+-&|!(){}[]^"~*?:\\'); |
10
|
|
|
|
|
|
|
my $wilds = quotemeta('+-&|!(){}[]^~:\\'); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub escape { |
13
|
13
|
|
|
13
|
1
|
676
|
my $s = shift; |
14
|
13
|
|
|
|
|
18
|
my $chars; |
15
|
|
|
|
|
|
|
|
16
|
13
|
100
|
|
|
|
34
|
if (ref $s) { |
17
|
4
|
|
|
|
|
7
|
$s = $$s; |
18
|
4
|
|
|
|
|
57
|
$s =~ s{([$all])}{\\$1}g; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
else { |
21
|
9
|
|
|
|
|
68
|
$s =~ s{([$wilds])}{\\$1}g; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
13
|
|
|
|
|
101
|
return $s; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub escape_chars { |
28
|
1
|
|
|
1
|
1
|
2
|
my $s = shift; |
29
|
1
|
|
|
|
|
23
|
$s =~ s{([$chars])}{\\$1}g; |
30
|
1
|
|
|
|
|
7
|
$s; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub unescape_chars { |
34
|
1
|
|
|
1
|
1
|
2
|
my $s = shift; |
35
|
1
|
|
|
|
|
25
|
$s =~ s{\\([$chars])}{$1}g; |
36
|
1
|
|
|
|
|
5
|
$s; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
1; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=encoding utf8 |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head1 NAME |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
SolarBeam::Util - Utility functions for SolarBeam |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head1 SYNOPSIS |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
use SolarBeam::Util qw(escape escape_chars unescape_chars); |
50
|
|
|
|
|
|
|
say escape_chars "foo?*"; |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head1 DESCRIPTION |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
L contains utility functions for L. |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head1 FUNCTIONS |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head2 escape |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
$str = escape $str; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head2 escape_chars |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
$str = escape_chars $str; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
The following values must be escaped in a search value: |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
+ - & | ! ( ) { } [ ] ^ " ~ * ? : \ |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
B Values sent to L are automatically escaped for you. |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head2 unescape_chars |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
$str = unescape_chars $str; |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
Unescapes values escaped in L. |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head1 SEE ALSO |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
L. |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=cut |