TT2.pm

filter: Statementstmt 67.5% 27 / 40 Branchbran 33.3% 2 / 6 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 88.8% 8 / 9 Podpod 100% 3 / 3 totaltotal 67.2% 41 / 61 CC 6 SCAR 11.9
CC
6
Cov
62%
transpile
6.0
transpile_file
6.0
new
2.1
CRAP 3.3
« TT2/Filters.pm ↑ Summary
1 package Jinja2::TT2;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use v5.20;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use Jinja2::TT2::Tokenizer;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Jinja2::TT2::Parser;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Jinja2::TT2::Emitter;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 our $VERSION = '0.01';
12  
13 1 ▶sub new {
Subroutine new: called CC=2 SCAR=7.2
Pod documented
14 1 my ($class, %opts) = @_;
15 return bless {
16 tokenizer => Jinja2::TT2::Tokenizer->new(),
17 parser => Jinja2::TT2::Parser->new(),
18 emitter => Jinja2::TT2::Emitter->new(%opts),
19 1 ▶ debug => $opts{debug} // 0,
Condition50%1/2
$opts{"debug"} // 0
l!l
01
MC/DC0%0/1
$opts{"debug"} // 0
$opts{"debug"}
Truth table50%1/2
A
A= $opts{"debug"}
Aresult
11
00
20 }, $class;
21 }
22  
23 43 ▶sub transpile {
Subroutine transpile: called CC=4 SCAR=17.9
Pod documented
24 43 my ($self, $template) = @_;
25  
26 # Step 1: Tokenize
27 43 my @tokens = $self->{tokenizer}->tokenize($template);
28  
29 43 ▶ if ($self->{debug}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"debug"}) 0 43 43
30 0 say STDERR "=== TOKENS ===";
31 0 for my $tok (@tokens) {
32 0 say STDERR " [$tok->{type}] '$tok->{value}'";
33 }
34 }
35  
36 # Step 2: Parse into AST
37 43 my $ast = $self->{parser}->parse(\@tokens);
38  
39 43 ▶ if ($self->{debug}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"debug"}) 0 43 43
40 0 require Data::Dumper;
41 0 say STDERR "=== AST ===";
42 0 say STDERR Data::Dumper::Dumper($ast);
43 }
44  
45 # Step 3: Emit TT2
46 43 return $self->{emitter}->emit($ast);
47 }
48  
49 0 ▶sub transpile_file {
Subroutine transpile_file: not called CC=2 SCAR=17.9
Pod documented
50 0 my ($self, $filename) = @_;
51  
52 0 ▶ open my $fh, '<:encoding(UTF-8)', $filename
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<:encoding(UTF-8)", $filename or die "Cannot open '${filename}': $!" 0 0 0
53 or die "Cannot open '$filename': $!";
54 0 my $template = do { local $/; <$fh> };
55 0 close $fh;
56  
57 0 return $self->transpile($template);
58 }
59  
60 1 1;
61  
62 __END__
« TT2/Filters.pm ↑ Summary