| 1 | package RPC::ExtDirect::Exception; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 7 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 7 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 7 | ▶ | no warnings 'uninitialized'; ## no critic | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 7 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 7 | ▶ | use RPC::ExtDirect::Util::Accessor; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 7 | ▶ | use RPC::ExtDirect::Util qw/ clean_error_message get_caller_info /; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | ### PUBLIC CLASS METHOD (CONSTRUCTOR) ### | ||||||||||||||||||||||||||||
| 13 | # | ||||||||||||||||||||||||||||
| 14 | # Initializes new instance of Exception. | ||||||||||||||||||||||||||||
| 15 | # | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | sub new { | ||||||||||||||||||||||||||||
| 18 | 25 | ▶ | my ($class, $arg) = @_; | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 25 | my $where = $arg->{where}; | |||||||||||||||||||||||||||
| 21 | 25 | my $message = $arg->{message}; | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | my $self = bless { | ||||||||||||||||||||||||||||
| 24 | debug => $arg->{debug}, | ||||||||||||||||||||||||||||
| 25 | action => $arg->{action}, | ||||||||||||||||||||||||||||
| 26 | method => $arg->{method}, | ||||||||||||||||||||||||||||
| 27 | tid => $arg->{tid}, | ||||||||||||||||||||||||||||
| 28 | verbose => $arg->{verbose}, | ||||||||||||||||||||||||||||
| 29 | 25 | }, $class; | |||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 25 | $self->_set_error($message, $where); | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 25 | return $self; | |||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | ### PUBLIC INSTANCE METHOD ### | ||||||||||||||||||||||||||||
| 37 | # | ||||||||||||||||||||||||||||
| 38 | # A stub for duck typing. Always returns failure. | ||||||||||||||||||||||||||||
| 39 | # | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 18 | ▶ | sub run { '' } | ||||||||||||||||||||||||||
|
Subroutine
run: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | ### PUBLIC INSTANCE METHOD ### | ||||||||||||||||||||||||||||
| 44 | # | ||||||||||||||||||||||||||||
| 45 | # Returns exception hashref; named so for duck typing. | ||||||||||||||||||||||||||||
| 46 | # | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | sub result { | ||||||||||||||||||||||||||||
| 49 | 25 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
result: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 25 | return $self->_get_exception_hashref(); | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | ### PUBLIC INSTANCE METHODS ### | ||||||||||||||||||||||||||||
| 55 | # | ||||||||||||||||||||||||||||
| 56 | # Simple read-write accessors | ||||||||||||||||||||||||||||
| 57 | # | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 7 | RPC::ExtDirect::Util::Accessor::mk_accessors( | |||||||||||||||||||||||||||
| 60 | simple => [qw/ | ||||||||||||||||||||||||||||
| 61 | debug action method tid where message verbose | ||||||||||||||||||||||||||||
| 62 | /], | ||||||||||||||||||||||||||||
| 63 | ); | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | ############## PRIVATE METHODS BELOW ############## | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | ### PRIVATE INSTANCE METHOD ### | ||||||||||||||||||||||||||||
| 68 | # | ||||||||||||||||||||||||||||
| 69 | # Sets internal error condition and message | ||||||||||||||||||||||||||||
| 70 | # | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | sub _set_error { | ||||||||||||||||||||||||||||
| 73 | 25 | ▶ | my ($self, $message, $where) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_set_error: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | # Store the information | ||||||||||||||||||||||||||||
| 76 | 25 | ▶ | $self->{where} = defined $where ? $where : get_caller_info(3); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 77 | 25 | $self->{message} = $message; | |||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | # Ensure fall through for caller methods | ||||||||||||||||||||||||||||
| 80 | 25 | return !1; | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | ### PRIVATE INSTANCE METHOD ### | ||||||||||||||||||||||||||||
| 84 | # | ||||||||||||||||||||||||||||
| 85 | # Returns exception hashref | ||||||||||||||||||||||||||||
| 86 | # | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | sub _get_exception_hashref { | ||||||||||||||||||||||||||||
| 89 | 25 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_get_exception_hashref: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | # If debug flag is not set, return generic message. This is for | ||||||||||||||||||||||||||||
| 92 | # compatibility with Ext.Direct specification. | ||||||||||||||||||||||||||||
| 93 | 25 | my ($where, $message); | |||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 25 | ▶ | if ( $self->debug || $self->verbose ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->debug or $self->verbose
MC/DC100%2/2
$self->debug or $self->verbose
$self->debug
$self->verbose
Truth table100%3/3
A or B
A= $self->debugB= $self->verbose
| |||||||||||||||||||||||||||||
| 96 | 19 | $where = $self->where; | |||||||||||||||||||||||||||
| 97 | 19 | $message = $self->message; | |||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | else { | ||||||||||||||||||||||||||||
| 100 | 6 | $where = 'ExtDirect'; | |||||||||||||||||||||||||||
| 101 | 6 | $message = 'An error has occured while processing request'; | |||||||||||||||||||||||||||
| 102 | }; | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | # Format the hashref | ||||||||||||||||||||||||||||
| 105 | 25 | my $exception_ref = { | |||||||||||||||||||||||||||
| 106 | type => 'exception', | ||||||||||||||||||||||||||||
| 107 | action => $self->action, | ||||||||||||||||||||||||||||
| 108 | method => $self->method, | ||||||||||||||||||||||||||||
| 109 | tid => $self->tid, | ||||||||||||||||||||||||||||
| 110 | where => $where, | ||||||||||||||||||||||||||||
| 111 | message => $message, | ||||||||||||||||||||||||||||
| 112 | }; | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 25 | return $exception_ref; | |||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 7 | 1; | |||||||||||||||||||||||||||