line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Error::TypeTiny; |
2
|
|
|
|
|
|
|
|
3
|
112
|
|
|
112
|
|
5335
|
use 5.008001; |
|
112
|
|
|
|
|
432
|
|
4
|
112
|
|
|
112
|
|
690
|
use strict; |
|
112
|
|
|
|
|
627
|
|
|
112
|
|
|
|
|
2439
|
|
5
|
112
|
|
|
112
|
|
569
|
use warnings; |
|
112
|
|
|
|
|
274
|
|
|
112
|
|
|
|
|
4923
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
BEGIN { |
8
|
112
|
|
|
112
|
|
443
|
$Error::TypeTiny::AUTHORITY = 'cpan:TOBYINK'; |
9
|
112
|
|
|
|
|
96839
|
$Error::TypeTiny::VERSION = '2.002001'; |
10
|
|
|
|
|
|
|
} |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
$Error::TypeTiny::VERSION =~ tr/_//d; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
require Type::Tiny; |
15
|
|
|
|
|
|
|
__PACKAGE__->Type::Tiny::_install_overloads( |
16
|
720
|
|
|
720
|
|
220701
|
q[""] => sub { $_[0]->to_string }, |
17
|
1598
|
|
|
1598
|
|
11708
|
q[bool] => sub { 1 }, |
18
|
|
|
|
|
|
|
); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
require Carp; |
21
|
|
|
|
|
|
|
*CarpInternal = \%Carp::CarpInternal; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
our %CarpInternal; |
24
|
|
|
|
|
|
|
$CarpInternal{$_}++ for @Type::Tiny::InternalPackages; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub new { |
27
|
838
|
|
|
838
|
1
|
1361
|
my $class = shift; |
28
|
838
|
50
|
|
|
|
4171
|
my %params = ( @_ == 1 ) ? %{ $_[0] } : @_; |
|
0
|
|
|
|
|
0
|
|
29
|
838
|
|
|
|
|
3272
|
return bless \%params, $class; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub throw { |
33
|
422
|
|
|
422
|
1
|
24467
|
my $next = $_[0]->can( 'throw_cb' ); |
34
|
422
|
|
|
|
|
1291
|
splice( @_, 1, 0, undef ); |
35
|
422
|
|
|
|
|
1221
|
goto $next; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub throw_cb { |
39
|
837
|
|
|
837
|
1
|
1909
|
my $class = shift; |
40
|
837
|
|
|
|
|
1289
|
my $callback = shift; |
41
|
|
|
|
|
|
|
|
42
|
837
|
|
|
|
|
1821
|
my ( $level, @caller, %ctxt ) = 0; |
43
|
837
|
|
|
|
|
1384
|
while ( |
44
|
|
|
|
|
|
|
do { |
45
|
2361
|
|
|
|
|
3950
|
my $caller = caller $level; |
46
|
2361
|
50
|
|
|
|
8884
|
defined $caller and $CarpInternal{$caller}; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
) |
49
|
|
|
|
|
|
|
{ |
50
|
1524
|
|
|
|
|
2246
|
$level++; |
51
|
|
|
|
|
|
|
} |
52
|
837
|
100
|
100
|
|
|
9182
|
if ( ( ( caller( $level - 1 ) )[1] || "" ) =~ |
53
|
|
|
|
|
|
|
/^(?:parameter validation for|exportable function) '(.+?)'$/ ) |
54
|
|
|
|
|
|
|
{ |
55
|
635
|
|
|
|
|
4076
|
my ( $pkg, $func ) = ( $1 =~ m{^(.+)::(\w+)$} ); |
56
|
635
|
100
|
50
|
|
|
2576
|
$level++ if caller( $level ) eq ( $pkg || "" ); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# Moo's Method::Generate::Constructor puts an eval in the stack trace, |
60
|
|
|
|
|
|
|
# that is useless for debugging, so show the stack frame one above. |
61
|
837
|
50
|
33
|
|
|
5800
|
$level++ |
62
|
|
|
|
|
|
|
if ( |
63
|
|
|
|
|
|
|
( caller( $level ) )[1] =~ /^\(eval \d+\)$/ |
64
|
|
|
|
|
|
|
and ( caller( $level ) )[3] eq '(eval)' # (caller())[3] is $subroutine |
65
|
|
|
|
|
|
|
); |
66
|
837
|
|
|
|
|
4842
|
@ctxt{qw/ package file line /} = caller( $level ); |
67
|
|
|
|
|
|
|
|
68
|
837
|
|
|
|
|
1838
|
my $stack = undef; |
69
|
837
|
100
|
|
|
|
1898
|
if ( our $StackTrace ) { |
70
|
1
|
|
|
|
|
4
|
require Devel::StackTrace; |
71
|
1
|
|
|
|
|
23
|
$stack = "Devel::StackTrace"->new( |
72
|
|
|
|
|
|
|
ignore_package => [ keys %CarpInternal ], |
73
|
|
|
|
|
|
|
); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
837
|
|
|
|
|
3557
|
our $LastError = $class->new( |
77
|
|
|
|
|
|
|
context => \%ctxt, |
78
|
|
|
|
|
|
|
stack_trace => $stack, |
79
|
|
|
|
|
|
|
@_, |
80
|
|
|
|
|
|
|
); |
81
|
|
|
|
|
|
|
|
82
|
837
|
100
|
|
|
|
7447
|
$callback ? $callback->( $LastError ) : die( $LastError ); |
83
|
|
|
|
|
|
|
} #/ sub throw |
84
|
|
|
|
|
|
|
|
85
|
739
|
|
66
|
739
|
1
|
6739
|
sub message { $_[0]{message} ||= $_[0]->_build_message } |
86
|
727
|
|
|
727
|
1
|
2529
|
sub context { $_[0]{context} } |
87
|
3
|
|
|
3
|
1
|
2481
|
sub stack_trace { $_[0]{stack_trace} } |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub to_string { |
90
|
377
|
|
|
377
|
1
|
842
|
my $e = shift; |
91
|
377
|
|
|
|
|
1191
|
my $c = $e->context; |
92
|
377
|
|
|
|
|
1087
|
my $m = $e->message; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
$m =~ /\n\z/s |
95
|
|
|
|
|
|
|
? $m |
96
|
|
|
|
|
|
|
: $c ? sprintf( |
97
|
|
|
|
|
|
|
"%s at %s line %s.\n", $m, $c->{file} || 'file?', |
98
|
377
|
50
|
50
|
|
|
5082
|
$c->{line} || 'NaN' |
|
|
50
|
50
|
|
|
|
|
99
|
|
|
|
|
|
|
) |
100
|
|
|
|
|
|
|
: sprintf( "%s\n", $m ); |
101
|
|
|
|
|
|
|
} #/ sub to_string |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub _build_message { |
104
|
1
|
|
|
1
|
|
6
|
return 'An exception has occurred'; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub croak { |
108
|
124
|
|
|
124
|
1
|
360
|
my ( $fmt, @args ) = @_; |
109
|
124
|
|
|
|
|
639
|
@_ = ( |
110
|
|
|
|
|
|
|
__PACKAGE__, |
111
|
|
|
|
|
|
|
message => sprintf( $fmt, @args ), |
112
|
|
|
|
|
|
|
); |
113
|
124
|
|
|
|
|
412
|
goto \&throw; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
1; |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
__END__ |