Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
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 chilling in the Monastery: (8)
As of 2014-12-22 05:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (110 votes), past polls