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.
> 
> I'd love to hear what others have done in similar situations. Thanks
> in advance.

sub has_module {
    my ($module_name) = @_;
    $module_name =~ s{::}{/}g;
    $module_name .= ".pm";
    return $INC{$module_name} || eval { require $module_name };
}

if (has_module("DBIx::Class")) {
    print "You have the DBIx::Class module!\n";
}

You should try perlmonks.org or comp.lang.perl.misc newsgroup, since
this is about Perl in general, not necessarily mod_perl.

Regards,
Philip

Reply via email to