| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
MC/DC0%0/2
$outenc ||= $enc
$outenc
$enc
Truth table66%2/3
A ||= B
A= $outencB= $enc
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 62 | 9 | DBG "Getting template $file from cache"; | |||||||||||||||||||||||||||
| 63 | 9 | ▶ | return wantarray ? @{$cache{$file}} : $cache{$file}[0]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 37 | ▶ | open($fh, '<', $file) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition66%2/3
substr($text, 0, 250) =~ /\[#[^#]*$Config::Maker::fenc([[:alnum:]_-]+)/ or substr($text, -250) =~ /\[#[^#]*$Config::Maker::fenc([[:alnum:]_-]+)/
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:]_-]+)/
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 9 | 1; | |||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | __END__ | ||||||||||||||||||||||||||||