line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Error::TypeTiny::Assertion; |
2
|
|
|
|
|
|
|
|
3
|
79
|
|
|
79
|
|
3213
|
use 5.008001; |
|
79
|
|
|
|
|
315
|
|
4
|
79
|
|
|
79
|
|
520
|
use strict; |
|
79
|
|
|
|
|
216
|
|
|
79
|
|
|
|
|
1778
|
|
5
|
79
|
|
|
79
|
|
408
|
use warnings; |
|
79
|
|
|
|
|
182
|
|
|
79
|
|
|
|
|
3950
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
BEGIN { |
8
|
79
|
|
|
79
|
|
300
|
$Error::TypeTiny::Assertion::AUTHORITY = 'cpan:TOBYINK'; |
9
|
79
|
|
|
|
|
64915
|
$Error::TypeTiny::Assertion::VERSION = '2.002001'; |
10
|
|
|
|
|
|
|
} |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
$Error::TypeTiny::Assertion::VERSION =~ tr/_//d; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
require Error::TypeTiny; |
15
|
|
|
|
|
|
|
our @ISA = 'Error::TypeTiny'; |
16
|
|
|
|
|
|
|
|
17
|
373
|
|
|
373
|
1
|
1469
|
sub type { $_[0]{type} } |
18
|
369
|
|
|
369
|
1
|
1079
|
sub value { $_[0]{value} } |
19
|
1038
|
|
100
|
1038
|
1
|
5550
|
sub varname { $_[0]{varname} ||= '$_' } |
20
|
2
|
|
|
2
|
1
|
19
|
sub attribute_step { $_[0]{attribute_step} } |
21
|
2
|
|
|
2
|
1
|
9
|
sub attribute_name { $_[0]{attribute_name} } |
22
|
|
|
|
|
|
|
|
23
|
367
|
|
|
367
|
1
|
1312
|
sub has_type { defined $_[0]{type} }; # sic |
24
|
2
|
|
|
2
|
1
|
9
|
sub has_attribute_step { exists $_[0]{attribute_step} } |
25
|
2
|
|
|
2
|
1
|
1050
|
sub has_attribute_name { exists $_[0]{attribute_name} } |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub new { |
28
|
415
|
|
|
415
|
1
|
1194
|
my $class = shift; |
29
|
415
|
|
|
|
|
1506
|
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
|
415
|
50
|
33
|
|
|
1445
|
if ( ref $Method::Generate::Accessor::CurrentAttribute |
|
|
|
66
|
|
|
|
|
42
|
|
|
|
|
|
|
and $self->{mgaca} || !exists $self->{mgaca} ) |
43
|
|
|
|
|
|
|
{ |
44
|
26
|
|
|
|
|
118
|
require B; |
45
|
26
|
|
|
|
|
43
|
my %d = %{$Method::Generate::Accessor::CurrentAttribute}; |
|
26
|
|
|
|
|
96
|
|
46
|
26
|
50
|
|
|
|
87
|
$self->{attribute_name} = $d{name} if defined $d{name}; |
47
|
26
|
50
|
|
|
|
102
|
$self->{attribute_step} = $d{step} if defined $d{step}; |
48
|
|
|
|
|
|
|
|
49
|
26
|
100
|
|
|
|
64
|
if ( defined $d{init_arg} ) { |
|
|
50
|
|
|
|
|
|
50
|
21
|
|
|
|
|
156
|
$self->{varname} = sprintf( '$args->{%s}', B::perlstring( $d{init_arg} ) ); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
elsif ( defined $d{name} ) { |
53
|
5
|
|
|
|
|
37
|
$self->{varname} = sprintf( '$self->{%s}', B::perlstring( $d{name} ) ); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
} #/ if ( ref $Method::Generate::Accessor::CurrentAttribute...) |
56
|
|
|
|
|
|
|
|
57
|
415
|
|
|
|
|
1918
|
return $self; |
58
|
|
|
|
|
|
|
} #/ sub new |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub message { |
61
|
349
|
|
|
349
|
1
|
1760
|
my $e = shift; |
62
|
349
|
100
|
|
|
|
806
|
$e->varname eq '$_' |
63
|
|
|
|
|
|
|
? $e->SUPER::message |
64
|
|
|
|
|
|
|
: sprintf( '%s (in %s)', $e->SUPER::message, $e->varname ); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub _build_message { |
68
|
1
|
|
|
1
|
|
2
|
my $e = shift; |
69
|
1
|
50
|
|
|
|
2
|
$e->has_type |
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
|
|
|
|
|
|
|
*to_string = sub { |
81
|
343
|
|
|
343
|
|
803
|
my $e = shift; |
82
|
343
|
|
|
|
|
912
|
my $msg = $e->message; |
83
|
|
|
|
|
|
|
|
84
|
343
|
|
|
|
|
1157
|
my $c = $e->context; |
85
|
343
|
50
|
50
|
|
|
2559
|
$msg .= sprintf( " at %s line %s", $c->{file} || 'file?', $c->{line} || 'NaN' ) |
|
|
|
50
|
|
|
|
|
86
|
|
|
|
|
|
|
if $c; |
87
|
|
|
|
|
|
|
|
88
|
343
|
|
|
|
|
918
|
my $explain = $e->explain; |
89
|
343
|
100
|
|
|
|
744
|
return "$msg\n" unless @{ $explain || [] }; |
|
343
|
100
|
|
|
|
1228
|
|
90
|
|
|
|
|
|
|
|
91
|
342
|
|
|
|
|
688
|
$msg .= "\n"; |
92
|
342
|
|
|
|
|
774
|
for my $line ( @$explain ) { |
93
|
2105
|
|
|
|
|
4182
|
$msg .= " $line\n"; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
342
|
|
|
|
|
2206
|
return $msg; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
if $] >= 5.008; |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub explain { |
101
|
366
|
|
|
366
|
1
|
905
|
my $e = shift; |
102
|
366
|
100
|
|
|
|
804
|
return undef unless $e->has_type; |
103
|
365
|
|
|
|
|
985
|
$e->type->validate_explain( $e->value, $e->varname ); |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
1; |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
__END__ |