Maker/Driver.pm

filter: Statementstmt 98.6% 74 / 75 Branchbran 75.0% 15 / 20 Conditioncond 66.6% 4 / 6 MC/DCmcdc 25.0% 1 / 4 Subroutinesub 100% 14 / 14 Podpod 0.0% 0 / 3 totaltotal 88.5% 108 / 122 CC 14 SCAR 13.9
CC
14
Cov
92%
load
8.1
apply
4.2
process
4.0
CRAP 4.0
« Maker/Encode.pm ↑ Summary Maker/Tee.pm »
1 package Config::Maker::Driver;
2  
3 9 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 9 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 9 ▶use Parse::RecDescent;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 9 ▶use Config::Maker;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 9 ▶use Config::Maker::Encode;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 9 ▶use Config::Maker::Option;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 9 ▶use Config::Maker::Path;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 9 ▶use Config::Maker::Tee;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 9 my $parser = $Config::Maker::parser;
17  
18 209 ▶sub apply {
Subroutine apply: called CC=4 SCAR=14.3
Pod undocumented
19 209 for my $e (@_) {
20 497 ▶ if(ref $e eq 'CODE') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $e eq 'CODE') { } 247 250 497
elsif (ref $e) { } 0 250 250
21 247 $e->();
22 } elsif(ref $e) {
23 0 $e->do();
24 } else {
25 250 print $e;
26 }
27 }
28 }
29  
30 45 ▶sub process {
Subroutine process: called CC=4 SCAR=13.9
Pod undocumented
31 45 my ($class, $file, $config, $outfh, $outenc) = @_;
32  
33 45 ▶ croak "Invalid config!"
Branch: 1 branch
BranchTrueFalseTotal
unless UNIVERSAL::isa($config, "Config::Maker::Config") 0 45 45
34 unless UNIVERSAL::isa($config, 'Config::Maker::Config');
35  
36 45 local $Config::Maker::Eval::config = $config;
37 45 local $_ = $config->{root};
38  
39 45 my ($code, $enc) = $class->load($file);
40
41 45 ▶ $outenc ||= $enc;
Condition66%2/3
$outenc ||= $enc
l!l&&r!l&&!r
1440
MC/DC0%0/2
$outenc ||= $enc
$outenc $enc
Truth table66%2/3
A ||= B
A= $outencB= $enc
ABresult
1X1
011
000
42 45 encmode($outfh, $outenc);
43  
44 45 LOG("Processing the template with output in $outenc");
45 45 my $old = select;
46 45 select $outfh;
47 45 eval { $code->() };
48 45 select $old;
49 45 ▶ die $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 2 43 45
50 }
51  
52 9 our %cache;
53  
54 46 ▶sub load {
Subroutine load: called CC=8 SCAR=20.9
Pod undocumented
55 46 my ($class, $file) = @_;
56 46 my ($fh, $text);
57 46 my $enc = 'system';
58  
59 46 $file = Config::Maker::locate($file);
60  
61 46 ▶ if($cache{$file}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Config::Maker::Driver::cache{$file}) 9 37 46
62 9 DBG "Getting template $file from cache";
63 9 ▶ return wantarray ? @{$cache{$file}} : $cache{$file}[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 9 0 9
64 }
65  
66 37 ▶ open($fh, '<', $file)
Branch: 1 branch
BranchTrueFalseTotal
open $fh, "<", $file or croak("Failed to open ${file}: $!") 37 0 37
67 or croak "Failed to open $file: $!";
68 {
69 37 local $/;
70 37 $text = <$fh>;
71 }
72 37 close $fh;
73  
74 37 ▶ if((substr($text, 0, 250) =~ /\[#[^#]*$Config::Maker::fenc([[:alnum:]_-]+)/) ||
Branch: 1 branch
BranchTrueFalseTotal
if (substr($text, 0, 250) =~ /\[#[^#]*$Config::Maker::fenc([[:alnum:]_-]+)/ or substr($text, -250) =~ /\[#[^#]*$Config::Maker::fenc([[:alnum:]_-]+)/) 1 36 37
Condition66%2/3
substr($text, 0, 250) =~ /\[#[^#]*$Config::Maker::fenc([[:alnum:]_-]+)/ or substr($text, -250) =~ /\[#[^#]*$Config::Maker::fenc([[:alnum:]_-]+)/
l!l&&r!l&&!r
1036
MC/DC50%1/2
substr($text, 0, 250) =~ /\[#[^#]*$Config::Maker::fenc([[:alnum:]_-]+)/ or substr($text, -250) =~ /\[#[^#]*$Config::Maker::fenc([[:alnum:]_-]+)/
substr($text, 0, 250) =~ /\[#[^#]*$Config::Maker::fenc([[:alnum:]_-]+)/ substr($text, -250) =~ /\[#[^#]*$Config::Maker::fenc([[:alnum:]_-]+)/
Truth table66%2/3
A or B
A= substr($text, 0, 250) =~ /\[#[^#]*$Config::Maker::fenc([[:alnum:]_-]+)/B= substr($text, -250) =~ /\[#[^#]*$Config::Maker::fenc([[:alnum:]_-]+)/
ABresult
1X1
011
000
75 (substr($text, -250) =~ /\[#[^#]*$Config::Maker::fenc([[:alnum:]_-]+)/)) {
76 1 $enc = $1;
77 }
78 37 $text = decode($enc, $text);
79  
80 37 LOG("Loading template $file encoded $enc");
81 37 my $out = $parser->template($text);
82 37 ▶ croak "Template file $file contained errors"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $out 0 37 37
83 unless defined $out;
84  
85 37 ▶ my $code = sub { apply(@$out); };
Subroutine __ANON__: called CC=1 SCAR=0.0
86 37 $cache{$file} = [$code, $enc];
87 37 ▶ return wantarray ? ($code, $enc) : $code;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 36 1 37
88 }
89  
90 9 1;
91  
92 __END__
« Maker/Encode.pm ↑ Summary Maker/Tee.pm »