blib/lib/String/PerlQuote.pm

filter: Statementstmt 90.3% 28 / 31 Branchbran 100% 2 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod 100% 2 / 2 totaltotal 92.6% 38 / 41 CC 2 SCAR 2.6
CC
2
Cov
91%
double_quote
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.3
↑ Summary
1 package String::PerlQuote;
2  
3 2 our $DATE = '2016-10-07'; # DATE
4 2 our $VERSION = '0.02'; # VERSION
5  
6 2 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 our @ISA = qw(Exporter);
12 2 our @EXPORT_OK = qw(
13 single_quote
14 double_quote
15 );
16  
17 # BEGIN COPY PASTE FROM Data::Dump
18 2 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 4 ▶sub double_quote {
Subroutine double_quote: called CC=2 SCAR=7.2
Pod documented
30 4 local($_) = $_[0];
31 # If there are many '"' we might want to use qq() instead
32 4 s/([\\\"\@\$])/\\$1/g;
33 4 ▶ return qq("$_") unless /[^\040-\176]/; # fast exit
Branch: 1 branch
BranchTrueFalseTotal
unless /[^\040-\176]/ 3 1 4
34  
35 1 s/([\a\b\t\n\f\r\e])/$esc{$1}/g;
36  
37 # no need for 3 digits in escape for these
38 0 s/([\0-\037])(?!\d)/sprintf('\\%o',ord($1))/eg;
39  
40 0 s/([\0-\037\177-\377])/sprintf('\\x%02X',ord($1))/eg;
41 0 s/([^\040-\176])/sprintf('\\x{%X}',ord($1))/eg;
42  
43 1 return qq("$_");
44 }
45 # END COPY PASTE FROM Data::Dump
46  
47 2 ▶sub single_quote {
Subroutine single_quote: called CC=1 SCAR=0.0
Pod documented
48 2 local($_) = $_[0];
49 2 s/([\\'])/\\$1/g;
50 2 return qq('$_');
51 }
52 2 1;
53 # ABSTRACT: Quote a string as Perl does
54  
55 __END__
↑ Summary