blib/lib/Compile/Generators.pm

filter: Statementstmt 100% 34 / 34 Branchbran 90.0% 9 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 2 totaltotal 94.2% 49 / 52 CC 6 SCAR 9.7
CC
6
Cov
98%
compile
4.0
pmc_compile
3.0
BEGIN
1.0
CRAP 2.6
↑ Summary
1 package Compile::Generators;
2 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use 5.006001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 our $VERSION = '0.11';
6  
7 3 ▶use Module::Compile -base;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 3 my $label = 'GENAAAA';
10  
11 3 ▶sub pmc_compile {
Subroutine pmc_compile: called CC=3 SCAR=11.0
Pod undocumented
12 3 my ($class, $input) = @_;
13 3 my $output;
14 3 ▶ while ($output = $class->compile($input)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($output = $class->compile($input)) 7 0 7
15 7 ▶ last if $output eq $input;
Branch: 1 branch
BranchTrueFalseTotal
if $output eq $input 3 4 7
16 4 $input = $output;
17 }
18 3 return $output;
19 }
20  
21 7 ▶sub compile {
Subroutine compile: called CC=4 SCAR=13.9
Pod undocumented
22 7 my ($class, $source) = @_;
23 7 ▶ return $source unless $source =~
Branch: 1 branch
BranchTrueFalseTotal
unless $source =~ /^(sub .*):generator (.*\n)((?s:.*?))(^\}.*\n)/m 3 4 7
24 /^(sub .*):generator (.*\n)((?s:.*?))(^\}.*\n)/m;
25 4 my $start = "$1$2";
26 4 my $end = $4;
27 4 my ($static, $dynamic) = split /^\s*\n/m, $3, 2;
28 4 ▶ if (not defined $dynamic) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $dynamic) 3 1 4
29 3 $dynamic = $static;
30 3 $static = '';
31 }
32 4 ▶ while ($dynamic =~ s/^(\s*yield\s*(.*))/#$1\n \$__GEN_STATE__ = '$label'; return $2; ${label}:/m) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dynamic =~ s/^(\s*yield\s*(.*))/#$1\n \$__GEN_STATE__ = '${label}'; return $2; ${label}:/m) 8 4 12
33 8 $label++;
34 }
35 # $dynamic =~ s/^/ /mg;
36
37 4 my $code = <<"_";
38 ${start} my \$__GEN_STATE__ = undef;
39 ${static}
40 return sub {
41 goto \$__GEN_STATE__ if defined \$__GEN_STATE__;
42 ${dynamic}
43 \$__GEN_STATE__ = '$label';
44 ${label}:
45 return;
46 }
47 ${end}
48 _
49 4 $label++;
50 4 $source =~ s/^sub .*:generator .*\n(?s:.*?)^\}.*\n/$code/m;
51 4 return $source;
52 }
53  
54 3 1;
55  
56 __DATA__
↑ Summary