| 1 | package XML::CuteQueries::Error; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 21 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 21 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 21 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 21 | ▶ | use Config; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 21 | ▶ | use overload '""' => "_stringify", fallback=>1; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 21 | ▶ | use base 'Class::Accessor'; __PACKAGE__->mk_accessors(qw(type text)); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 21 | ▶ | use constant QUERY_ERROR => 1; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 21 | ▶ | use constant DATA_ERROR => 2; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 21 | ▶ | use constant UNKNOWN => 9_999; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 21 | my $USEDBY = "???"; | |||||||||||||||||||||||||||
| 16 | 21 | ▶ | sub import { $USEDBY = caller; return } | ||||||||||||||||||||||||||
|
Subroutine
import: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | # new {{{ | ||||||||||||||||||||||||||||
| 19 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||||||||||||||||||||
| 20 | 0 | my $class = shift; | |||||||||||||||||||||||||||
| 21 | 0 | my $this = bless {type=>UNKNOWN, text=>"unknown", @_, map {$_=>"unknown"} qw(ub_file ub_line file line package caller)}, $class; | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | # This is ripped off from IPC::System::Simple::Exception, it's pretty hot | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 0 | my ($package, $file, $line, $sub); | |||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 0 | my $depth = 0; | |||||||||||||||||||||||||||
| 28 | 0 | while (1) { | |||||||||||||||||||||||||||
| 29 | 0 | ($package, $file, $line, $sub) = CORE::caller($depth++); | |||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | # Skip up the call stack until we find something outside | ||||||||||||||||||||||||||||
| 32 | # of the caller, $class or eval space | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 0 | ▶ | croak "This should probably be invoked inside modules designed to use it, rather than just raw as you have done" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | unless $package; | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 0 | ▶ | if( $package->isa($USEDBY) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | 0 | $this->{ub_file} = $file; | |||||||||||||||||||||||||||
| 39 | 0 | $this->{ub_line} = $line; | |||||||||||||||||||||||||||
| 40 | 0 | next; | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 0 | ▶ | next if $package->isa($class); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | 0 | ▶ | next if $package->isa(__PACKAGE__); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | 0 | ▶ | next if $file =~ /^\(eval\s\d+\)$/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 0 | last; | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | # We now have everything correct, *except* for our subroutine | ||||||||||||||||||||||||||||
| 51 | # name. If it's __ANON__ or (eval), then we need to keep on | ||||||||||||||||||||||||||||
| 52 | # digging deeper into our stack to find the real name. However we | ||||||||||||||||||||||||||||
| 53 | # don't update our other information, since that will be correct | ||||||||||||||||||||||||||||
| 54 | # for our current exception. | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 0 | my $first_guess_subroutine = $sub; | |||||||||||||||||||||||||||
| 57 | 0 | ▶ | while (defined $sub and $sub =~ /^\(eval\)$|::__ANON__$/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $sub and $sub =~ /^\(eval\)$|::__ANON__$/
MC/DC0%0/2
defined $sub and $sub =~ /^\(eval\)$|::__ANON__$/
defined $sub
$sub =~ /^\(eval\)$|::__ANON__$/
Truth table0%0/3
A and B
A= defined $subB= $sub =~ /^\(eval\)$|::__ANON__$/
| |||||||||||||||||||||||||||||
| 58 | 0 | $depth++; | |||||||||||||||||||||||||||
| 59 | 0 | $sub = (CORE::caller($depth))[3]; | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | # If we end up falling out the bottom of our stack, then our | ||||||||||||||||||||||||||||
| 63 | # __ANON__ guess is the best we can get. This includes situations | ||||||||||||||||||||||||||||
| 64 | # where we were called from the top level of a program. | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 0 | ▶ | if (not defined $sub) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | 0 | $sub = $first_guess_subroutine; | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 0 | $this->{package} = $package; | |||||||||||||||||||||||||||
| 71 | 0 | $this->{file} = $file; | |||||||||||||||||||||||||||
| 72 | 0 | $this->{line} = $line; | |||||||||||||||||||||||||||
| 73 | 0 | $this->{caller} = $sub; | |||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 0 | return $this; | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | # }}} | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 0 | ▶ | sub query_error { | ||||||||||||||||||||||||||
|
Subroutine
query_error: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 80 | 0 | my $this = shift; | |||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 0 | ▶ | return 1 if $this->{type} == QUERY_ERROR; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 83 | 0 | return; | |||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 0 | ▶ | sub data_error { | ||||||||||||||||||||||||||
|
Subroutine
data_error: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 87 | 0 | my $this = shift; | |||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 0 | ▶ | return 1 if $this->{type} == DATA_ERROR; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | 0 | return; | |||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 0 | ▶ | sub throw { | ||||||||||||||||||||||||||
|
Subroutine
throw: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 94 | 0 | my $this = shift; | |||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 0 | croak $this; | |||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 0 | ▶ | sub _stringify { | ||||||||||||||||||||||||||
|
Subroutine
_stringify: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 100 | 0 | my $this = shift; | |||||||||||||||||||||||||||
| 101 | 0 | my $type = $this->{type}; | |||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 0 | ▶ | return "DATA ERROR: $this->{text} at $this->{file} line $this->{line}\n" if $type == DATA_ERROR; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 104 | 0 | ▶ | return "QUERY ERROR: $this->{text} at $this->{file} line $this->{line}\n" if $type == QUERY_ERROR; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 0 | return "UNKNOWN ERROR TYPE at $this->{ub_file} line $this->{ub_line}: $this->{text} or something at $this->{file} line $this->{line}\n"; | |||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 21 | 1; | |||||||||||||||||||||||||||