| 1 | package Text::Nunjucks::Lib::Error; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Port representation of a JS built-in Error / TypeError (name + message) | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 23 | our $VERSION = '0.001'; | |||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 23 | ▶ | use Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 23 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | # src/lib.js reaches for the JS globals `new Error(...)` (inOperator) and | ||||||||||||||||||||||||||||
| 10 | # `new TypeError(...)` (groupBy). Perl has no universal Error base, so the port | ||||||||||||||||||||||||||||
| 11 | # models a thrown JS error as a small object carrying { name, message } -- the | ||||||||||||||||||||||||||||
| 12 | # two fields _prettifyError reads back ("${cause.name}: ${cause.message}") and | ||||||||||||||||||||||||||||
| 13 | # the corpus harness reads (->name / ->message). `name` defaults to 'Error'; | ||||||||||||||||||||||||||||
| 14 | # callers that want a different JS error type pass name => 'TypeError'. | ||||||||||||||||||||||||||||
| 15 | # | ||||||||||||||||||||||||||||
| 16 | # NOTE (open mapping): how JS built-in error types map to Perl is not yet | ||||||||||||||||||||||||||||
| 17 | # settled by an ADR -- see the k9 report. This class is the single, minimal | ||||||||||||||||||||||||||||
| 18 | # place that representation is encapsulated. | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 23 | has message => ( is => 'ro' ); | |||||||||||||||||||||||||||
| 21 | 281 | ▶ | has name => ( is => 'ro', default => sub { 'Error' } ); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 1587 | ▶ | around BUILDARGS => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.3
| |||||||||||||||||||||||||||||
| 24 | 1587 | my ( $orig, $class, @args ) = @_; | |||||||||||||||||||||||||||
| 25 | 1587 | ▶ | return $class->$orig(@args) if @args == 1 && ref $args[0] eq 'HASH'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@args == 1 and ref $args[0] eq "HASH"
MC/DC0%0/2
@args == 1 and ref $args[0] eq "HASH"
@args == 1
ref $args[0] eq "HASH"
Truth table66%2/3
A and B
A= @args == 1B= ref $args[0] eq "HASH"
| |||||||||||||||||||||||||||||
| 26 | 1587 | my ( $message, %opts ) = @args; | |||||||||||||||||||||||||||
| 27 | 1587 | return $class->$orig( message => $message, %opts ); | |||||||||||||||||||||||||||
| 28 | 23 | }; | |||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 23 | 1; | |||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | __END__ | ||||||||||||||||||||||||||||