| 1 | package Unexpected::TraitFor::StringifyingError; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 4 | ▶ | use Unexpected::Functions qw( inflate_placeholders parse_arg_list ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 4 | ▶ | use Unexpected::Types qw( ArrayRef Bool Str ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 4 | ▶ | use Moo::Role; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 4 | requires qw( BUILD ); | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | # Object attributes (public) | ||||||||||||||||||||||||||||
| 12 | 23 | ▶ | has 'args' => is => 'ro', isa => ArrayRef, default => sub { [] }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 4 | has 'error' => is => 'ro', isa => Str, default => 'Unknown error'; | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 4 | has 'no_quote_bind_values' => is => 'ro', isa => Bool, default => 0; | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | # Construction | ||||||||||||||||||||||||||||
| 19 | 33 | ▶ | around 'BUILDARGS' => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||
| 20 | 33 | my ($orig, $self, @args) = @_; my $attr = parse_arg_list( @args ); | |||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 33 | my $e = delete $attr->{error}; | |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 33 | ▶ | $e and ref $e eq 'CODE' and $e = $e->( $self, $attr ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$e and ref $e eq "CODE"
MC/DC100%2/2
$e and ref $e eq "CODE"
$e
ref $e eq "CODE"
Truth table100%3/3
A and B
A= $eB= ref $e eq "CODE"
| |||||||||||||||||||||||||||||
| 25 | 33 | ▶ | $e and $e .= q() and chomp $e; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$e and $e .= ''
MC/DC50%1/2
$e and $e .= ''
$e
$e .= ''
Truth table66%2/3
A and B
A= $eB= $e .= ''
| |||||||||||||||||||||||||||||
| 26 | 33 | ▶ | $e and $attr->{error} = $e; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 27 | 33 | return $attr; | |||||||||||||||||||||||||||
| 28 | 4 | }; | |||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 31 | ▶ | after 'BUILD' => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 31 | # Fixes 98c94be8-d01e-11e2-8bc5-3f0fbdbf7481 WTF? Stringify fails. | ||||||||||||||||||||||||||||
| 32 | # Bug only happens when Moose class inherits from Moo class which | ||||||||||||||||||||||||||||
| 33 | # uses overload string. Moose class inherits from Moose class which | ||||||||||||||||||||||||||||
| 34 | # has consumed a ::Role::WithOverloading works. Moo inherits from | ||||||||||||||||||||||||||||
| 35 | # Moo also works | ||||||||||||||||||||||||||||
| 36 | 31 | my $self = shift; $self->as_string; return; | |||||||||||||||||||||||||||
| 37 | 4 | }; | |||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | # Public methods | ||||||||||||||||||||||||||||
| 40 | 13 | ▶ | sub as_boolean { | ||||||||||||||||||||||||||
|
Subroutine
as_boolean: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 41 | 13 | return 1; | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 53 | ▶ | sub as_string { # Stringifies the error and inflates the placeholders | ||||||||||||||||||||||||||
|
Subroutine
as_string: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 45 | 53 | my $self = shift; my $e = $self->error; | |||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 53 | ▶ | 0 > index $e, '[_' and return "${e}\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 14 | my $opts = [ '[?]', '[]', $self->no_quote_bind_values ]; | |||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 14 | return inflate_placeholders( $opts, $e, @{ $self->args } )."\n"; | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 4 | 1; | |||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | __END__ | ||||||||||||||||||||||||||||