what's wrong with calling the public constructor for Time::Piece from within the constructor of your subclass (thereby providing an instance to _mktime), and then reblessing the reference returned into your current package?
I'd love to, but it's not that simple.
- It is not the only route of construction -- new objects are created either by new(), overloaded operators, gmtime(), or localtime(). The last two are procedural in nature and will not work if called statically via package name indirection (Time::MyPiece->gmtime()) since they expect either a reference or scalar seconds since epoch as first args. All of these eventually call _mktime() either as a method or procedure, so it seemed to make since to target the real constructor rather than each individual route.
- Even when we do target _mktime(), the blessings are hard coded as class 'Time::Piece'; we can rebless in a constructor, but we're stuck again with having to override every method that eventually calls _mktime() so that we can rebless. Not zesty.
It's worth noting as well that unless the documentation explicitly guards against it, you're perfectly free to interpret this as a "protected" method, which as a subclass your module may legitimately override.
Good point, I feel better about that then.
Now, granted, if they're functions then they'll expect to be called on a class name, not on a reference to a class instance, ...
This still passes the class name as a first argument -- as I mentioned, if the first argument is present and not a reference, then it expects it to be a scalar count of seconds since epoch, not a string representing the calling class name.
Matt
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:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.