line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package String::PerlQuote; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $DATE = '2016-10-07'; # DATE |
4
|
|
|
|
|
|
|
our $VERSION = '0.02'; # VERSION |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
14059
|
use 5.010001; |
|
1
|
|
|
|
|
2
|
|
7
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
16
|
|
8
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
22
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
3
|
use Exporter; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
314
|
|
11
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
12
|
|
|
|
|
|
|
our @EXPORT_OK = qw( |
13
|
|
|
|
|
|
|
single_quote |
14
|
|
|
|
|
|
|
double_quote |
15
|
|
|
|
|
|
|
); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# BEGIN COPY PASTE FROM Data::Dump |
18
|
|
|
|
|
|
|
my %esc = ( |
19
|
|
|
|
|
|
|
"\a" => "\\a", |
20
|
|
|
|
|
|
|
"\b" => "\\b", |
21
|
|
|
|
|
|
|
"\t" => "\\t", |
22
|
|
|
|
|
|
|
"\n" => "\\n", |
23
|
|
|
|
|
|
|
"\f" => "\\f", |
24
|
|
|
|
|
|
|
"\r" => "\\r", |
25
|
|
|
|
|
|
|
"\e" => "\\e", |
26
|
|
|
|
|
|
|
); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# put a string value in double quotes |
29
|
|
|
|
|
|
|
sub double_quote { |
30
|
4
|
|
|
4
|
1
|
479
|
local($_) = $_[0]; |
31
|
|
|
|
|
|
|
# If there are many '"' we might want to use qq() instead |
32
|
4
|
|
|
|
|
18
|
s/([\\\"\@\$])/\\$1/g; |
33
|
4
|
100
|
|
|
|
23
|
return qq("$_") unless /[^\040-\176]/; # fast exit |
34
|
|
|
|
|
|
|
|
35
|
1
|
|
|
|
|
7
|
s/([\a\b\t\n\f\r\e])/$esc{$1}/g; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# no need for 3 digits in escape for these |
38
|
1
|
|
|
|
|
2
|
s/([\0-\037])(?!\d)/sprintf('\\%o',ord($1))/eg; |
|
0
|
|
|
|
|
0
|
|
39
|
|
|
|
|
|
|
|
40
|
1
|
|
|
|
|
1
|
s/([\0-\037\177-\377])/sprintf('\\x%02X',ord($1))/eg; |
|
0
|
|
|
|
|
0
|
|
41
|
1
|
|
|
|
|
3
|
s/([^\040-\176])/sprintf('\\x{%X}',ord($1))/eg; |
|
0
|
|
|
|
|
0
|
|
42
|
|
|
|
|
|
|
|
43
|
1
|
|
|
|
|
4
|
return qq("$_"); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
# END COPY PASTE FROM Data::Dump |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub single_quote { |
48
|
2
|
|
|
2
|
1
|
922
|
local($_) = $_[0]; |
49
|
2
|
|
|
|
|
10
|
s/([\\'])/\\$1/g; |
50
|
2
|
|
|
|
|
8
|
return qq('$_'); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
1; |
53
|
|
|
|
|
|
|
# ABSTRACT: Quote a string as Perl does |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
__END__ |