| 1 | #============================================================= -*-perl-*- | ||||||||||||||||||||||||||||||||||||||
| 2 | # | ||||||||||||||||||||||||||||||||||||||
| 3 | # Template | ||||||||||||||||||||||||||||||||||||||
| 4 | # | ||||||||||||||||||||||||||||||||||||||
| 5 | # DESCRIPTION | ||||||||||||||||||||||||||||||||||||||
| 6 | # Module implementing a simple, user-oriented front-end to the Template | ||||||||||||||||||||||||||||||||||||||
| 7 | # Toolkit. | ||||||||||||||||||||||||||||||||||||||
| 8 | # | ||||||||||||||||||||||||||||||||||||||
| 9 | # AUTHOR | ||||||||||||||||||||||||||||||||||||||
| 10 | # Andy Wardley <abw@wardley.org> | ||||||||||||||||||||||||||||||||||||||
| 11 | # | ||||||||||||||||||||||||||||||||||||||
| 12 | # COPYRIGHT | ||||||||||||||||||||||||||||||||||||||
| 13 | # Copyright (C) 1996-2022 Andy Wardley. All Rights Reserved. | ||||||||||||||||||||||||||||||||||||||
| 14 | # | ||||||||||||||||||||||||||||||||||||||
| 15 | # This module is free software; you can redistribute it and/or | ||||||||||||||||||||||||||||||||||||||
| 16 | # modify it under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||||||
| 17 | # | ||||||||||||||||||||||||||||||||||||||
| 18 | #======================================================================== | ||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||
| 20 | package Template; | ||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||
| 22 | 116 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 23 | 116 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 24 | 116 | ▶ | use 5.010; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 25 | 116 | ▶ | use base 'Template::Base'; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||
| 27 | 116 | ▶ | use Template::Config; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 28 | 116 | ▶ | use Template::Constants; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 29 | 116 | ▶ | use Template::Provider; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 30 | 116 | ▶ | use Template::Service; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 31 | 116 | ▶ | use File::Basename; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 32 | 116 | ▶ | use File::Path; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 33 | 116 | ▶ | use Scalar::Util qw(blessed); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||
| 35 | 116 | our $VERSION = '3.106'; | |||||||||||||||||||||||||||||||||||||
| 36 | 116 | our $ERROR = ''; | |||||||||||||||||||||||||||||||||||||
| 37 | 116 | our $DEBUG = 0; | |||||||||||||||||||||||||||||||||||||
| 38 | 116 | ▶ | our $BINMODE = 0 unless defined $BINMODE; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 39 | 116 | our $AUTOLOAD; | |||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||
| 41 | # preload all modules if we're running under mod_perl | ||||||||||||||||||||||||||||||||||||||
| 42 | 116 | ▶ | Template::Config->preload() if $ENV{ MOD_PERL }; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||
| 45 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||
| 46 | # process($input, \%replace, $output) | ||||||||||||||||||||||||||||||||||||||
| 47 | # | ||||||||||||||||||||||||||||||||||||||
| 48 | # Main entry point for the Template Toolkit. The Template module | ||||||||||||||||||||||||||||||||||||||
| 49 | # delegates most of the processing effort to the underlying SERVICE | ||||||||||||||||||||||||||||||||||||||
| 50 | # object, an instance of the Template::Service class. | ||||||||||||||||||||||||||||||||||||||
| 51 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||
| 53 | 1406 | ▶ | sub process { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
process: called CC=11 SCAR=24.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 54 | 1406 | my ($self, $template, $vars, $outstream, @opts) = @_; | |||||||||||||||||||||||||||||||||||||
| 55 | 1406 | my ($output, $error); | |||||||||||||||||||||||||||||||||||||
| 56 | 1406 | ▶ | my $options = (@opts == 1) && ref($opts[0]) eq 'HASH' | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@opts == 1 and ref $opts[0] eq "HASH"
MC/DC50%1/2
@opts == 1 and ref $opts[0] eq "HASH"
@opts == 1
ref $opts[0] eq "HASH"
Truth table66%2/3
A and B
A= @opts == 1B= ref $opts[0] eq "HASH"
| |||||||||||||||||||||||||||||||||||||||
| 57 | ? shift(@opts) : { @opts }; | ||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||
| 59 | 1406 | ▶ | $options->{ binmode } //= $BINMODE; | ||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$options->{"binmode"} //= $Template::BINMODE
MC/DC0%0/2
$options->{"binmode"} //= $Template::BINMODE
$options->{"binmode"}
$Template::BINMODE
Truth table66%2/3
A //= B
A= $options->{"binmode"}B= $Template::BINMODE
| |||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||
| 61 | # we're using this for testing in t/output.t and t/filter.t so | ||||||||||||||||||||||||||||||||||||||
| 62 | # don't remove it if you don't want tests to fail... | ||||||||||||||||||||||||||||||||||||||
| 63 | 1406 | ▶ | $self->DEBUG("set binmode\n") if $DEBUG && $options->{ binmode }; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$Template::DEBUG and $options->{"binmode"}
MC/DC50%1/2
$Template::DEBUG and $options->{"binmode"}
$Template::DEBUG
$options->{"binmode"}
Truth table66%2/3
A and B
A= $Template::DEBUGB= $options->{"binmode"}
| |||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||
| 65 | 1406 | $output = $self->{ SERVICE }->process($template, $vars); | |||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||
| 67 | 1406 | ▶ | if (defined $output) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 68 | 1394 | ▶ | $outstream ||= $self->{ OUTPUT }; | ||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$outstream ||= $self->{"OUTPUT"}
MC/DC0%0/2
$outstream ||= $self->{"OUTPUT"}
$outstream
$self->{"OUTPUT"}
Truth table66%2/3
A ||= B
A= $outstreamB= $self->{"OUTPUT"}
| |||||||||||||||||||||||||||||||||||||||
| 69 | 1394 | ▶ | unless (ref $outstream) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 70 | 4 | my $outpath = $self->{ OUTPUT_PATH }; | |||||||||||||||||||||||||||||||||||||
| 71 | 4 | ▶ | $outstream = "$outpath/$outstream" if $outpath; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||
| 74 | # send processed template to output stream, checking for error | ||||||||||||||||||||||||||||||||||||||
| 75 | 1394 | ▶ | return ($self->error($error)) | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 76 | if ($error = &_output($outstream, \$output, $options)); | ||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||
| 78 | 1394 | return 1; | |||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||
| 80 | else { | ||||||||||||||||||||||||||||||||||||||
| 81 | 12 | return $self->error($self->{ SERVICE }->error); | |||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||
| 86 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||
| 87 | # service() | ||||||||||||||||||||||||||||||||||||||
| 88 | # | ||||||||||||||||||||||||||||||||||||||
| 89 | # Returns a reference to the internal SERVICE object which handles | ||||||||||||||||||||||||||||||||||||||
| 90 | # all requests for this Template object | ||||||||||||||||||||||||||||||||||||||
| 91 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||
| 93 | 3 | ▶ | sub service { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
service: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 94 | 3 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 95 | 3 | return $self->{ SERVICE }; | |||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||
| 99 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||
| 100 | # context() | ||||||||||||||||||||||||||||||||||||||
| 101 | # | ||||||||||||||||||||||||||||||||||||||
| 102 | # Returns a reference to the CONTEXT object within the SERVICE | ||||||||||||||||||||||||||||||||||||||
| 103 | # object. | ||||||||||||||||||||||||||||||||||||||
| 104 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||
| 106 | 12 | ▶ | sub context { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
context: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 107 | 12 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 108 | 12 | return $self->{ SERVICE }->{ CONTEXT }; | |||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||
| 111 | 2 | ▶ | sub template { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
template: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 112 | 2 | shift->context->template(@_); | |||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||
| 116 | #======================================================================== | ||||||||||||||||||||||||||||||||||||||
| 117 | # -- PRIVATE METHODS -- | ||||||||||||||||||||||||||||||||||||||
| 118 | #======================================================================== | ||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||
| 120 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||
| 121 | # _init(\%config) | ||||||||||||||||||||||||||||||||||||||
| 122 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||
| 123 | 252 | ▶ | sub _init { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_init: called CC=11 SCAR=24.3
| |||||||||||||||||||||||||||||||||||||||
| 124 | 252 | my ($self, $config) = @_; | |||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||
| 126 | # convert any textual DEBUG args to numerical form | ||||||||||||||||||||||||||||||||||||||
| 127 | 252 | my $debug = $config->{ DEBUG }; | |||||||||||||||||||||||||||||||||||||
| 128 | 252 | ▶ | $config->{ DEBUG } = Template::Constants::debug_flags($self, $debug) | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition80%4/5
defined $debug and not $debug =~ /^\d+$/
Template::Constants::debug_flags($self, $debug) || (return)
MC/DC100%2/2
defined $debug and not $debug =~ /^\d+$/
defined $debug
not $debug =~ /^\d+$/
MC/DC0%0/1
Template::Constants::debug_flags($self, $debug) || (return)
Template::Constants::debug_flags($self, $debug)
Truth table100%3/3
A and not(B)
A= defined $debugB= not $debug =~ /^\d+$/
Truth table50%1/2
A
A= Template::Constants::debug_flags($self, $debug)
| |||||||||||||||||||||||||||||||||||||||
| 129 | || return if defined $debug && $debug !~ /^\d+$/; | ||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||
| 131 | # prepare a namespace handler for any CONSTANTS definition | ||||||||||||||||||||||||||||||||||||||
| 132 | 252 | ▶ | if (my $constants = $config->{ CONSTANTS }) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 133 | 9 | ▶ | my $ns = $config->{ NAMESPACE } ||= { }; | ||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$config->{"NAMESPACE"} ||= {}
MC/DC100%1/1
$config->{"NAMESPACE"} ||= {}
$config->{"NAMESPACE"}
Truth table100%2/2
A
A= $config->{"NAMESPACE"}
| |||||||||||||||||||||||||||||||||||||||
| 134 | 9 | ▶ | my $cns = $config->{ CONSTANTS_NAMESPACE } || 'constants'; | ||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$config->{'CONSTANTS_NAMESPACE'} || 'constants'
MC/DC100%1/1
$config->{'CONSTANTS_NAMESPACE'} || 'constants'
$config->{'CONSTANTS_NAMESPACE'}
Truth table100%2/2
A
A= $config->{'CONSTANTS_NAMESPACE'}
| |||||||||||||||||||||||||||||||||||||||
| 135 | 9 | ▶ | $constants = Template::Config->constants($constants) | ||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
'Template::Config'->constants($constants) || (return $self->error('Template::Config'->error))
MC/DC0%0/1
'Template::Config'->constants($constants) || (return $self->error('Template::Config'->error))
'Template::Config'->constants($constants)
Truth table50%1/2
A
A= 'Template::Config'->constants($constants)
| |||||||||||||||||||||||||||||||||||||||
| 136 | || return $self->error(Template::Config->error); | ||||||||||||||||||||||||||||||||||||||
| 137 | 9 | $ns->{ $cns } = $constants; | |||||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||
| 140 | $self->{ SERVICE } = $config->{ SERVICE } | ||||||||||||||||||||||||||||||||||||||
| 141 | 252 | ▶ | || Template::Config->service($config) | ||||||||||||||||||||||||||||||||||||
|
Condition40%2/5
$config->{'SERVICE'} || 'Template::Config'->service($config) || (return $self->error('Template::Config'->error))
$config->{"SERVICE"} or "Template::Config"->service($config)
MC/DC0%0/2
$config->{'SERVICE'} || 'Template::Config'->service($config) || (return $self->error('Template::Config'->error))
$config->{"SERVICE"}
"Template::Config"->service($config)
Truth table33%1/3
A or B
A= $config->{"SERVICE"}B= "Template::Config"->service($config)
| |||||||||||||||||||||||||||||||||||||||
| 142 | || return $self->error(Template::Config->error); | ||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||
| 144 | 252 | ▶ | $self->{ OUTPUT } = $config->{ OUTPUT } || \*STDOUT; | ||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$config->{'OUTPUT'} || \*STDOUT
MC/DC100%1/1
$config->{'OUTPUT'} || \*STDOUT
$config->{'OUTPUT'}
Truth table100%2/2
A
A= $config->{'OUTPUT'}
| |||||||||||||||||||||||||||||||||||||||
| 145 | 252 | $self->{ OUTPUT_PATH } = $config->{ OUTPUT_PATH }; | |||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||
| 147 | 252 | return $self; | |||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||
| 151 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||
| 152 | # _output($where, $text) | ||||||||||||||||||||||||||||||||||||||
| 153 | #------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||
| 155 | 1395 | ▶ | sub _output { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_output: called CC=15 SCAR=28.8
| |||||||||||||||||||||||||||||||||||||||
| 156 | 1395 | my ($where, $textref, $options) = @_; | |||||||||||||||||||||||||||||||||||||
| 157 | 1395 | my $reftype; | |||||||||||||||||||||||||||||||||||||
| 158 | 1395 | my $error = 0; | |||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||
| 160 | # call a CODE reference | ||||||||||||||||||||||||||||||||||||||
| 161 | 1395 | ▶ | if (($reftype = ref($where)) eq 'CODE') { | ||||||||||||||||||||||||||||||||||||
|
Branch: 6 branches
| |||||||||||||||||||||||||||||||||||||||
| 162 | 1 | &$where($$textref); | |||||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||||
| 164 | # print to a glob (such as \*STDOUT) | ||||||||||||||||||||||||||||||||||||||
| 165 | elsif ($reftype eq 'GLOB') { | ||||||||||||||||||||||||||||||||||||||
| 166 | 0 | print $where $$textref; | |||||||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||||||
| 168 | # append output to a SCALAR ref | ||||||||||||||||||||||||||||||||||||||
| 169 | elsif ($reftype eq 'SCALAR') { | ||||||||||||||||||||||||||||||||||||||
| 170 | 1387 | $$where .= $$textref; | |||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||
| 172 | # push onto ARRAY ref | ||||||||||||||||||||||||||||||||||||||
| 173 | elsif ($reftype eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||
| 174 | 1 | push @$where, $$textref; | |||||||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||||||||
| 176 | # call the print() method on an object that implements the method | ||||||||||||||||||||||||||||||||||||||
| 177 | # (e.g. IO::Handle, Apache::Request, etc) | ||||||||||||||||||||||||||||||||||||||
| 178 | ▶ | elsif (blessed($where) && $where->can('print')) { | |||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
builtin::blessed($where) and $where->can("print")
MC/DC50%1/2
builtin::blessed($where) and $where->can("print")
builtin::blessed($where)
$where->can("print")
Truth table66%2/3
A and B
A= builtin::blessed($where)B= $where->can("print")
| |||||||||||||||||||||||||||||||||||||||
| 179 | 1 | $where->print($$textref); | |||||||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||||||
| 181 | # a simple string is taken as a filename | ||||||||||||||||||||||||||||||||||||||
| 182 | elsif (! $reftype) { | ||||||||||||||||||||||||||||||||||||||
| 183 | 5 | local *FP; | |||||||||||||||||||||||||||||||||||||
| 184 | # make destination directory if it doesn't exist | ||||||||||||||||||||||||||||||||||||||
| 185 | 5 | my $dir = dirname($where); | |||||||||||||||||||||||||||||||||||||
| 186 | 5 | ▶ | eval { mkpath($dir) unless -d $dir; }; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 187 | 5 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||
| 188 | # strip file name and line number from error raised by die() | ||||||||||||||||||||||||||||||||||||||
| 189 | 0 | ($error = $@) =~ s/ at \S+ line \d+\n?$//; | |||||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||||
| 191 | elsif (open(FP, '>', $where)) { | ||||||||||||||||||||||||||||||||||||||
| 192 | # binmode option can be 1 or a specific layer, e.g. :utf8 | ||||||||||||||||||||||||||||||||||||||
| 193 | 5 | my $bm = $options->{ binmode }; | |||||||||||||||||||||||||||||||||||||
| 194 | 5 | ▶ | if (not(defined $bm)) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 195 | 1 | $bm = $BINMODE; | |||||||||||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||||||||||||
| 197 | 5 | ▶ | if ($bm && $bm eq 1) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
$bm and $bm eq 1
MC/DC50%1/2
$bm and $bm eq 1
$bm
$bm eq 1
Truth table66%2/3
A and B
A= $bmB= $bm eq 1
| |||||||||||||||||||||||||||||||||||||||
| 198 | 2 | binmode FP; | |||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||
| 200 | elsif ($bm){ | ||||||||||||||||||||||||||||||||||||||
| 201 | 0 | binmode FP, $bm; | |||||||||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||||||||||
| 203 | 5 | print FP $$textref; | |||||||||||||||||||||||||||||||||||||
| 204 | 5 | close FP; | |||||||||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||||||||
| 206 | else { | ||||||||||||||||||||||||||||||||||||||
| 207 | 0 | $error = "$where: $!"; | |||||||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||||||||||
| 210 | # give up, we've done our best | ||||||||||||||||||||||||||||||||||||||
| 211 | else { | ||||||||||||||||||||||||||||||||||||||
| 212 | 0 | $error = "output_handler() cannot determine target type ($where)\n"; | |||||||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||
| 215 | 1395 | return $error; | |||||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||
| 219 | 116 | 1; | |||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||
| 221 | __END__ | ||||||||||||||||||||||||||||||||||||||