our
$VERSION
=
'3.34'
;
$VERSION
=
eval
$VERSION
;
'OIO'
=> {
'description'
=>
'Generic Object::InsideOut exception'
,
'fields'
=> [
'Error'
,
'Chain'
],
},
'OIO::Code'
=> {
'isa'
=>
'OIO'
,
'description'
=>
'Object::InsideOut exception that indicates a coding error'
,
'fields'
=> [
'Info'
,
'Code'
],
},
'OIO::Internal'
=> {
'isa'
=>
'OIO::Code'
,
'description'
=>
'Object::InsideOut exception that indicates a internal problem'
,
'fields'
=> [
'Code'
,
'Declaration'
],
},
'OIO::Attribute'
=> {
'isa'
=>
'OIO::Code'
,
'description'
=>
'Object::InsideOut exception that indicates a coding error'
,
'fields'
=> [
'Attribute'
],
},
'OIO::Method'
=> {
'isa'
=>
'OIO'
,
'description'
=>
'Object::InsideOut exception that indicates an method calling error'
,
},
'OIO::Args'
=> {
'isa'
=>
'OIO::Method'
,
'description'
=>
'Object::InsideOut exception that indicates an argument error'
,
'fields'
=> [
'Usage'
,
'Arg'
],
},
);
OIO->Trace(1);
sub
OIO::
die
{
my
$class
=
shift
;
my
%args
=
@_
;
my
$report_self
=
delete
(
$args
{
'self'
});
if
(!
$report_self
) {
my
@ignore
= (__PACKAGE__,
'Object::InsideOut'
);
if
(
exists
(
$args
{
'ignore_package'
})) {
if
(
ref
(
$args
{
'ignore_package'
})) {
push
(
@ignore
, @{
$args
{
'ignore_package'
}});
}
else
{
push
(
@ignore
,
$args
{
'ignore_package'
});
}
}
$args
{
'ignore_package'
} = \
@ignore
;
}
my
$location
=
delete
(
$args
{
'location'
});
my
$e
=
$class
->new(
%args
);
if
(
$location
) {
$e
->{
'package'
} =
$$location
[0];
$e
->{
'file'
} =
$$location
[1];
$e
->{
'line'
} =
$$location
[2];
}
elsif
(
$report_self
) {
my
$frame
=
$e
->trace->frame(1);
$e
->{
'package'
} =
$frame
->
package
;
$e
->{
'line'
} =
$frame
->line;
$e
->{
'file'
} =
$frame
->filename;
}
$e
->throw(
%args
);
}
sub
OIO::full_message
{
my
$self
=
shift
;
my
$msg
=
ref
(
$self
) .
' error: '
.
$self
->message();
chomp
(
$msg
);
my
@fields
=
$self
->Fields();
foreach
my
$field
(
@fields
) {
next
if
(
$field
eq
'Chain'
);
if
(
exists
(
$self
->{
$field
})) {
$msg
.=
"\n$field: "
.
$self
->{
$field
};
chomp
(
$msg
);
}
}
$msg
.=
"\nPackage: "
.
$self
->{
'package'
}
.
"\nFile: "
.
$self
->{
'file'
}
.
"\nLine: "
.
$self
->{
'line'
};
if
(
exists
(
$self
->{
'Chain'
})) {
my
$chain
= OIO::full_message(
$self
->{
'Chain'
});
chomp
(
$chain
);
$chain
=~ s/^/ /mg;
$msg
.=
"\n\nSubsequent to the above, the following error also occurred:\n"
.
$chain
;
}
return
(
$msg
.
"\n"
);
}
sub
OIO::trap
{
if
(Object::InsideOut::Util::is_it(
$_
[0],
'Exception::Class::Base'
)) {
die
(
$_
[0]);
}
OIO->
die
(
'location'
=> [
caller
() ],
'message'
=>
'Trapped uncaught error'
,
'Error'
=>
join
(
''
,
@_
));
}
sub
OIO::combine
{
my
(
$err1
,
$err2
) =
@_
;
if
(
$err2
&& !
ref
(
$err2
)) {
my
$e
= OIO->new(
'message'
=>
"$err2"
,
'ignore_package'
=> [ __PACKAGE__ ]
);
my
$frame
=
$e
->trace->frame(1);
$e
->{
'package'
} =
$frame
->
package
;
$e
->{
'line'
} =
$frame
->line;
$e
->{
'file'
} =
$frame
->filename;
$err2
=
$e
;
}
if
(
$err1
) {
if
(!
ref
(
$err1
)) {
my
$e
= OIO->new(
'message'
=>
"$err1"
,
'ignore_package'
=> [ __PACKAGE__ ]
);
my
$frame
=
$e
->trace->frame(1);
$e
->{
'package'
} =
$frame
->
package
;
$e
->{
'line'
} =
$frame
->line;
$e
->{
'file'
} =
$frame
->filename;
$err1
=
$e
;
}
if
(
$err2
) {
if
(Object::InsideOut::Util::is_it(
$err1
,
'OIO'
)) {
$err1
->{
'Chain'
} =
$err2
;
}
else
{
warn
(
$err2
);
}
}
}
else
{
$err1
=
$err2
;
undef
(
$err2
);
}
return
(
$err1
);
}
}
1;