Here's an example I wrote. It's in use in production code. The method that contains this is a "helper" method which lives in its own package and is used in several classes. It mangles some paramaters and then:
- changes package to whatever class it was invoked from;
- calls a method in that class's superclass.
The reason I need to change package halfway through the method is, from perldoc perlobj
It is important to note that "SUPER" refers to the super-class(es) of the current package
so instead of just doing this:
I have to do this:
Block eval won't cut it here, and while I'm sure plenty of people are going to bleat that this travesty just demonstrates that my design was wrong in the first place (and I'd agree) in the real world one doesn't always know what all the requirements are when one starts writing code. I decided it was better to write a couple of lines of ugly code - and comment what I was doing and why - than to spend literally days re-jigging everything else so that I could then write that tiny snippet of functionality more cleanly.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
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.
| & || & |
| < || < |
| > || > |
| [ || [ |
| ] || ] ||