in reply to Small examples of string eval
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.
It is important to note that "SUPER" refers to the super-class(es) of the current packageso instead of just doing this:
I have to do this:$class->SUPER::blah($hash_of_data);
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.eval " package $class; \$class->SUPER::blah(\$hash_of_data); ";
|
---|
In Section
Seekers of Perl Wisdom