| 1 | package Error::TypeTiny; | ||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||
| 3 | 290 | ▶ | use 5.008001; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 4 | 290 | ▶ | use strict; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 5 | 290 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||
| 7 | 290 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 8 | 290 | $Error::TypeTiny::AUTHORITY = 'cpan:TOBYINK'; | |||||||||||||||||||||||||||||||||
| 9 | 290 | $Error::TypeTiny::VERSION = '2.010001'; | |||||||||||||||||||||||||||||||||
| 10 | } | ||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||
| 12 | 290 | $Error::TypeTiny::VERSION =~ tr/_//d; | |||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||
| 14 | 290 | require Type::Tiny; | |||||||||||||||||||||||||||||||||
| 15 | __PACKAGE__->Type::Tiny::_install_overloads( | ||||||||||||||||||||||||||||||||||
| 16 | 730 | ▶ | q[""] => sub { local $@; $_[0]->to_string }, | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 17 | 854 | ▶ | q[bool] => sub { 1 }, | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 18 | 290 | ); | |||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||
| 20 | 290 | require Carp; | |||||||||||||||||||||||||||||||||
| 21 | 290 | *CarpInternal = \%Carp::CarpInternal; | |||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||
| 23 | 290 | our %CarpInternal; | |||||||||||||||||||||||||||||||||
| 24 | 290 | $CarpInternal{$_}++ for @Type::Tiny::InternalPackages; | |||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||
| 26 | 879 | ▶ | sub new { | ||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 27 | 879 | my $class = shift; | |||||||||||||||||||||||||||||||||
| 28 | 0 | ▶ | my %params = ( @_ == 1 ) ? %{ $_[0] } : @_; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 29 | 879 | return bless \%params, $class; | |||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||
| 32 | 450 | ▶ | sub throw { | ||||||||||||||||||||||||||||||||
|
Subroutine
throw: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 33 | 450 | my $next = $_[0]->can( 'throw_cb' ); | |||||||||||||||||||||||||||||||||
| 34 | 450 | splice( @_, 1, 0, undef ); | |||||||||||||||||||||||||||||||||
| 35 | 450 | goto $next; | |||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||
| 38 | 878 | ▶ | sub throw_cb { | ||||||||||||||||||||||||||||||||
|
Subroutine
throw_cb: called CC=11 SCAR=24.1
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 39 | 878 | my $class = shift; | |||||||||||||||||||||||||||||||||
| 40 | 878 | my $callback = shift; | |||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||
| 42 | 878 | my ( $level, @caller, %ctxt ) = 0; | |||||||||||||||||||||||||||||||||
| 43 | 878 | ▶ | while ( | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 44 | do { | ||||||||||||||||||||||||||||||||||
| 45 | 2504 | my $caller = caller $level; | |||||||||||||||||||||||||||||||||
| 46 | 2504 | ▶ | defined $caller and $CarpInternal{$caller}; | ||||||||||||||||||||||||||||||||
|
Condition66%2/3
defined $caller && $Error::TypeTiny::CarpInternal{$caller}
MC/DC50%1/2
defined $caller && $Error::TypeTiny::CarpInternal{$caller}
defined $caller
$Error::TypeTiny::CarpInternal{$caller}
Truth table66%2/3
A && B
A= defined $callerB= $Error::TypeTiny::CarpInternal{$caller}
| |||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||
| 48 | ) | ||||||||||||||||||||||||||||||||||
| 49 | { | ||||||||||||||||||||||||||||||||||
| 50 | 1626 | $level++; | |||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||
| 52 | 878 | ▶ | if ( ( ( caller( $level - 1 ) )[1] || "" ) =~ | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
(caller $level - 1)[1] || ''
MC/DC100%1/1
(caller $level - 1)[1] || ''
(caller $level - 1)[1]
Truth table100%2/2
A
A= (caller $level - 1)[1]
| |||||||||||||||||||||||||||||||||||
| 53 | /^(?:parameter validation for|exportable function) '(.+?)'$/ ) | ||||||||||||||||||||||||||||||||||
| 54 | { | ||||||||||||||||||||||||||||||||||
| 55 | 652 | my ( $pkg, $func ) = ( $1 =~ m{^(.+)::(\w+)$} ); | |||||||||||||||||||||||||||||||||
| 56 | 652 | ▶ | $level++ if caller( $level ) eq ( $pkg || "" ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$pkg || ''
MC/DC0%0/1
$pkg || ''
$pkg
Truth table50%1/2
A
A= $pkg
| |||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||
| 59 | { | ||||||||||||||||||||||||||||||||||
| 60 | 290 | ▶ | no warnings 'uninitialized'; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 61 | # Moo's Method::Generate::Constructor puts an eval in the stack trace, | ||||||||||||||||||||||||||||||||||
| 62 | # that is useless for debugging, so show the stack frame one above. | ||||||||||||||||||||||||||||||||||
| 63 | 878 | ▶ | $level++ | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
(caller $level)[1] =~ /^\(eval \d+\)$/ and (caller $level)[3] eq "(eval)"
MC/DC0%0/2
(caller $level)[1] =~ /^\(eval \d+\)$/ and (caller $level)[3] eq "(eval)"
(caller $level)[1] =~ /^\(eval \d+\)$/
(caller $level)[3] eq "(eval)"
Truth table33%1/3
A and B
A= (caller $level)[1] =~ /^\(eval \d+\)$/B= (caller $level)[3] eq "(eval)"
| |||||||||||||||||||||||||||||||||||
| 64 | if ( | ||||||||||||||||||||||||||||||||||
| 65 | ( caller( $level ) )[1] =~ /^\(eval \d+\)$/ | ||||||||||||||||||||||||||||||||||
| 66 | and ( caller( $level ) )[3] eq '(eval)' # (caller())[3] is $subroutine | ||||||||||||||||||||||||||||||||||
| 67 | ); | ||||||||||||||||||||||||||||||||||
| 68 | 878 | @ctxt{qw/ package file line /} = caller( $level ); | |||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||
| 71 | 878 | my $stack = undef; | |||||||||||||||||||||||||||||||||
| 72 | 878 | ▶ | if ( our $StackTrace ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 73 | 1 | require Devel::StackTrace; | |||||||||||||||||||||||||||||||||
| 74 | 1 | $stack = "Devel::StackTrace"->new( | |||||||||||||||||||||||||||||||||
| 75 | ignore_package => [ keys %CarpInternal ], | ||||||||||||||||||||||||||||||||||
| 76 | ); | ||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||
| 79 | 878 | our $LastError = $class->new( | |||||||||||||||||||||||||||||||||
| 80 | context => \%ctxt, | ||||||||||||||||||||||||||||||||||
| 81 | stack_trace => $stack, | ||||||||||||||||||||||||||||||||||
| 82 | @_, | ||||||||||||||||||||||||||||||||||
| 83 | ); | ||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||
| 85 | 878 | ▶ | $callback ? $callback->( $LastError ) : die( $LastError ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 86 | } #/ sub throw | ||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||
| 88 | 750 | ▶ | sub message { $_[0]{message} ||= $_[0]->_build_message } | ||||||||||||||||||||||||||||||||
|
Subroutine
message: called CC=2 SCAR=7.2
Pod
documented
Condition66%2/3
$_[0]{"message"} ||= $_[0]->_build_message
MC/DC0%0/2
$_[0]{"message"} ||= $_[0]->_build_message
$_[0]{"message"}
$_[0]->_build_message
Truth table66%2/3
A ||= B
A= $_[0]{"message"}B= $_[0]->_build_message
| |||||||||||||||||||||||||||||||||||
| 89 | 737 | ▶ | sub context { $_[0]{context} } | ||||||||||||||||||||||||||||||||
|
Subroutine
context: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 90 | 3 | ▶ | sub stack_trace { $_[0]{stack_trace} } | ||||||||||||||||||||||||||||||||
|
Subroutine
stack_trace: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||
| 92 | 392 | ▶ | sub to_string { | ||||||||||||||||||||||||||||||||
|
Subroutine
to_string: called CC=5 SCAR=17.8
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 93 | 392 | my $e = shift; | |||||||||||||||||||||||||||||||||
| 94 | 392 | my $c = $e->context; | |||||||||||||||||||||||||||||||||
| 95 | 392 | my $m = $e->message; | |||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||
| 97 | $m =~ /\n\z/s | ||||||||||||||||||||||||||||||||||
| 98 | ? $m | ||||||||||||||||||||||||||||||||||
| 99 | : $c ? sprintf( | ||||||||||||||||||||||||||||||||||
| 100 | "%s at %s line %s.\n", $m, $c->{file} || 'file?', | ||||||||||||||||||||||||||||||||||
| 101 | 392 | ▶ | $c->{line} || 'NaN' | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
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'}
| |||||||||||||||||||||||||||||||||||
| 102 | ) | ||||||||||||||||||||||||||||||||||
| 103 | : sprintf( "%s\n", $m ); | ||||||||||||||||||||||||||||||||||
| 104 | } #/ sub to_string | ||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||
| 106 | 1 | ▶ | sub _build_message { | ||||||||||||||||||||||||||||||||
|
Subroutine
_build_message: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 107 | 1 | return 'An exception has occurred'; | |||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||
| 110 | 141 | ▶ | sub croak { | ||||||||||||||||||||||||||||||||
|
Subroutine
croak: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 111 | 141 | my ( $fmt, @args ) = @_; | |||||||||||||||||||||||||||||||||
| 112 | 141 | @_ = ( | |||||||||||||||||||||||||||||||||
| 113 | __PACKAGE__, | ||||||||||||||||||||||||||||||||||
| 114 | message => sprintf( $fmt, @args ), | ||||||||||||||||||||||||||||||||||
| 115 | ); | ||||||||||||||||||||||||||||||||||
| 116 | 141 | goto \&throw; | |||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||
| 119 | 290 | 1; | |||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||
| 121 | __END__ | ||||||||||||||||||||||||||||||||||