| 1 | package Text::Xslate::Util; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 384 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 384 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 384 | ▶ | use Carp (); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 380 | ▶ | use parent qw(Exporter); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 378 | our @EXPORT_OK = qw( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | mark_raw unmark_raw | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | html_escape escaped_string | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | uri_escape | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | p dump | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | html_builder | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | hash_with_default | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | literal_to_value value_to_literal | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | import_from | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | neat | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | is_int any_in | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | read_around | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | make_error | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | $DEBUG | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | $STRING $NUMBER | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 378 | our $DEBUG; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 378 | ▶ | defined($DEBUG) or $DEBUG = $ENV{XSLATE} || ''; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$ENV{'XSLATE'} || ''
MC/DC100%1/1
$ENV{'XSLATE'} || ''
$ENV{'XSLATE'}
Truth table100%2/2
A
A= $ENV{'XSLATE'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 378 | our $DisplayWidth = 76; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 378 | ▶ | if($DEBUG =~ /display_width=(\d+)/) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | $DisplayWidth = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | # cf. http://swtch.com/~rsc/regexp/regexp1.html | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 378 | my $dquoted = qr/" [^"\\]* (?: \\. [^"\\]* )* "/xms; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 378 | my $squoted = qr/' [^'\\]* (?: \\. [^'\\]* )* '/xms; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 378 | our $STRING = qr/(?: $dquoted | $squoted )/xms; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 378 | our $NUMBER = qr/ (?: | |||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | (?: [0-9][0-9_]* (?: \. [0-9_]+)? \b) # decimal | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | | | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | (?: 0 (?: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | (?: [0-7_]+ ) # octal | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | | | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | (?: x [0-9a-fA-F_]+) # hex | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | | | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | (?: b [01_]+ ) # binary | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | )?) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | )/xms; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 378 | require Text::Xslate; # load XS stuff | |||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | sub mark_raw; # XS | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | sub unmark_raw; # XS | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | sub html_escape; # XS | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | sub uri_escape; # XS | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 378 | sub escaped_string; *escaped_string = \&mark_raw; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | sub merge_hash; # XS | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 12 | ▶ | sub html_builder (&){ | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
html_builder: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 12 | my($code_ref) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 12 | ▶ | return sub { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 12 | my $ret = $code_ref->(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | return ref($ret) eq 'CODE' | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 12 | ▶ | ? html_builder(\&{$ret}) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | : mark_raw($ret); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 12 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 12 | ▶ | sub hash_with_default { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
hash_with_default: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 12 | my($hash_ref, $default) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 12 | ▶ | ref($hash_ref) eq 'HASH' | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | or Carp::croak('Usage: hash_with_default(\%vars, $default)'); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 12 | require 'Text/Xslate/HashWithDefault.pm'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 12 | my %vars; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 12 | tie %vars, 'Text::Xslate::HashWithDefault', $hash_ref, $default; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 12 | return \%vars; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | # for internals | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 56 | ▶ | sub neat { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
neat: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 56 | my($s) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 56 | ▶ | if ( defined $s ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 52 | ▶ | if ( ref($s) || Scalar::Util::looks_like_number($s) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
ref $s or &Scalar::Util::looks_like_number($s)
MC/DC100%2/2
ref $s or &Scalar::Util::looks_like_number($s)
ref $s
&Scalar::Util::looks_like_number($s)
Truth table100%3/3
A or B
A= ref $sB= &Scalar::Util::looks_like_number($s)
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 7 | return $s; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 47 | return "'$s'"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 6 | return 'nil'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 39069 | ▶ | sub is_int { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_int: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 39069 | my($s) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | # XXX: '+1', '1.0', '00', must NOT be interpreted as an integer | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 39069 | ▶ | return defined($s) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition88%8/9
defined $s && $s =~ /\A -? [0-9]+ \z/msx && int $s eq $s && abs int $s < 2147483647
defined $s and $s =~ /\A -? [0-9]+ \z/msx and int $s eq $s
defined $s and $s =~ /\A -? [0-9]+ \z/msx
MC/DC75%3/4
defined $s && $s =~ /\A -? [0-9]+ \z/msx && int $s eq $s && abs int $s < 2147483647
defined $s
$s =~ /\A -? [0-9]+ \z/msx
int $s eq $s
abs int $s < 2147483647
Truth table80%4/5
A and B and C && D
A= defined $sB= $s =~ /\A -? [0-9]+ \z/msxC= int $s eq $sD= abs int $s < 2147483647
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | && $s =~ /\A -? [0-9]+ \z/xms | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | && int($s) eq $s | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | && abs(int($s)) < 0x7FFF_FFFF; # fits int32_t | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 6654 | ▶ | sub any_in { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
any_in: called CC=3 SCAR=12.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 6654 | my $value = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 6654 | ▶ | if(defined $value) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 6652 | ▶ | return scalar grep { defined($_) && $value eq $_ } @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
defined $_ && $value eq $_
MC/DC50%1/2
defined $_ && $value eq $_
defined $_
$value eq $_
Truth table66%2/3
A && B
A= defined $_B= $value eq $_
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | return scalar grep { not defined($_) } @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 378 | my %esc2char = ( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 't' => "\t", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 'n' => "\n", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 'r' => "\r", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 35725 | ▶ | sub literal_to_value { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
literal_to_value: called CC=8 SCAR=20.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 35723 | my($value) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 35723 | ▶ | return $value if not defined $value; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 35723 | ▶ | if($value =~ s/\A "(.*)" \z/$1/xms){ | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 33028 | ▶ | $value =~ s/\\(.)/$esc2char{$1} || $1/xmseg; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$esc2char{$1} || $1
MC/DC0%0/2
$esc2char{$1} || $1
$esc2char{$1}
$1
Truth table66%2/3
A || B
A= $esc2char{$1}B= $1
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | elsif($value =~ s/\A '(.*)' \z/$1/xms) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 272 | $value =~ s/\\(['\\])/$1/xmsg; # ' for poor editors | |||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | elsif($value =~ /\A [+-]? $NUMBER \z/xmso) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 2289 | ▶ | if($value =~ s/\A ([+-]?) (?= 0[0-7xb])//xms) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 74 | ▶ | $value = ($1 eq '-' ? -1 : +1) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | * oct($value); # also grok hex and binary | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 2215 | $value =~ s/_//xmsg; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 35723 | return $value; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 378 | my %char2esc = ( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | "\\" => '\\\\', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | "\n" => '\\n', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | "\r" => '\\r', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | '"' => '\\"', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | '$' => '\\$', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | '@' => '\\@', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 378 | my $value_chars = join '|', map { quotemeta } keys %char2esc; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 108 | ▶ | sub value_to_literal { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
value_to_literal: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 108 | my($value) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 108 | ▶ | return 'undef' if not defined $value; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 108 | ▶ | if(is_int($value)){ | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 32 | return $value; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 76 | $value =~ s/($value_chars)/$char2esc{$1}/xmsgeo; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 76 | return qq{"$value"}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 36 | ▶ | sub import_from { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
import_from: called CC=12 SCAR=25.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 36 | my $code = "# Text::Xslate::Util::import_from()\n" | |||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | . "package " . "Text::Xslate::Util::_import;\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | . "use warnings FATAL => 'all';\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | . 'my @args;' . "\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 36 | ▶ | for(my $i = 0; $i < @_; $i++) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 48 | my $module = $_[$i]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 48 | ▶ | if($module =~ /[^a-zA-Z0-9_:]/) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 2 | Carp::confess("Xslate: Invalid module name: $module"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 46 | my $commands; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 46 | ▶ | if(ref $_[$i+1]){ | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 26 | require 'Data/Dumper.pm'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 26 | my @args = ($_[++$i]); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 26 | my @protos = ('*data'); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 26 | $commands = Data::Dumper->new(\@args, \@protos)->Terse(1)->Dump(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 46 | ▶ | $code .= "use $module ();\n" if !$module->can('export_into_xslate'); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 46 | ▶ | if(!defined($commands) or $commands ne '') { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $commands or $commands ne ""
MC/DC0%0/2
not defined $commands or $commands ne ""
not defined $commands
$commands ne ""
Truth table66%2/3
not(A) or B
A= not defined $commandsB= $commands ne ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 46 | ▶ | $code .= sprintf <<'END_IMPORT', $module, $commands || '()'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$commands || '()'
MC/DC100%1/1
$commands || '()'
$commands
Truth table100%2/2
A
A= $commands
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | @args = %2$s; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | %1$s->can('export_into_xslate') | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | ? %1$s->export_into_xslate(\@funcs, @args) # bridge modules | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | : %1$s->import(@args); # function-based modules | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | END_IMPORT | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 34 | local $Text::Xslate::Util::{'_import::'}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | #print STDERR $code; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 34 | my @funcs; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 34 | my $e = do { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 34 | local $@; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 34 | ▶ | eval qq{package} | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | . qq{ Text::Xslate::Util::_import;\n} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | . $code; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 34 | $@; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 34 | ▶ | Carp::confess("Xslate: Failed to import:\n" . $e) if $e; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | push @funcs, map { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 32 | my $entity_ref = \$Text::Xslate::Util::_import::{$_}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 98 | my $c; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 98 | ▶ | if(ref($entity_ref) eq 'GLOB') { # normal symbols | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 98 | $c = *{$entity_ref}{CODE}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | elsif(ref($entity_ref) eq 'REF') { # special constants | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 380 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 0 | $c = \&{ 'Text::Xslate::Util::_import::' . $_ }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 98 | ▶ | defined($c) ? ($_ => $c) : (); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | } keys %Text::Xslate::Util::_import::; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 32 | return {@funcs}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 779 | ▶ | sub make_error { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
make_error: called CC=10 SCAR=23.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 779 | my($self, $message, $file, $line, @extra) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 779 | ▶ | if(ref $message eq 'SCALAR') { # re-thrown form virtual machines | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | return ${$message}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 779 | my $lines = read_around($file, $line, 1, $self->input_layer); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 779 | ▶ | if($lines) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 736 | ▶ | $lines .= "\n" if $lines !~ /\n\z/xms; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 736 | $lines = '-' x $DisplayWidth . "\n" | |||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | . $lines | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | . '-' x $DisplayWidth . "\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 779 | local $Carp::CarpLevel = $Carp::CarpLevel + 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 779 | ▶ | my $class = ref($self) || $self; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $self || $self
MC/DC0%0/2
ref $self || $self
ref $self
$self
Truth table33%1/3
A || B
A= ref $selfB= $self
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 779 | ▶ | $message =~ s/\A \Q$class: \E//xms and $message .= "\t..."; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 779 | ▶ | if(defined $file) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 759 | ▶ | if(defined $line) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 753 | unshift @extra, $line; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 759 | ▶ | unshift @extra, ref($file) ? '<string>' : $file; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 779 | ▶ | if(@extra) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 759 | $message = Carp::shortmess(sprintf '%s (%s)', | |||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | $message, join(':', @extra)); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 20 | $message = Carp::shortmess($message); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 779 | return sprintf "%s: %s%s", | |||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | $class, $message, $lines; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 789 | ▶ | sub read_around { # for error messages | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_around: called CC=10 SCAR=23.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 789 | my($file, $line, $around, $input_layer) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 789 | ▶ | defined($file) && defined($line) or return ''; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $file and defined $line
MC/DC100%2/2
defined $file and defined $line
defined $file
defined $line
Truth table100%3/3
A and B
A= defined $fileB= defined $line
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 761 | ▶ | if (ref $file) { # if $file is a scalar ref, it must contain text strings | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 301 | my $content = $$file; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 301 | utf8::encode($content); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 301 | $file = \$content; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 761 | ▶ | $around = 1 if not defined $around; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 761 | ▶ | $input_layer = '' if not defined $input_layer; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 761 | ▶ | open my $in, '<' . $input_layer, $file or return ''; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 742 | local $/ = "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 742 | local $. = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 742 | my $s = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 742 | ▶ | while(defined(my $l = <$in>)) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 1612 | ▶ | if($. >= ($line - $around)) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 1332 | $s .= $l; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 1612 | ▶ | if($. >= ($line + $around)) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 82 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 742 | return $s; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 148 | ▶ | sub p { # for debugging, the guts of dump() | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
p: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 148 | require 'Data/Dumper.pm'; # we don't want to create its namespace | |||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 148 | my $dd = Data::Dumper->new(\@_); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 148 | $dd->Indent(1); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 148 | $dd->Sortkeys(1); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 148 | $dd->Quotekeys(0); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 148 | $dd->Terse(1); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 148 | ▶ | return $dd->Dump() if defined wantarray; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 0 | print $dd->Dump(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 6 | ▶ | sub dump :method { goto &p } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dump: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 378 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||