You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Arshavir Grigorian <gr...@gmail.com> on 2006/08/21 19:33:42 UTC
dynamic loading
Hi,
I am wondering if anyone has experience with a framework for
dynamically loading certain modules into an application and executing
certain code based on whether a certain module is loaded (available or
not). By "dynamically", I do not mean loading run-time, only being
able to safely exclude certain modules at startup. One place this
could come in handy is when selling an app to 2 clients of whom one
has purchased all the functionality and the other has not, and you
don't want to give them certain module(s). I am guessing one could
accomplish this by using a macro processor (m4) to preprocess Perl
code before it's "released", but it would probably be somewhat
painful.
I'd love to hear what others have done in similar situations. Thanks in advance.
Arshavir
Re: dynamic loading
Posted by Arshavir Grigorian <gr...@gmail.com>.
Thanks for all the posts.
Re: dynamic loading
Posted by James Smith <js...@sanger.ac.uk>.
For the project I work on many of our Modules derive from a common
Root module which contains the following dynamic_use call which is
exactly the same as a use line - but does not fail fatally if the
module isn't there - it also nicely means that the code isn't
loaded up front (as if all blocks of code were included with a
normal use line)... it seems to work OK for the project (which
has a nice plugin system)
our $failed_modules;
sub dynamic_use {
my( $self, $classname ) = @_;
unless( $classname ) {
my @caller = caller(0);
my $error_message = "Dynamic use called from $caller[1] (line
$caller[2]) with no classname parameter\n";
warn $error_message;
$failed_modules->{$classname} = $error_message;
return 0;
}
if( exists( $failed_modules->{$classname} ) ) {
# warn "EnsEMBL::Web::Root: tried to use $classname again - this has
already failed $failed_modules->{$classname}";
return 0;
}
my( $parent_namespace, $module ) = $classname =~/^(.*::)(.*)$/ ? ($1,$2)
: ('::',$classname);
no strict 'refs';
return 1 if $parent_namespace->{$module.'::'} && %{
$parent_namespace->{$module.'::'}||{} }; # return if already used
eval "require $classname";
if($@) {
warn "EnsEMBL::Web::Root: failed to use
$classname\nEnsEMBL::Web::Root: $@" unless $@ =~/^Can't locate /;
$parent_namespace->{$module.'::'} = {};
$failed_modules->{$classname} = $@ || "Unknown failure when
dynamically using module";
return 0;
}
$classname->import();
return 1;
}
sub dynamic_use_failure {
my( $self, $classname ) = @_;
return $failed_modules->{$classname};
}
On Mon, 21 Aug 2006, John ORourke wrote:
> Arshavir Grigorian wrote:
>
> > I am wondering if anyone has experience with a framework for
> > dynamically loading certain modules into an application and executing
> > certain code based on whether a certain module is loaded (available or
> > not). By "dynamically", I do not mean loading run-time, only being
> > able to safely exclude certain modules at startup. One place this
> > could come in handy is when selling an app to 2 clients of whom one
> > has purchased all the functionality and the other has not, and you
> > don't want to give them certain module(s). I am guessing one could
> > accomplish this by using a macro processor (m4) to preprocess Perl
> > code before it's "released", but it would probably be somewhat
> > painful.
>
>
> I'm just finishing a plugin architecture which dynamically loads
> available plugins, but in doing so I found some useful CPAN modules:
>
> Module::Optional - exactly what you're after
> Module::Pluggable - very flexible plugin/optional module manager
>
> hth,
> John
>
>
Re: dynamic loading
Posted by John ORourke <jo...@o-rourke.org>.
Arshavir Grigorian wrote:
> I am wondering if anyone has experience with a framework for
> dynamically loading certain modules into an application and executing
> certain code based on whether a certain module is loaded (available or
> not). By "dynamically", I do not mean loading run-time, only being
> able to safely exclude certain modules at startup. One place this
> could come in handy is when selling an app to 2 clients of whom one
> has purchased all the functionality and the other has not, and you
> don't want to give them certain module(s). I am guessing one could
> accomplish this by using a macro processor (m4) to preprocess Perl
> code before it's "released", but it would probably be somewhat
> painful.
I'm just finishing a plugin architecture which dynamically loads
available plugins, but in doing so I found some useful CPAN modules:
Module::Optional - exactly what you're after
Module::Pluggable - very flexible plugin/optional module manager
hth,
John
Re: dynamic loading
Posted by "Philip M. Gollucci" <pg...@p6m7g8.com>.
Arshavir Grigorian wrote:
> Hi,
>
> I am wondering if anyone has experience with a framework for
> dynamically loading certain modules into an application and executing
> certain code based on whether a certain module is loaded (available or
> not). By "dynamically", I do not mean loading run-time, only being
> able to safely exclude certain modules at startup. One place this
> could come in handy is when selling an app to 2 clients of whom one
> has purchased all the functionality and the other has not, and you
> don't want to give them certain module(s). I am guessing one could
> accomplish this by using a macro processor (m4) to preprocess Perl
> code before it's "released", but it would probably be somewhat
> painful.
Actually I dont' think the m4 idea is so bad, you could probably just have it stub out the packages
package A;
1;
and change your code to do ::can() or ->can() as appropriate.
I can't think of another way, that will keep the "conditional" code shared for those that bought it all.
--
------------------------------------------------------------------------
Philip M. Gollucci (pgollucci@p6m7g8.com) 323.219.4708
Consultant / http://p6m7g8.net/Resume/resume.shtml
Senior Software Engineer - TicketMaster - http://ticketmaster.com
1024D/A79997FA F357 0FDD 2301 6296 690F 6A47 D55A 7172 A799 97F
"In all that I've done wrong I know I must have done something right to
deserve a hug every morning and butterfly kisses at night."
__ ___ ___ ____ __
/ |/ /_ __/ __/ __ \/ /
/ /|_/ / // /\ \/ /_/ / /__
/_/ /_/\_, /___/\___\_\___/
<___/