Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Autocreating Classes

by stvn (Monsignor)
on Oct 07, 2006 at 13:26 UTC ( #576839=note: print w/ replies, xml ) Need Help??


in reply to Autocreating Classes

If you need to generate these classes dynamically at runtime, then you could use the technique Joost suggested. However, if you have a fixed set of classes which you know at compile time, and are basically just looking to save your wrists from having to type things over and over, then you could use Module::Compile::TT to just expand the code you need at module load time (actually pre compile-time phase).

package A; # ... code here use tt ( subclasses => [ map { 'B' . $_ } 1 .. 100 ] ); [% FOREACH subclass IN subclasses %] package [% subclass %]; our @ISA = qw(A); [% END %] no tt;
There is always more than one way to do it ;)

-stvn


Comment on Re: Autocreating Classes
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://576839]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (13)
As of 2014-10-30 16:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (208 votes), past polls