Are there any weaknesses?
- As was pointed out, you need to take care of possibility someone
subclass will implement stringification overload. A solution was
proposed - alternatively, you can document that it's forbidden
for a subclass to overload stringification if you don't want
to pay the penalty. I think this isn't a major issue; overloading
is used, but most objects don't.
- You have to write a DESTROY method. You can't say that you can
live with the memory leak - Perl does not garantee that if you
create a reference, let it go out of scope, and then create a
new reference, the new one will not have the same address as
the first one.
- Serialization might be a bit harder in some cases. But calling
Serialize or Date::Dumper on an object won't work in general
anyway. An object might have a reference to something, and
a general serialization function cannot know whether the
reference needs to be shared with something else.
- You can't use the standard Class::MethodMaker. But that doesn't
mean you can't have a module giving you the same functionality.
I've written a proof of concept Class::MethodMaker::InsideOut
(not released) giving the same functionality as Class::MethodMaker
for Inside Out objects. It'll can even do the DESTROY function
and the declaration of hashes. It's using a source filter.
Alternatively, you could use our to declare the
attribute hashes, and write a module with the same functionality
- If you have a large class, you may want to split it over more than
one file. If your attribute hashes are lexical, this will not work.
Again, you could use a source filter to merge the files, or
declare the attribute hashes with our.
Just in case you are saying that making the attribute hashes
package variables makes that someone else can access your attributes,
that's ok. I'm not advocating my technique such that you cannot
get to the attributes, I want to prevent accidents
After all: "It would prefer that you stayed out of its living room
because you weren't invited, not because it has a shotgun."
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
| & || & |
| < || < |
| > || > |
| [ || [ |
| ] || ] ||