blib/lib/Regexp/DeferredExecution.pm

filter: Statementstmt 74.0% 20 / 27 Branchbran 16.6% 1 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 1 totaltotal 68.2% 28 / 41 CC 4 SCAR 17.0
CC
4
Cov
64%
convert
12.2
BEGIN
1.0
BEGIN
1.0
CRAP 5.5
↑ Summary
1 package Regexp::DeferredExecution;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 $VERSION = '0.05';
7  
8 1 ▶use Text::Balanced qw( extract_multiple
Subroutine BEGIN: called CC=1 SCAR=0.0
9 extract_codeblock
10 1 );
11  
12 1 ▶use overload;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 4 ▶sub import {
Subroutine import: called CC=1 SCAR=0.0
15 4 shift;
16 4 overload::constant('qr' => \&convert);
17 }
18  
19 2 ▶sub unimport {
Subroutine unimport: called CC=1 SCAR=0.0
20 2 shift;
21 2 overload::remove_constant('qr');
22 }
23  
24 10 ▶sub convert {
Subroutine convert: called CC=4 SCAR=25.0
Pod undocumented
25  
26 10 my $re = shift;
27  
28 10 ▶ return $re unless $re =~ m/\(\?\{/; # no need to alter this one.
Branch: 1 branch
BranchTrueFalseTotal
unless $re =~ /\(\?\{/ 10 0 10
29  
30 0 my @chunks =
31 extract_multiple($re,
32 [ qr/\(\? # '(?' (escaped)
33 (?=\{) # followed by '{' (lookahead)
34 /x,
35 \&extract_codeblock
36 ]
37 );
38  
39 0 ▶ for (my $i = 1 ; $i < @chunks ; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @chunks) 0 0 0
40 # wrap all code into a closure and push onto the stack:
41 0 ▶ if ($chunks[$i-1] eq "(?") {
Branch: 1 branch
BranchTrueFalseTotal
if ($chunks[$i - 1] eq "(?") 0 0 0
42 0 $chunks[$i] =~ s/\A \{
43 (.*)
44 \} \Z
45 /{
46 local \@Regexp::DeferredExecution::c = \@Regexp::DeferredExecution::c;
47 push \@Regexp::DeferredExecution::c, [\$^N, q{$1}];
48 }/msx;
49 }
50 }
51  
52 0 $re = join("", @chunks);
53  
54 # install the stack storage and execution code:
55 0 $re = "(?{
56 local \@Regexp::DeferredExecution::c = ();
57 })$re(?{
58 for (\@Regexp::DeferredExecution::c) {
59 \$^N = \$\$_[0];
60 eval \$\$_[1];
61 }
62 })";
63  
64 0 return $re;
65 }
66  
67 1 1;
68 __END__
↑ Summary