blib/lib/Eval/TypeTiny/CodeAccumulator.pm

filter: Statementstmt 97.4% 75 / 77 Branchbran 70.0% 7 / 10 Conditioncond 50.0% 6 / 12 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 100% 20 / 20 Podpod 100% 14 / 14 totaltotal 87.7% 122 / 139 CC 13 SCAR 10.0
CC
13
Cov
89%
new
7.3
add_placeholder
3.0
BEGIN
2.5
CRAP 2.7
« blib/lib/Type/Coercion/Union.pm ↑ Summary lib/Types/Standard/Tied.pm »
1 package Eval::TypeTiny::CodeAccumulator;
2  
3 62 ▶use 5.008001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 62 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 62 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 62 ▶BEGIN {
Subroutine BEGIN: called CC=2 SCAR=9.2
8 0 ▶ if ( $] < 5.010 ) { require Devel::TypeTiny::Perl58Compat }
Branch: 1 branch
BranchTrueFalseTotal
if ($] < "5.01") 0 62 62
9 }
10  
11 62 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
12 62 $Eval::TypeTiny::CodeAccumulator::AUTHORITY = 'cpan:TOBYINK';
13 62 $Eval::TypeTiny::CodeAccumulator::VERSION = '2.010001';
14 }
15  
16 62 $Eval::TypeTiny::CodeAccumulator::VERSION =~ tr/_//d;
17  
18 394 ▶sub new {
Subroutine new: called CC=6 SCAR=19.9
Pod documented
19 394 my $class = shift;
20  
21 0 ▶ my %self = @_ == 1 ? %{$_[0]} : @_;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 ? : 0 394 394
22 394 ▶ $self{env} ||= {};
Condition50%1/2
$self{"env"} ||= {}
l!l
0394
MC/DC0%0/1
$self{"env"} ||= {}
$self{"env"}
Truth table50%1/2
A
A= $self{"env"}
Aresult
11
00
23 394 ▶ $self{code} ||= [];
Condition50%1/2
$self{"code"} ||= []
l!l
0394
MC/DC0%0/1
$self{"code"} ||= []
$self{"code"}
Truth table50%1/2
A
A= $self{"code"}
Aresult
11
00
24 394 ▶ $self{placeholders} ||= {};
Condition50%1/2
$self{"placeholders"} ||= {}
l!l
0394
MC/DC0%0/1
$self{"placeholders"} ||= {}
$self{"placeholders"}
Truth table50%1/2
A
A= $self{"placeholders"}
Aresult
11
00
25 394 ▶ $self{indent} ||= '';
Condition50%1/2
$self{"indent"} ||= ""
l!l
0394
MC/DC0%0/1
$self{"indent"} ||= ""
$self{"indent"}
Truth table50%1/2
A
A= $self{"indent"}
Aresult
11
00
26  
27 394 bless \%self, $class;
28 }
29  
30 454 ▶sub code { join( "\n", @{ $_[0]{code} } ) }
Subroutine code: called CC=1 SCAR=0.0
Pod documented
31 326 ▶sub description { $_[0]{description} }
Subroutine description: called CC=1 SCAR=0.0
Pod documented
32 326 ▶sub env { $_[0]{env} }
Subroutine env: called CC=1 SCAR=0.0
Pod documented
33  
34 7333 ▶sub add_line {
Subroutine add_line: called CC=1 SCAR=0.0
Pod documented
35 7333 my $self = shift;
36 7333 my $indent = $self->{indent};
37  
38 7333 push @{ $self->{code} }, map { $indent . $_ } map { split /\n/ } @_;
39  
40 7333 $self;
41 }
42  
43 103 ▶sub addf {
Subroutine addf: called CC=1 SCAR=0.0
Pod documented
44 103 my $self = shift;
45 103 my $fmt = shift;
46 103 $self->add_line( sprintf $fmt, @_ );
47 }
48  
49 121 ▶sub increase_indent {
Subroutine increase_indent: called CC=1 SCAR=0.0
Pod documented
50 121 $_[0]{indent} .= "\t";
51 121 $_[0];
52 }
53  
54 121 ▶sub decrease_indent {
Subroutine decrease_indent: called CC=1 SCAR=0.0
Pod documented
55 121 $_[0]{indent} =~ s/\t$//;
56 121 $_[0];
57 }
58  
59 2026 ▶sub add_gap {
Subroutine add_gap: called CC=1 SCAR=0.0
Pod documented
60 2026 push @{ $_[0]{code} }, '';
61 }
62  
63 4 ▶sub add_placeholder {
Subroutine add_placeholder: called CC=3 SCAR=11.0
Pod documented
64 4 my ( $self, $for ) = ( shift, @_ );
65 4 ▶ my $indent = $self->{indent} || '';
Condition50%1/2
$self->{'indent'} || ''
l!l
40
MC/DC0%0/1
$self->{'indent'} || ''
$self->{'indent'}
Truth table50%1/2
A
A= $self->{'indent'}
Aresult
11
00
66  
67 $self->{placeholders}{$for} = [
68 4 scalar( @{ $self->{code} } ),
69 $self->{indent},
70 4 ];
71 4 push @{ $self->{code} }, "$indent# placeholder [ $for ]";
72  
73 4 ▶ if ( defined wantarray ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined wantarray) 2 2 4
74 2 ▶ return sub { $self->fill_placeholder( $for, @_ ) };
Subroutine __ANON__: called CC=1 SCAR=0.0
75 }
76 }
77  
78 2 ▶sub fill_placeholder {
Subroutine fill_placeholder: called CC=2 SCAR=6.9
Pod documented
79 2 my ( $self, $for, @lines ) = ( shift, @_ );
80  
81 2 ▶ my ( $line_number, $indent ) = @{ delete $self->{placeholders}{$for} or die };
Condition50%1/2
delete $self->{'placeholders'}{$for} || die()
l!l
20
MC/DC0%0/1
delete $self->{'placeholders'}{$for} || die()
delete $self->{'placeholders'}{$for}
Truth table50%1/2
A
A= delete $self->{'placeholders'}{$for}
Aresult
11
00
82 2 my @indented_lines = map { $indent . $_ } map { split /\n/ } @lines;
83 2 splice( @{ $self->{code} }, $line_number, 1, @indented_lines );
84  
85 2 $self;
86 }
87  
88 280 ▶sub add_variable {
Subroutine add_variable: called CC=2 SCAR=6.9
Pod documented
89 280 my ( $self, $suggested_name, $reference ) = ( shift, @_ );
90
91 280 my $actual_name = $suggested_name;
92 280 my $i = 1;
93 280 ▶ while ( exists $self->{env}{$actual_name} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"env"}{$actual_name}) 67 280 347
94 67 $actual_name = sprintf '%s_%d', $suggested_name, ++$i;
95 }
96  
97 280 $self->{env}{$actual_name} = $reference;
98  
99 280 $actual_name;
100 }
101  
102 326 ▶sub finalize {
Subroutine finalize: called CC=2 SCAR=6.9
Pod documented
103 326 my $self = shift;
104  
105 326 for my $p ( values %{ $self->{placeholders} } ) {
106 2 splice( @{ $self->{code} }, $p->[0], 1 );
107 }
108  
109 326 $self;
110 }
111  
112 326 ▶sub compile {
Subroutine compile: called CC=2 SCAR=7.0
Pod documented
113 326 my ( $self, %opts ) = ( shift, @_ );
114  
115 326 ▶ $self->{finalized}++ or $self->finalize();
Branch: 1 branch
BranchTrueFalseTotal
$self->{"finalized"}++ or $self->finalize 0 326 326
116  
117 326 require Eval::TypeTiny;
118 326 return Eval::TypeTiny::eval_closure(
119 description => $self->description,
120 %opts,
121 source => $self->code,
122 environment => $self->env,
123 );
124 }
125  
126 62 1;
127  
128 __END__
« blib/lib/Type/Coercion/Union.pm ↑ Summary lib/Types/Standard/Tied.pm »