karlgoethebier:
You're not wrong at all. Roles could be a good way to do it.
Generally I do it when:
- It's purely a one-off thing that I'm trying to solve, and don't expect to ever need it for the class again. A frequent case is when I'm debugging something complicated that relies on a little bit of inner state of the class and a custom "toString" function in the class for logging could give me the data I need to solve the problem.
- The class API isn't fully resolved and some of the implementation is a bit hacky. I don't want to expose the hackiness to the classes API but I need to get a problem solved. So I have no problem accessing the internals in an ugly fashion to make something happen, and let the class evolve normally without putting an ugly hack in the API that may be troublesome to remove later. (Such as when John Smith sees it and immediately uses it in production....)
I'm not saying it's a good/best practice, but that it sure is convenient.
Sorry for the long delay in replying. I've ignored my Chatterbox queue a bit too long, and now I'm trying to work through the backlog...
...roboticus
When your only tool is a hammer, all problems look like your thumb.
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.