I wanted to build an awesome place for people to discuss module specific issues, but I don't have any more time for this, and there are much better places to discuss Perl-related issues. I'd recommend asking your question on Stack Overflow or on Perl Monks.
If you are looking for a Perl tutorial or Perl-related news, I hope these links will serve you well.
Posted on 2008-06-24 13:56:29-07 by mgoldshteyn
Question about multi-field object tests in :Init
I would like to check if an object is in invariant form after all of the final initialization is performed in the :Init attributed subroutine. If the object is in an "improper" form, I would like to fail construction, just as field type validators throw an OIO::Args error. I realize that I can do this manually, but such functionality should probably be built in. For example, maybe some :Restricted function in Object::InsideOut itself that one could call from an :Init subroutine that would perform:
OIO::Args->die(...)
... with some supplied parameters.

Here is a somewhat contrived example that demonstrates the need and you can decide on the best approach:
sub _init :Init { # A car should not have any sort of wings as one of its parts # Note that this test involves two members of the class and could potentially # test base class members or functions on them, as well. if ($vehicle_type[$$self] eq 'car' && grep {/\Wwings\W/} @{$parts[$$self]}) { $self->fail_init( 'message' => 'A car should not have wings', 'Info' => 'A wings part was added to a vehicle of type car', ); # fail_init should do whatever it needs to and result in a die() # We never get to this point, because of the early exit due to fail_init } }

Thanks,

Michael Goldshteyn
Direct Responses: 8142 | Write a response