|
Hello all and happy new year !
In one of my previous mail I sent, I sent the following question:
An object has 2 attributes, each one having a type. Only
one of these attributes is mandatory for the object. How
can I express it with your module?
Jerry, your response was:
"The easiest way is to use an :Init subroutine:
package Class_Object2; {
use Object::InsideOut;
my @attribute1
:Field
:Arg('name' => 'attribute1')
:Type(ClassName1);
my @attribute2
:Field
:Arg('name' => 'attribute2')
:Type(ClassName2);
sub init :Init
{
my ($self, $args) = @_;
# Must have at least one of these
if (! defined($attribute1[$$self]) &&
! defined($attribute2[$$self]))
{
OIO::Args->die(
'error' => 'Missing mandatory arg',
'Usage' => q/Must specify at least one of 'attribute1'
and 'attribute2'/,
'ignore_package' => __PACKAGE__);
}
}
}
But if I create a object Class_Object2 with no parameter, OIO::Code exception is raised instead of OIO::Args (OIO::Args exception is not rethrown in subroutine _args from InsideOut.pm)
Is it possible to retrieve the OIO::Args exception !
Thanks |