| 1 | package Text::Nunjucks::Runtime::SafeString; | ||||||||||||||
| 2 | # ABSTRACT: A string marked as safe from autoescaping (runtime.js SafeString) | ||||||||||||||
| 3 | |||||||||||||||
| 4 | 23 | our $VERSION = '0.001'; | |||||||||||||
| 5 | |||||||||||||||
| 6 | 23 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | 23 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 8 | use overload | ||||||||||||||
| 9 | 72 | ▶ | '""' => sub { $_[0]->{val} }, | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 10 | 0 | ▶ | 'bool' => sub { 1 }, | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 11 | 23 | fallback => 1; | |||||||||||||
| 12 | 23 | ▶ | use Text::Nunjucks::Lib; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 13 | |||||||||||||||
| 14 | # upstream: function SafeString in src/runtime.js (a String subclass). | ||||||||||||||
| 15 | # | ||||||||||||||
| 16 | # JS: `function SafeString(val){ if (typeof val!=='string') return val; ... }` | ||||||||||||||
| 17 | # and prototype valueOf/toString both return this.val. Marks a string as not | ||||||||||||||
| 18 | # to be autoescaped. Overloads stringification to val so the compiler's output | ||||||||||||||
| 19 | # concatenation coerces it exactly as JS's `+ ''` does. | ||||||||||||||
| 20 | |||||||||||||||
| 21 | 107524 | ▶ | sub new { | ||||||||||||
|
Subroutine
new: called CC=2 SCAR=9.2
Pod
undocumented
| |||||||||||||||
| 22 | 0 | ▶ | my ( $class, $val ) = @_; | ||||||||||||
|
Subroutine
new: not called CC=2 SCAR=9.2
Pod
undocumented
| |||||||||||||||
| 23 | # if (typeof val !== 'string') return val; -- non-strings pass through | ||||||||||||||
| 24 | 0 | ▶ | return $val unless Text::Nunjucks::Lib->is_string($val); | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 25 | # this.length = val.length -- in UTF-16 code units (ADR 0012) | ||||||||||||||
| 26 | 0 | return bless { val => $val, length => Text::Nunjucks::Lib->js_string_length($val) }, $class; | |||||||||||||
| 27 | } | ||||||||||||||
| 28 | |||||||||||||||
| 29 | 107657 | ▶ | sub val { $_[0]->{val} } | ||||||||||||
|
Subroutine
val: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 30 | 2 | ▶ | sub length { $_[0]->{length} } | ||||||||||||
|
Subroutine
length: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 31 | 0 | ▶ | sub value_of { $_[0]->{val} } # SafeString.prototype.valueOf | ||||||||||||
|
Subroutine
value_of: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 32 | 0 | ▶ | sub to_string { $_[0]->{val} } # SafeString.prototype.toString | ||||||||||||
|
Subroutine
to_string: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 33 | |||||||||||||||
| 34 | 23 | 1; | |||||||||||||
| 35 | |||||||||||||||
| 36 | __END__ | ||||||||||||||