in reply to Re: Use and Require - making an informed choice.
in thread Use and Require - making an informed choice.
package Foo; use strict; use warnings; my $foo = Foo->new; $foo->rarelyusedfunction; Foo::CodeLoader->new->list(); sub new { return bless \{},shift; } sub commonlyusedfunction { # do stuff } sub rarelyusedfunction { my $self = shift; my $cl = Foo::CodeLoader->new(); $cl->load('DDS'); my $dds = Data::Dump::Streamer->new; $dds->Dump($self)->Out(); } package Foo::CodeLoader; sub new { my $class = shift; my %modules = ( DDS => 'Data::Dump::Streamer' + ); return bless \%modules,$class; } sub load { my $self = shift; my $param = shift; eval "require $self->{$param}"; } sub list { my $self = shift; for (values %{$self}) { print "$_\n"; } } 1;
Although I'm always slightly uncomfortable with eval require
--------------------------------------------------------------
"If there is such a phenomenon as absolute evil, it consists in treating another human being as a thing."
John Brunner, "The Shockwave Rider".
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Use and Require - making an informed choice.
by merlyn (Sage) on Jan 30, 2006 at 17:19 UTC | |
by g0n (Priest) on Jan 30, 2006 at 18:04 UTC | |
|
Re^3: Use and Require - making an informed choice.
by xdg (Monsignor) on Jan 30, 2006 at 15:28 UTC | |
|
Re^3: Use and Require - making an informed choice.
by demerphq (Chancellor) on Feb 01, 2006 at 08:48 UTC |