| 1 | package Error::TypeTiny::Assertion; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 286 | ▶ | use 5.008001; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 286 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 286 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 286 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 286 | $Error::TypeTiny::Assertion::AUTHORITY = 'cpan:TOBYINK'; | |||||||||||||||||||||||||||||||||||||||||
| 9 | 286 | $Error::TypeTiny::Assertion::VERSION = '2.010001'; | |||||||||||||||||||||||||||||||||||||||||
| 10 | } | ||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 286 | $Error::TypeTiny::Assertion::VERSION =~ tr/_//d; | |||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 286 | require Error::TypeTiny; | |||||||||||||||||||||||||||||||||||||||||
| 15 | 286 | our @ISA = 'Error::TypeTiny'; | |||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 368 | ▶ | sub type { $_[0]{type} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
type: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 364 | ▶ | sub value { $_[0]{value} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
value: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 1020 | ▶ | sub varname { $_[0]{varname} ||= '$_' } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
varname: called CC=2 SCAR=6.9
Pod
documented
Condition100%2/2
$_[0]{"varname"} ||= "\$_"
MC/DC100%1/1
$_[0]{"varname"} ||= "\$_"
$_[0]{"varname"}
Truth table100%2/2
A
A= $_[0]{"varname"}
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | 2 | ▶ | sub attribute_step { $_[0]{attribute_step} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
attribute_step: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 2 | ▶ | sub attribute_name { $_[0]{attribute_name} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
attribute_name: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 362 | ▶ | sub has_type { defined $_[0]{type} }; # sic | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
has_type: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 2 | ▶ | sub has_attribute_step { exists $_[0]{attribute_step} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
has_attribute_step: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | 2 | ▶ | sub has_attribute_name { exists $_[0]{attribute_name} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
has_attribute_name: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | 427 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=8 SCAR=21.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | 427 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 29 | 427 | my $self = $class->SUPER::new( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | # Supported but undocumented parameter is `mgaca`. | ||||||||||||||||||||||||||||||||||||||||||
| 32 | # This indicates whether Error::TypeTiny::Assertion | ||||||||||||||||||||||||||||||||||||||||||
| 33 | # should attempt to figure out which attribute caused | ||||||||||||||||||||||||||||||||||||||||||
| 34 | # the error from Method::Generate::Accessor's info. | ||||||||||||||||||||||||||||||||||||||||||
| 35 | # Can be set to true/false or not set. If not set, | ||||||||||||||||||||||||||||||||||||||||||
| 36 | # the current behaviour is true, but this may change | ||||||||||||||||||||||||||||||||||||||||||
| 37 | # in the future. If set to false, will ignore the | ||||||||||||||||||||||||||||||||||||||||||
| 38 | # $Method::Generate::Accessor::CurrentAttribute hashref. | ||||||||||||||||||||||||||||||||||||||||||
| 39 | # | ||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | 427 | ▶ | if ( ref $Method::Generate::Accessor::CurrentAttribute | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
ref $Method::Generate::Accessor::CurrentAttribute and $self->{"mgaca"} || !exists $self->{"mgaca"}
$self->{"mgaca"} or not exists $self->{"mgaca"}
MC/DC33%1/3
ref $Method::Generate::Accessor::CurrentAttribute and $self->{"mgaca"} || !exists $self->{"mgaca"}
ref $Method::Generate::Accessor::CurrentAttribute
$self->{"mgaca"}
not exists $self->{"mgaca"}
Truth table50%2/4
A and B or not(C)
A= ref $Method::Generate::Accessor::CurrentAttributeB= $self->{"mgaca"}C= not exists $self->{"mgaca"}
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | and $self->{mgaca} || !exists $self->{mgaca} ) | ||||||||||||||||||||||||||||||||||||||||||
| 43 | { | ||||||||||||||||||||||||||||||||||||||||||
| 44 | 26 | require B; | |||||||||||||||||||||||||||||||||||||||||
| 45 | 26 | my %d = %{$Method::Generate::Accessor::CurrentAttribute}; | |||||||||||||||||||||||||||||||||||||||||
| 46 | 26 | ▶ | $self->{attribute_name} = $d{name} if defined $d{name}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | 26 | ▶ | $self->{attribute_step} = $d{step} if defined $d{step}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | 26 | ▶ | if ( defined $d{init_arg} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | 21 | $self->{varname} = sprintf( '$args->{%s}', B::perlstring( $d{init_arg} ) ); | |||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||
| 52 | elsif ( defined $d{name} ) { | ||||||||||||||||||||||||||||||||||||||||||
| 53 | 5 | $self->{varname} = sprintf( '$self->{%s}', B::perlstring( $d{name} ) ); | |||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||
| 55 | } #/ if ( ref $Method::Generate::Accessor::CurrentAttribute...) | ||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | 427 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 58 | } #/ sub new | ||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | 344 | ▶ | sub message { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
message: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | 344 | my $e = shift; | |||||||||||||||||||||||||||||||||||||||||
| 62 | 344 | ▶ | $e->varname eq '$_' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | ? $e->SUPER::message | ||||||||||||||||||||||||||||||||||||||||||
| 64 | : sprintf( '%s (in %s)', $e->SUPER::message, $e->varname ); | ||||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | 1 | ▶ | sub _build_message { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_message: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | 1 | my $e = shift; | |||||||||||||||||||||||||||||||||||||||||
| 69 | 1 | ▶ | $e->has_type | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | ? sprintf( | ||||||||||||||||||||||||||||||||||||||||||
| 71 | '%s did not pass type constraint "%s"', | ||||||||||||||||||||||||||||||||||||||||||
| 72 | Type::Tiny::_dd( $e->value ), $e->type | ||||||||||||||||||||||||||||||||||||||||||
| 73 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 74 | : sprintf( | ||||||||||||||||||||||||||||||||||||||||||
| 75 | '%s did not pass type constraint', | ||||||||||||||||||||||||||||||||||||||||||
| 76 | Type::Tiny::_dd( $e->value ) | ||||||||||||||||||||||||||||||||||||||||||
| 77 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 78 | } #/ sub _build_message | ||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||
| 80 | 338 | ▶ | *to_string = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=7 SCAR=19.7
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | 338 | my $e = shift; | |||||||||||||||||||||||||||||||||||||||||
| 82 | 338 | my $msg = $e->message; | |||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | 338 | my $c = $e->context; | |||||||||||||||||||||||||||||||||||||||||
| 85 | 338 | ▶ | $msg .= sprintf( " at %s line %s", $c->{file} || 'file?', $c->{line} || 'NaN' ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%2/4
$c->{'file'} || 'file?'
$c->{'line'} || 'NaN'
MC/DC0%0/1
$c->{'file'} || 'file?'
$c->{'file'}
MC/DC0%0/1
$c->{'line'} || 'NaN'
$c->{'line'}
Truth table50%1/2
A
A= $c->{'file'}
Truth table50%1/2
A
A= $c->{'line'}
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | if $c; | ||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | 338 | my $explain = $e->explain; | |||||||||||||||||||||||||||||||||||||||||
| 89 | 338 | ▶ | return "$msg\n" unless @{ $explain || [] }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$explain || []
MC/DC100%1/1
$explain || []
$explain
Truth table100%2/2
A
A= $explain
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | 337 | $msg .= "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 92 | 337 | for my $line ( @$explain ) { | |||||||||||||||||||||||||||||||||||||||||
| 93 | 2063 | $msg .= " $line\n"; | |||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | 337 | return $msg; | |||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||
| 98 | 286 | ▶ | if $] >= 5.008; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | 361 | ▶ | sub explain { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
explain: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | 361 | my $e = shift; | |||||||||||||||||||||||||||||||||||||||||
| 102 | 361 | ▶ | return undef unless $e->has_type; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | 360 | $e->type->validate_explain( $e->value, $e->varname ); | |||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | 286 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | __END__ | ||||||||||||||||||||||||||||||||||||||||||