graq has asked for the wisdom of the Perl Monks concerning the following question:
Or am I missing the point (as usual :P)?package Some::Class; my $typeToTableLookup = { 'typeOne' => 'classOne', 'typeTwo' => 'classTwo', }; require A::N::Other::typeOne; # Remove these require A::N::Other::typeTwo; # two lines... sub new { my ($proto, $type) = @_; my $class = ref($proto) || $proto; die( "Note type must be specified.\n" ) unless $type; my $self = bless { type => $type }, $class; return $self; } sub doSomeFoo { my ($self, $id) = @_; my $typeTableName = $$typeToTableLookup{$self->{type}} or die( "Type does not have a class\n" ); my $classFile = 'A::N::Other::'.ucfirst($typeTableName); my $fooOb; eval { # require $classFile; # ... and replace them here. $fooOb = $classFile->doSomeBar($id); }; die $@ if $@; return \$fooOb; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Arbritrarily requireing classes.
by japhy (Canon) on Aug 03, 2004 at 16:03 UTC | |
|
•Re: Arbritrarily requireing classes.
by merlyn (Sage) on Aug 03, 2004 at 16:13 UTC | |
|
Re: Arbritrarily requireing classes.
by Gilimanjaro (Hermit) on Aug 03, 2004 at 16:14 UTC | |
|
Re: Arbritrarily requireing classes.
by danielcid (Scribe) on Aug 03, 2004 at 16:12 UTC | |
|
Re: Arbritrarily requireing classes.
by ysth (Canon) on Aug 03, 2004 at 17:08 UTC | |
|
Re: Arbritrarily requireing classes.
by gellyfish (Monsignor) on Aug 03, 2004 at 16:43 UTC | |
|
Re: Arbritrarily requireing classes.
by broquaint (Abbot) on Aug 04, 2004 at 03:34 UTC |