perl-modperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Steve Piner <ste...@marketview.co.nz>
Subject Re: How do my handler call dynamically a module based the request input
Date Mon, 05 Aug 2002 22:33:22 GMT

You could probably do the same thing that constructors do, i.e. pass the
name of the class in a variable:

my $class = "A::$module_call";
$class->C(@params);

That should work under 'use strict'. You might need to see what happens
with the first parameter in C though.

Steve


Harry Zhu wrote:
> 
> That will do the work, but the thing is I need add "no strict" before such
> statements, maybe in many places.
> 
> I can also do like
> $result =  A::B1::C->(@params) if $module_call eq 'B1';
> $result =  A::B2::C->(@params) if $module_call eq 'B2';
> $result =  A::B3::C->(@params) if $module_call eq 'B3';
> ...
> but it's not flexible, even not feasible when more and more Bs added to the
> list.
> Is there any other way that seems less odd to do the similar dispatch work?
> 
> Harry Zhu
> 
> ----- Original Message -----
> From: "Robert Landrum" <rlandrum@aol.net>
> To: <modperl@perl.apache.org>
> Sent: Monday, August 05, 2002 2:43 PM
> Subject: Re: How do my handler call dynamically a module based the request
> input
> 
> > On Mon, Aug 05, 2002 at 02:08:24PM -0700, Harry Zhu wrote:
> > > Some small tricks needed to pass the "strict" check, see if you perl
> guru out there give me some hint:
> > >
> > > Suppose I have module A::B1, A::B2, A::B3 with method C
> > >
> > > my old cgi would look something like
> > > sub D {
> > > my ($module_call, @params) = shift;
> > > my $result = A::${module_call}::C->(@params);
> > > ...
> >
> >
> > Hmm...  Seems odd to do things this way, but Ok.
> >
> > my $result;
> > { no strict;
> > $result = A::${module_call}::C->(@params);
> > }
> >
> > Rob
> > --
> > Robert Landrum
> > Systems Programmer
> >

-- 
Steve Piner
Web Applications Developer
Marketview Limited
http://www.marketview.co.nz

Mime
View raw message