Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Slides from NY Inside-Out Talk

by Ovid (Cardinal)
on Jan 19, 2006 at 21:51 UTC ( #524355=note: print w/replies, xml ) Need Help??


in reply to Slides from NY Inside-Out Talk

Nice slides. I see that my Class::BuildMethods faired poorly, but for reasons other than what I expected. I was generally against the idea of adding anything to this as I deliberately wanted the code to be simple, but from what I can see from your slides, there are some extremely useful features I can provide while still maintaining the simplicity.

Out of curiosity, what technique would you suggest for me to avoid the HoH? I could create a package hash inside of each class and store things there directly, but that breaks encapsulation. However, it only does that in the "please stay out of the kitchen" sense, not in the "decouple code from implementation" sense. Do you think that would be sane?

Cheers,
Ovid

New address of my CGI Course.

Replies are listed 'Best First'.
Re^2: Slides from NY Inside-Out Talk
by xdg (Monsignor) on Jan 19, 2006 at 22:43 UTC

    For the purpose for which you intend Class::BuildMethods, I don't think the HoH is a big deal. It mandates accessors, but that's an acceptable style choice if you're not trying to provide the full inside-out capability set. You could use a package global (I do that in Object::LocalVars) but there's some speed penalty there due to the extra redirection. (I'm pretty indifferent, personally, on advisory versus enforced encapsulation.)

    More critical, I think, is adding a CLONE method for thread/pseudo-fork safety if you really want to offer a robust module, particularly for users on Win32. The tricky bit will be registering the objects without losing simplicity. Short of adding a method like Class::InsideOut::register, you may need to register the object behind the scenes in the accessors when values are set. (Prior to any properties being set, there's minimal, if any, harm if the objects aren't registered.) That's simplicity at the cost of efficiency, of course.

    Storable support is the other issue you may want to address. Serializing inside-out objects with Data::Dumper is difficult. From what I understand, modules like CGI::Session can also serialize with Storable which isn't too hard to support. However, if you don't add that support, you should at least document the lack as many people just assume that any object can be serialized.

    For both of those, you should be able to crib fairly freely from Class::InsideOut -- the code is fairly clean and should adapt to your implementation without a lot of fuss.

    -xdg

    Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://524355]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (9)
As of 2019-11-15 10:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Strict and warnings: which comes first?



    Results (83 votes). Check out past polls.

    Notices?