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".
In reply to Re^2: Use and Require - making an informed choice.
by g0n
in thread Use and Require - making an informed choice.
by g0n
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |