Quote.pm

filter: Statementstmt 82.9% 161 / 194 Branchbran 60.7% 102 / 168 Conditioncond 57.6% 30 / 52 MC/DCmcdc 35.4% 11 / 31 Subroutinesub 82.7% 24 / 29 Podpod 100% 8 / 8 totaltotal 69.7% 336 / 482 SCAR 59.9
CC
108
Cov
71%
quote_sub
69.3
unquote_sub
54.4
BEGIN
25.6
CRAP 399.2
↑ Summary Defer.pm »
1 package Sub::Quote;
2  
3 3 ▶sub _clean_eval { eval $_[0] }
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine _clean_eval: called CC=1 SCAR=0.0
4  
5 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 7 our $VERSION = '2.006_007';
9 7 $VERSION =~ tr/_//d;
10  
11 8 ▶use Sub::Defer qw(defer_sub);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 8 ▶use Scalar::Util qw(weaken);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 8 ▶use Exporter ();
Subroutine BEGIN: called CC=1 SCAR=0.0
14 8 ▶BEGIN { *import = \&Exporter::import }
Subroutine BEGIN: called CC=1 SCAR=0.0
15 8 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
16 8 ▶BEGIN { our @CARP_NOT = qw(Sub::Defer) }
Subroutine BEGIN: called CC=1 SCAR=0.0
17 8 ▶use B ();
Subroutine BEGIN: called CC=1 SCAR=0.0
18 BEGIN {
19 8 ▶ my $TRUE = sub(){!!1};
Subroutine BEGIN: called CC=15 SCAR=32.4
20 8 my $FALSE = sub(){!!0};
21 8 ▶ *_HAVE_IS_UTF8 = defined &utf8::is_utf8 ? $TRUE : $FALSE;
Branch: 1 branch
BranchTrueFalseTotal
defined &utf8::is_utf8 ? : 6 1 7
22 8 ▶ *_HAVE_PERLSTRING = defined &B::perlstring ? $TRUE : $FALSE;
Branch: 1 branch
BranchTrueFalseTotal
defined &B::perlstring ? : 6 1 7
23 7 ▶ *_CAN_TRACK_BOOLEANS = defined &builtin::is_bool ? $TRUE : $FALSE;
Branch: 1 branch
BranchTrueFalseTotal
defined &builtin::is_bool ? : 7 0 7
24 7 ▶ *_CAN_TRACK_NUMBERS = defined &builtin::created_as_number ? $TRUE : $FALSE;
Branch: 1 branch
BranchTrueFalseTotal
defined &builtin::created_as_number ? : 7 0 7
25 7 ▶ *_BAD_BACKSLASH_ESCAPE = _HAVE_PERLSTRING() && "$]" == 5.010_000 ? $TRUE : $FALSE;
Branch: 1 branch
BranchTrueFalseTotal
&_HAVE_PERLSTRING() && "$]" == 5.01 ? : 0 7 7
Condition66%2/3
&_HAVE_PERLSTRING() and "$]" == "5.01"
!ll&&!rl&&r
160
MC/DC0%0/2
&_HAVE_PERLSTRING() and "$]" == "5.01"
&_HAVE_PERLSTRING() "$]" == "5.01"
Truth table66%2/3
A and B
A= &_HAVE_PERLSTRING()B= "$]" == "5.01"
ABresult
0X0
100
111
26 7 ▶ *_HAVE_HEX_FLOAT = !$ENV{SUB_QUOTE_NO_HEX_FLOAT} && "$]" >= 5.022 ? $TRUE : $FALSE;
Branch: 1 branch
BranchTrueFalseTotal
!$ENV{'SUB_QUOTE_NO_HEX_FLOAT'} && "$]" >= 5.022 ? : 6 1 7
Condition66%2/3
not $ENV{"SUB_QUOTE_NO_HEX_FLOAT"} and "$]" >= "5.022"
!ll&&!rl&&r
106
MC/DC50%1/2
not $ENV{"SUB_QUOTE_NO_HEX_FLOAT"} and "$]" >= "5.022"
not $ENV{"SUB_QUOTE_NO_HEX_FLOAT"} "$]" >= "5.022"
Truth table66%2/3
not(A) and B
A= not $ENV{"SUB_QUOTE_NO_HEX_FLOAT"}B= "$]" >= "5.022"
ABresult
0X0
100
111
27  
28 # This may not be perfect, as we can't tell the format purely from the size
29 # but it should cover the common cases, and other formats are more likely to
30 # be less precise.
31 7 my $nvsize = 8 * length pack 'F', 0;
32 7 ▶ my $nvmantbits
Branch: 6 branches
BranchTrueFalseTotal
$nvsize == 16 ? : 0 7 7
$nvsize == 32 ? : 0 7 7
$nvsize == 64 ? : 7 0 7
$nvsize == 80 ? : 0 0 0
$nvsize == 128 ? : 0 0 0
$nvsize == 256 ? : 0 0 0
33 = $nvsize == 16 ? 11
34 : $nvsize == 32 ? 24
35 : $nvsize == 64 ? 53
36 : $nvsize == 80 ? 64
37 : $nvsize == 128 ? 113
38 : $nvsize == 256 ? 237
39 : 237 # unknown float format
40 ;
41 7 my $precision = int( log(2)/log(10)*$nvmantbits );
42  
43 7 ▶ *_NVSIZE = sub(){$nvsize};
Subroutine __ANON__: not called CC=1 SCAR=1.2
44 7 ▶ *_NVMANTBITS = sub(){$nvmantbits};
Subroutine __ANON__: not called CC=1 SCAR=1.2
45 7 ▶ *_FLOAT_PRECISION = sub(){$precision};
Subroutine __ANON__: not called CC=1 SCAR=1.2
46 }
47  
48 7 our @EXPORT = qw(quote_sub unquote_sub quoted_from_sub qsub);
49 7 our @EXPORT_OK = qw(quotify capture_unroll inlinify sanitize_identifier);
50  
51 7 our %QUOTED;
52  
53 7 my %escape;
54 7 if (_BAD_BACKSLASH_ESCAPE) {
55 %escape = (
56 (map +(chr($_) => sprintf '\x%02x', $_), 0 .. 0x31, 0x7f),
57 "\t" => "\\t",
58 "\n" => "\\n",
59 "\r" => "\\r",
60 "\f" => "\\f",
61 "\b" => "\\b",
62 "\a" => "\\a",
63 "\e" => "\\e",
64 (map +($_ => "\\$_"), qw(" \ $ @)),
65 );
66 }
67  
68 sub quotify {
69 2490 ▶ my $value = $_[0];
Subroutine quotify: called CC=21 SCAR=31.8
Pod documented
70 7 ▶ no warnings 'numeric';
Subroutine BEGIN: called CC=1 SCAR=0.0
71 BEGIN {
72 7 ▶ warnings->unimport(qw(experimental::builtin))
Subroutine BEGIN: called CC=1 SCAR=0.0
73 if _CAN_TRACK_BOOLEANS || _CAN_TRACK_NUMBERS;
74 }
75 ! defined $value ? 'undef()'
76 : _CAN_TRACK_BOOLEANS && builtin::is_bool($value) ? (
77 $value ? '(!!1)' : '(!!0)'
78 )
79 # numeric detection
80 : (
81 _CAN_TRACK_NUMBERS
82 ? builtin::created_as_number($value)
83 : (
84 !(_HAVE_IS_UTF8 && utf8::is_utf8($value))
85 && length( (my $dummy = '') & $value )
86 && 0 + $value eq $value
87 )
88 ) ? (
89 $value != $value ? (
90 $value eq (9**9**9*0)
91 ? '(9**9**9*0)' # nan
92 : '(-(9**9**9*0))' # -nan
93 )
94 : $value == 9**9**9 ? '(9**9**9)' # inf
95 : $value == -9**9**9 ? '(-9**9**9)' # -inf
96 : $value == 0 ? (
97 sprintf('%g', $value) eq '-0' ? '-0.0' : '0',
98 )
99 : $value !~ /[e.]/i ? (
100 $value > 0 ? (sprintf '%u', $value)
101 : (sprintf '%d', $value)
102 )
103 : do {
104 153 my $float = $value;
105 153 my $max_factor = int( log( abs($value) ) / log(2) ) - _NVMANTBITS;
106 153 ▶ my $ex_sign = $max_factor > 0 ? 1 : -1;
Branch: 1 branch
BranchTrueFalseTotal
$max_factor > 0 ? : 33 120 153
107 153 FACTOR: for my $ex (0 .. abs($max_factor)) {
108 153 my $num = $value / 2**($ex_sign * $ex);
109 153 for my $precision (_FLOAT_PRECISION .. _FLOAT_PRECISION+2) {
110 267 my $formatted = sprintf '%0.'.$precision.'g', $num;
111 267 ▶ $float = $formatted
Branch: 1 branch
BranchTrueFalseTotal
if $ex == 0 267 0 267
112 if $ex == 0;
113 267 ▶ if ($formatted == $num) {
Branch: 1 branch
BranchTrueFalseTotal
if ($formatted == $num) 153 114 267
114 153 ▶ if ($ex) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ex) 0 153 153
115 0 ▶ $float
Branch: 2 branches
BranchTrueFalseTotal
$ex_sign == 1 ? : 0 0 0
$ex > 53 ? : 0 0 0
116 = $formatted
117 . ($ex_sign == 1 ? '*' : '/')
118 . (
119 $ex > _NVMANTBITS
120 ? "2**$ex"
121 : sprintf('%u', 2**$ex)
122 );
123 }
124 153 last FACTOR;
125 }
126 }
127 0 if (_HAVE_HEX_FLOAT) {
128 51 $float = sprintf '%a', $value;
129 0 last FACTOR;
130 }
131 }
132 102 "$float";
133 }
134 )
135 : !_CAN_TRACK_BOOLEANS && !length($value) && length( (my $dummy2 = '') & $value ) ? '(!!0)' # false
136 2490 ▶ : _BAD_BACKSLASH_ESCAPE && _HAVE_IS_UTF8 && utf8::is_utf8($value) ? do {
Branch: 12 branches
BranchTrueFalseTotal
!defined($value) ? : 3 2487 2490
builtin::is_bool($value) ? : 6 2481 2487
$value ? : 3 3 6
&builtin::created_as_number($value) ? : 477 2004 2481
$value != $value ? : 6 471 477
$value eq sin(9**9**9) ? : 6 0 6
$value == 9**9**9 ? : 6 465 471
$value == -9**9**9 ? : 6 459 465
$value == 0 ? : 9 450 459
sprintf('%g', $value) eq '-0' ? : 0 9 9
!($value =~ /[e.]/i) ? : 297 153 450
$value > 0 ? : 165 132 297
137 $value =~ s/(["\$\@\\[:cntrl:]]|[^\x00-\x7f])/
138 $escape{$1} || sprintf('\x{%x}', ord($1))
139 /ge;
140 qq["$value"];
141 }
142 : _HAVE_PERLSTRING ? B::perlstring($value)
143 : qq["\Q$value\E"];
144 }
145  
146 sub sanitize_identifier {
147 0 ▶ my $name = shift;
Subroutine sanitize_identifier: not called CC=1 SCAR=6.9
Pod documented
148 0 $name =~ s/([_\W])/sprintf('_%x', ord($1))/ge;
149 0 $name;
150 }
151  
152 sub capture_unroll {
153 13 ▶ my ($from, $captures, $indent) = @_;
Subroutine capture_unroll: called CC=2 SCAR=6.9
Pod documented
154 join(
155 '',
156 map {
157 13 ▶ /^([\@\%\$])/
Branch: 1 branch
BranchTrueFalseTotal
/^([\@\%\$])/ or croak("capture key should start with \@, % or \$: $_") 2 24 26
158 or croak "capture key should start with \@, \% or \$: $_";
159 24 (' ' x $indent).qq{my ${_} = ${1}{${from}->{${\quotify $_}}};\n};
160 } keys %$captures
161 );
162 }
163  
164 sub inlinify {
165 8 ▶ my ($code, $args, $extra, $local) = @_;
Subroutine inlinify: called CC=9 SCAR=22.0
Pod documented
166 8 ▶ $args = '()'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args 1 7 8
167 if !defined $args;
168 8 ▶ my $do = 'do { '.($extra||'');
Condition100%2/2
$extra || ''
l!l
71
MC/DC100%1/1
$extra || ''
$extra
Truth table100%2/2
A
A= $extra
Aresult
11
00
169 8 ▶ if ($code =~ s/^(\s*package\s+([a-zA-Z0-9:]+);)//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($code =~ s/^(\s*package\s+([a-zA-Z0-9:]+);)//) 1 7 8
170 1 $do .= $1;
171 }
172 8 ▶ if ($code =~ s{
Branch: 2 branches
BranchTrueFalseTotal
if ($code =~ s/ \A((?:\#\ BEGIN\ quote_sub\ PRELUDE\n.*?\#\ END\ quote_sub\ PRELUDE\n)?\s*) (^\s*) my \s* \(([^)]+)\) \s* = \s* \@_; //msx) { } 3 5 8
elsif ($local or $args ne '@_') { } 3 2 5
173 \A((?:\#\ BEGIN\ quote_sub\ PRELUDE\n.*?\#\ END\ quote_sub\ PRELUDE\n)?\s*)
174 (^\s*) my \s* \(([^)]+)\) \s* = \s* \@_;
175 }{}xms) {
176 3 my ($pre, $indent, $code_args) = ($1, $2, $3);
177 3 $do .= $pre;
178 3 ▶ if ($code_args ne $args) {
Branch: 1 branch
BranchTrueFalseTotal
if ($code_args ne $args) 1 2 3
179 1 $do .= $indent . 'my ('.$code_args.') = ('.$args.'); ';
180 }
181 }
182 ▶ elsif ($local || $args ne '@_') {
Condition100%3/3
$local or $args ne "\@_"
l!l&&r!l&&!r
122
MC/DC100%2/2
$local or $args ne "\@_"
$local $args ne "\@_"
Truth table100%3/3
A or B
A= $localB= $args ne "\@_"
ABresult
1X1
011
000
183 3 ▶ $do .= ($local ? 'local ' : '').'@_ = ('.$args.'); ';
Branch: 1 branch
BranchTrueFalseTotal
$local ? : 1 2 3
184 }
185 8 $do.$code.' }';
186 }
187  
188 sub quote_sub {
189 # HOLY DWIMMERY, BATMAN!
190 # $name => $code => \%captures => \%options
191 # $name => $code => \%captures
192 # $name => $code
193 # $code => \%captures => \%options
194 # $code
195 21 ▶ my $options =
Subroutine quote_sub: called CC=28 SCAR=42.4
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
ref $_[-1] eq 'HASH' && ref $_[-2] eq 'HASH' ? : 5 16 21
Condition100%3/3
ref $_[-1] eq "HASH" and ref $_[-2] eq "HASH"
!ll&&!rl&&r
1515
MC/DC100%2/2
ref $_[-1] eq "HASH" and ref $_[-2] eq "HASH"
ref $_[-1] eq "HASH" ref $_[-2] eq "HASH"
Truth table100%3/3
A and B
A= ref $_[-1] eq "HASH"B= ref $_[-2] eq "HASH"
ABresult
0X0
100
111
196 (ref($_[-1]) eq 'HASH' and ref($_[-2]) eq 'HASH')
197 ? pop
198 : {};
199 21 ▶ my $captures = ref($_[-1]) eq 'HASH' ? pop : undef;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[-1] eq 'HASH' ? : 6 15 21
200 21 ▶ undef($captures) if $captures && !keys %$captures;
Branch: 1 branch
BranchTrueFalseTotal
if $captures and not keys %$captures 5 16 21
Condition100%3/3
$captures and not keys %$captures
!ll&&!rl&&r
1515
MC/DC100%2/2
$captures and not keys %$captures
$captures not keys %$captures
Truth table100%3/3
A and not(B)
A= $capturesB= not keys %$captures
ABresult
0X0
100
111
201 21 my $code = pop;
202 21 my $name = $_[0];
203 21 ▶ if ($name) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name) 1 20 21
204 1 my $subname = $name;
205 1 ▶ my $package = $subname =~ s/(.*)::// ? $1 : caller;
Branch: 1 branch
BranchTrueFalseTotal
$subname =~ s/(.*)::// ? : 1 0 1
206 1 $name = join '::', $package, $subname;
207 1 ▶ croak qq{package name "$package" too long!}
Branch: 1 branch
BranchTrueFalseTotal
if length $package > 252 1 0 1
208 if length $package > 252;
209 0 ▶ croak qq{package name "$package" is not valid!}
Branch: 1 branch
BranchTrueFalseTotal
unless $package =~ /^[^\d\W]\w*(?:::\w+)*$/ 0 0 0
210 unless $package =~ /^[^\d\W]\w*(?:::\w+)*$/;
211 0 ▶ croak qq{sub name "$subname" too long!}
Branch: 1 branch
BranchTrueFalseTotal
if length $subname > 252 0 0 0
212 if length $subname > 252;
213 0 ▶ croak qq{sub name "$subname" is not valid!}
Branch: 1 branch
BranchTrueFalseTotal
unless $subname =~ /^[^\d\W]\w*$/ 0 0 0
214 unless $subname =~ /^[^\d\W]\w*$/;
215 }
216 20 my @caller = caller(0);
217 20 my ($attributes, $file, $line) = @{$options}{qw(attributes file line)};
218 20 ▶ if ($attributes) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attributes) 0 20 20
219 /\A\w+(?:\(.*\))?\z/s || croak "invalid attribute $_"
220 0 ▶ for @$attributes;
Branch: 1 branch
BranchTrueFalseTotal
/\A\w+(?:\(.*\))?\z/s or croak("invalid attribute $_") 0 0 0
221 }
222 my $quoted_info = {
223 name => $name,
224 code => $code,
225 captures => $captures,
226 package => (exists $options->{package} ? $options->{package} : $caller[0]),
227 hints => (exists $options->{hints} ? $options->{hints} : $caller[8]),
228 warning_bits => (exists $options->{warning_bits} ? $options->{warning_bits} : $caller[9]),
229 20 ▶ hintshash => (exists $options->{hintshash} ? $options->{hintshash} : $caller[10]),
Branch: 7 branches
BranchTrueFalseTotal
exists $options->{'package'} ? : 0 20 20
exists $options->{'hints'} ? : 3 17 20
exists $options->{'warning_bits'} ? : 1 19 20
exists $options->{'hintshash'} ? : 3 17 20
$attributes ? : 0 20 20
$file ? : 0 20 20
$line ? : 0 20 20
230 ($attributes ? (attributes => $attributes) : ()),
231 ($file ? (file => $file) : ()),
232 ($line ? (line => $line) : ()),
233 };
234 20 my $unquoted;
235 20 weaken($quoted_info->{unquoted} = \$unquoted);
236 20 ▶ if ($options->{no_defer}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options->{'no_defer'}) { } 0 20 20
237 0 my $fake = \my $var;
238 0 local $QUOTED{$fake} = $quoted_info;
239 0 my $sub = unquote_sub($fake);
240 0 ▶ Sub::Defer::_install_coderef($name, $sub) if $name && !$options->{no_install};
Branch: 1 branch
BranchTrueFalseTotal
if $name and not $options->{"no_install"} 0 0 0
Condition0%0/3
$name and not $options->{"no_install"}
!ll&&!rl&&r
000
MC/DC0%0/2
$name and not $options->{"no_install"}
$name not $options->{"no_install"}
Truth table0%0/3
A and not(B)
A= $nameB= not $options->{"no_install"}
ABresult
0X0
100
111
241 0 return $sub;
242 }
243 else {
244 my $deferred = defer_sub(
245 ($options->{no_install} ? undef : $name),
246 sub {
247 6 ▶ $unquoted if 0;
Subroutine __ANON__: called CC=1 SCAR=0.0
248 6 unquote_sub($quoted_info->{deferred});
249 },
250 {
251 ($attributes ? ( attributes => $attributes ) : ()),
252 20 ▶ ($name ? () : ( package => $quoted_info->{package} )),
Branch: 3 branches
BranchTrueFalseTotal
$options->{'no_install'} ? : 0 20 20
$attributes ? : 0 20 20
$name ? : 0 20 20
253 },
254 );
255 20 weaken($quoted_info->{deferred} = $deferred);
256 20 weaken($QUOTED{$deferred} = $quoted_info);
257 20 return $deferred;
258 }
259 }
260  
261 sub _context {
262 14 ▶ my $info = shift;
Subroutine _context: called CC=7 SCAR=25.7
263 14 ▶ $info->{context} ||= do {
Condition66%2/3
$info->{"context"} ||= do { () = @{$info;}{"package", "hints", "warning_bits", "hintshash", "file", "line"}; $line ||= 1 if $file; my $line_mark = ""; if ($line) { $line_mark = '#line ' . ($line - 1); if ($file) { $line_mark .= qq[ "$file"]; } ; $line_mark .= "\n"; } ; $info->{"context"} = "# BEGIN quote_sub PRELUDE\n" . "package $package;\n" . "BEGIN {\n" . " \$^H = " . quotify($hints) . ";\n" . " \${^WARNING_BITS} = " . quotify($warning_bits) . ";\n" . " %^H = (\n" . join("", map((' ' . quotify($_) . ' => ' . quotify($hintshash->{$_}) . ",\n"), grep((!(ref $hintshash->{$_} && $hintshash->{$_} =~ /\A(?:\w+(?:::\w+)*=)?[A-Z]+\(0x[[0-9a-fA-F]+\)\z/)), keys %$hintshash))) . " );\n" . "}\n" . $line_mark . "# END quote_sub PRELUDE\n" }
l!l&&r!l&&!r
2120
MC/DC0%0/2
$info->{"context"} ||= do { () = @{$info;}{"package", "hints", "warning_bits", "hintshash", "file", "line"}; $line ||= 1 if $file; my $line_mark = ""; if ($line) { $line_mark = '#line ' . ($line - 1); if ($file) { $line_mark .= qq[ "$file"]; } ; $line_mark .= "\n"; } ; $info->{"context"} = "# BEGIN quote_sub PRELUDE\n" . "package $package;\n" . "BEGIN {\n" . " \$^H = " . quotify($hints) . ";\n" . " \${^WARNING_BITS} = " . quotify($warning_bits) . ";\n" . " %^H = (\n" . join("", map((' ' . quotify($_) . ' => ' . quotify($hintshash->{$_}) . ",\n"), grep((!(ref $hintshash->{$_} && $hintshash->{$_} =~ /\A(?:\w+(?:::\w+)*=)?[A-Z]+\(0x[[0-9a-fA-F]+\)\z/)), keys %$hintshash))) . " );\n" . "}\n" . $line_mark . "# END quote_sub PRELUDE\n" }
$info->{"context"} do { () = @{$info;}{"package", "hints", "warning_bits", "hintshash", "file", "line"}; $line ||= 1 if $file; my $line_mark = ""; if ($line) { $line_mark = '#line ' . ($line - 1); if ($file) { $line_mark .= qq[ "$file"]; } ; $line_mark .= "\n"; } ; $info->{"context"} = "# BEGIN quote_sub PRELUDE\n" . "package $package;\n" . "BEGIN {\n" . " \$^H = " . quotify($hints) . ";\n" . " \${^WARNING_BITS} = " . quotify($warning_bits) . ";\n" . " %^H = (\n" . join("", map((' ' . quotify($_) . ' => ' . quotify($hintshash->{$_}) . ",\n"), grep((!(ref $hintshash->{$_} && $hintshash->{$_} =~ /\A(?:\w+(?:::\w+)*=)?[A-Z]+\(0x[[0-9a-fA-F]+\)\z/)), keys %$hintshash))) . " );\n" . "}\n" . $line_mark . "# END quote_sub PRELUDE\n" }
Truth table66%2/3
A ||= B
A= $info->{"context"}B= do { () = @{$info;}{"package", "hints", "warning_bits", "hintshash", "file", "line"}; $line ||= 1 if $file; my $line_mark = ""; if ($line) { $line_mark = '#line ' . ($line - 1); if ($file) { $line_mark .= qq[ "$file"]; } ; $line_mark .= "\n"; } ; $info->{"context"} = "# BEGIN quote_sub PRELUDE\n" . "package $package;\n" . "BEGIN {\n" . " \$^H = " . quotify($hints) . ";\n" . " \${^WARNING_BITS} = " . quotify($warning_bits) . ";\n" . " %^H = (\n" . join("", map((' ' . quotify($_) . ' => ' . quotify($hintshash->{$_}) . ",\n"), grep((!(ref $hintshash->{$_} && $hintshash->{$_} =~ /\A(?:\w+(?:::\w+)*=)?[A-Z]+\(0x[[0-9a-fA-F]+\)\z/)), keys %$hintshash))) . " );\n" . "}\n" . $line_mark . "# END quote_sub PRELUDE\n" }
ABresult
1X1
011
000
264 my ($package, $hints, $warning_bits, $hintshash, $file, $line)
265 12 = @{$info}{qw(package hints warning_bits hintshash file line)};
266  
267 12 ▶ $line ||= 1
Branch: 1 branch
BranchTrueFalseTotal
if $file 0 12 12
Condition0%0/2
$line ||= 1
l!l
00
MC/DC0%0/1
$line ||= 1
$line
Truth table0%0/2
A
A= $line
Aresult
11
00
268 if $file;
269  
270 12 my $line_mark = '';
271 12 ▶ if ($line) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line) 0 12 12
272 0 $line_mark = "#line ".($line-1);
273 0 ▶ if ($file) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file) 0 0 0
274 0 $line_mark .= qq{ "$file"};
275 }
276 0 $line_mark .= "\n";
277 }
278  
279 $info->{context}
280 ="# BEGIN quote_sub PRELUDE\n"
281 ."package $package;\n"
282 ."BEGIN {\n"
283 ." \$^H = ".quotify($hints).";\n"
284 ." \${^WARNING_BITS} = ".quotify($warning_bits).";\n"
285 ." \%^H = (\n"
286 . join('', map
287 " ".quotify($_)." => ".quotify($hintshash->{$_}).",\n",
288 12 ▶ grep !(ref $hintshash->{$_} && $hintshash->{$_} =~ /\A(?:\w+(?:::\w+)*=)?[A-Z]+\(0x[[0-9a-fA-F]+\)\z/),
Condition33%1/3
ref $hintshash->{$_} && $hintshash->{$_} =~ /\A(?:\w+(?:::\w+)*=)?[A-Z]+\(0x[[0-9a-fA-F]+\)\z/
!ll&&!rl&&r
300
MC/DC0%0/2
ref $hintshash->{$_} && $hintshash->{$_} =~ /\A(?:\w+(?:::\w+)*=)?[A-Z]+\(0x[[0-9a-fA-F]+\)\z/
ref $hintshash->{$_} $hintshash->{$_} =~ /\A(?:\w+(?:::\w+)*=)?[A-Z]+\(0x[[0-9a-fA-F]+\)\z/
Truth table33%1/3
A && B
A= ref $hintshash->{$_}B= $hintshash->{$_} =~ /\A(?:\w+(?:::\w+)*=)?[A-Z]+\(0x[[0-9a-fA-F]+\)\z/
ABresult
0X0
100
111
289 keys %$hintshash)
290 ." );\n"
291 ."}\n"
292 .$line_mark
293 ."# END quote_sub PRELUDE\n";
294 };
295 }
296  
297 sub quoted_from_sub {
298 6 ▶ my ($sub) = @_;
Subroutine quoted_from_sub: called CC=8 SCAR=22.7
Pod documented
299 6 ▶ my $quoted_info = $QUOTED{$sub||''} or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $quoted_info = $Sub::Quote::QUOTED{$sub or ""} or return undef 2 4 6
Condition50%1/2
$sub || ''
l!l
60
MC/DC0%0/1
$sub || ''
$sub
Truth table50%1/2
A
A= $sub
Aresult
11
00
300 my ($name, $code, $captures, $unquoted, $deferred)
301 4 = @{$quoted_info}{qw(name code captures unquoted deferred)};
302 4 $code = _context($quoted_info) . $code;
303 4 ▶ $unquoted &&= $$unquoted;
Condition66%2/3
$unquoted &&= $$unquoted
!ll&&!rl&&r
022
MC/DC50%1/2
$unquoted &&= $$unquoted
$unquoted $$unquoted
Truth table66%2/3
A &&= B
A= $unquotedB= $$unquoted
ABresult
0X0
100
111
304 4 ▶ if (($deferred && $deferred eq $sub)
Branch: 1 branch
BranchTrueFalseTotal
if ($deferred and $deferred eq $sub or $unquoted and $unquoted eq $sub) 4 0 4
Condition55%5/9
$deferred and $deferred eq $sub or $unquoted and $unquoted eq $sub
l!l&&r!l&&!r
310
$deferred and $deferred eq $sub
!ll&&!rl&&r
013
$unquoted and $unquoted eq $sub
!ll&&!rl&&r
001
MC/DC0%0/4
$deferred and $deferred eq $sub or $unquoted and $unquoted eq $sub
$deferred $deferred eq $sub $unquoted $unquoted eq $sub
Truth table28%2/7
A and B or C and D
A= $deferredB= $deferred eq $subC= $unquotedD= $unquoted eq $sub
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
305 || ($unquoted && $unquoted eq $sub)) {
306 4 return [ $name, $code, $captures, $unquoted, $deferred ];
307 }
308 0 return undef;
309 }
310  
311 sub unquote_sub {
312 11 ▶ my ($sub) = @_;
Subroutine unquote_sub: called CC=20 SCAR=40.0
Pod documented
313 11 ▶ my $quoted_info = $QUOTED{$sub} or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $quoted_info = $Sub::Quote::QUOTED{$sub} or return undef 0 11 11
314 11 my $unquoted = $quoted_info->{unquoted};
315 11 ▶ unless ($unquoted && $$unquoted) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($unquoted and $$unquoted) 11 0 11
Condition33%1/3
$unquoted and $$unquoted
!ll&&!rl&&r
0110
MC/DC0%0/2
$unquoted and $$unquoted
$unquoted $$unquoted
Truth table33%1/3
A and B
A= $unquotedB= $$unquoted
ABresult
0X0
100
111
316 my ($name, $code, $captures, $package, $attributes)
317 11 = @{$quoted_info}{qw(name code captures package attributes)};
318  
319 11 ▶ ($package, $name) = $name =~ /(.*)::(.*)/
Branch: 1 branch
BranchTrueFalseTotal
if $name 0 11 11
320 if $name;
321  
322 11 ▶ my %captures = $captures ? %$captures : ();
Branch: 1 branch
BranchTrueFalseTotal
$captures ? : 1 10 11
323 11 $captures{'$_UNQUOTED'} = \$unquoted;
324 11 $captures{'$_QUOTED'} = \$quoted_info;
325  
326 11 ▶ my $make_sub
Branch: 3 branches
BranchTrueFalseTotal
$name ? : 0 10 10
$attributes ? : 0 10 10
$name ? : 0 10 10
327 = "{\n"
328 . capture_unroll("\$_[1]", \%captures, 2)
329 . " package ${package};\n"
330 . (
331 $name
332 # disable the 'variable $x will not stay shared' warning since
333 # we're not letting it escape from this scope anyway so there's
334 # nothing trying to share it
335 ? " no warnings 'closure';\n sub ${name} "
336 : " \$\$_UNQUOTED = sub "
337 )
338 . ($attributes ? join('', map ":$_ ", @$attributes) : '') . "{\n"
339 . " (\$_QUOTED,\$_UNQUOTED) if 0;\n"
340 . _context($quoted_info)
341 . $code
342 . " }".($name ? "\n \$\$_UNQUOTED = \\&${name}" : '') . ";\n"
343 . "}\n"
344 . "1;\n";
345 10 ▶ if (my $debug = $ENV{SUB_QUOTE_DEBUG}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $debug = $ENV{"SUB_QUOTE_DEBUG"}) 0 10 10
346 0 ▶ if ($debug =~ m{^([^\W\d]\w*(?:::\w+)*(?:::)?)$}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($debug =~ /^([^\W\d]\w*(?:::\w+)*(?:::)?)$/) { } 0 0 0
elsif ($debug =~ m[\A/(.*)/\z]s) { } 0 0 0
347 0 my $filter = $1;
348 0 ▶ my $match
Branch: 2 branches
BranchTrueFalseTotal
$filter =~ /::$/ ? : 0 0 0
$filter =~ /::/ ? : 0 0 0
Condition0%0/4
$name || '__ANON__'
l!l
00
$name or "__ANON__"
l!l
00
MC/DC0%0/1
$name || '__ANON__'
$name
MC/DC0%0/1
$name or "__ANON__"
$name
Truth table0%0/2
A
A= $name
Aresult
11
00
Truth table0%0/2
A
A= $name
Aresult
11
00
349 = $filter =~ /::$/ ? $package.'::'
350 : $filter =~ /::/ ? $package.'::'.($name||'__ANON__')
351 : ($name||'__ANON__');
352 0 ▶ warn $make_sub
Branch: 1 branch
BranchTrueFalseTotal
if $match eq $filter 0 0 0
353 if $match eq $filter;
354 }
355 elsif ($debug =~ m{\A/(.*)/\z}s) {
356 0 my $filter = $1;
357 0 ▶ warn $make_sub
Branch: 1 branch
BranchTrueFalseTotal
if $code =~ /$filter/ 0 0 0
358 if $code =~ $filter;
359 }
360 else {
361 0 warn $make_sub;
362 }
363 }
364 {
365 7 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
366 10 ▶ local *{"${package}::${name}"} if $name;
Branch: 1 branch
BranchTrueFalseTotal
if $name 0 10 10
367 10 my ($success, $e);
368 {
369 10 local $@;
370 10 $success = _clean_eval($make_sub, \%captures);
371 10 $e = $@;
372 }
373 10 ▶ unless ($success) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($success) 1 9 10
374 1 my $space = length($make_sub =~ tr/\n//);
375 1 my $line = 0;
376 1 $make_sub =~ s/^/sprintf "%${space}d: ", ++$line/emg;
377 1 croak "Eval went very, very wrong:\n\n${make_sub}\n\n$e";
378 }
379 9 weaken($QUOTED{$$unquoted} = $quoted_info);
380 }
381 }
382 9 $$unquoted;
383 }
384  
385 sub qsub ($) {
386 0 ▶ goto &quote_sub;
Subroutine qsub: not called CC=1 SCAR=6.9
Pod documented
387 }
388  
389 sub CLONE {
390 5 ▶ my @quoted = map { defined $_ ? (
Subroutine CLONE: called CC=6 SCAR=17.9
391 4 ▶ $_->{unquoted} && ${$_->{unquoted}} ? (${ $_->{unquoted} } => $_) : (),
Branch: 1 branch
BranchTrueFalseTotal
$_->{'deferred'} ? : 4 1 5
392 8 ▶ $_->{deferred} ? ($_->{deferred} => $_) : (),
Branch: 2 branches
BranchTrueFalseTotal
defined $_ ? : 5 3 8
$_->{'unquoted'} && ${$_->{'unquoted'};} ? : 2 3 5
Condition100%3/3
$_->{"unquoted"} and ${$_->{"unquoted"};}
!ll&&!rl&&r
122
MC/DC100%2/2
$_->{"unquoted"} and ${$_->{"unquoted"};}
$_->{"unquoted"} ${$_->{"unquoted"};}
Truth table100%3/3
A and B
A= $_->{"unquoted"}B= ${$_->{"unquoted"};}
ABresult
0X0
100
111
393 ) : () } values %QUOTED;
394 5 %QUOTED = @quoted;
395 5 weaken($_) for values %QUOTED;
396 }
397  
398 7 1;
399 __END__
↑ Summary Defer.pm »