On 05/12/2013 22:59, Mike Small wrote:

Would it work for you to keep your hash but make the values instead be
references to arrays of references to objects with the attributes you
mention above: address, width, masks, etc.?  Are the values in your
current hash objects with such attributes? Is it only that before you
had one value per name and now you have many or is there more to it than
that?

I'd consider objects that have _getter and _setter fields as well as a value field. _getter and _setter would be closures which know the details about what are legal values, defined when the object is created, and the normal get() and set() methods would use them.

I do something along those lines in CPU::Emulator::Z80 to hide the implementation details of register pairs. See the _derive_register_16 and _derive_register_8 methods.

You may also like the trick with Tie::Hash::Vivify to prevent accidental auto-vivification in the hash of registers.

--
David Cantrell | Official London Perl Mongers Bad Influence

There's no problem so complex that it can't be solved
by killing everyone even remotely associated with it

_______________________________________________
Boston-pm mailing list
[email protected]
http://mail.pm.org/mailman/listinfo/boston-pm

Reply via email to