Pathologically Eclectic Rubbish Lister | |
PerlMonks |
Re: questions about bless's second argumentby Fletch (Bishop) |
on Nov 19, 2020 at 23:54 UTC ( [id://11123863]=note: print w/replies, xml ) | Need Help?? |
One possible usage: imagine if you had some sort of factory method and wanted to create subclasses on the fly. Handwavy terrible example just what you could do with it (use a real metaprogramming module instead):
Then you could do something like:
Rather than cheating and scraping from the instance's class name, you could use that as a key to lookup whatever in a hash keyed by the class name. Or you could (dynamically) generate code and populate subs in the new class' package namespace (*{"Widget::${new_color}::frobulate} = sub { ... } Edit: a possible usage other than the obvious that's how subclasing works, of course. (derp)
The cake is a lie.
In Section
Seekers of Perl Wisdom
|
|