You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Harry Zhu <ha...@GreatLodge.COM> on 2002/08/05 23:08:24 UTC

How do my handler call dynamically a module based the request input

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);
...
}

But now I am converting it to mod-perl and like to "use strict" everywhere. However, it fails
 [error] Can't use string ("A::B1::C") as a SCALAR ref while "strict refs" in use at myscript.pm  


Seperately, if I have hash
$c = {
   b=> {
     a => {
       a1 =>1,
       a2 => 2,
     },
     ....
   }
};

in module A::B, and if I do
my %b = %{$A::B::c->{b}};
and then even if I manipulate on %b, I found the $A::B::c also changed from other module calls.
for example, if $t = $b{a}{a3}; it will added a key a3 to the hash %{A::B::c->{b}{a}} !

This probably due to the reference of $A::B::c->{b}. I know if, instead, 
my %b = (), 
foreach $b (keys %{$A::B::c->{b}}) {
  foreach (keys %{$A::B::c->{b}{$b}}) {
    $b{$b}{$_} = $A::B::c->{b}{$b}{$_};
  }
} 

and it will not affact the $A::B::c what ever you do with the %b. Is the a simple way to copy only in values the hash of hash?


Harry Zhu
GreatLodge.com  

Re: How do my handler call dynamically a module based the request input

Posted by Geoffrey Young <ge...@modperlcookbook.org>.

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?


you might want to check out Apache::Dispatch (on CPAN), which does this 
kind of URI->method translation thing for you.

--Geoff




Re: How do my handler call dynamically a module based the requestinput

Posted by Harry Zhu <ha...@GreatLodge.COM>.
Actually I have both variables and functions defined parallelly in a set of
config modules, which will be dynamically used to assign the value or make
the function call based on a input parameter. I was wish the uniform way
  $module = shift;
  $x = ${"A::${module}::c}->{b};
  $y = ${"A::${module}::m}->(@param);

will work, of cause, under the "use strict". I also exported these variables
and functions, so I can do something like
  require "A/$module.pm";
  $x = $c->{b};
  $y = &m->(@param);

Seems the simplest solution is to convert the variables to functions if I
don't want the "no strict" added to my code.

Thanks a lot.

Harry


----- Original Message -----
From: "Garth Winter Webb" <ga...@perijove.com>
To: <mo...@perl.apache.org>
Cc: "Harry Zhu" <ha...@greatlodge.com>
Sent: Tuesday, August 06, 2002 8:14 PM
Subject: Re: How do my handler call dynamically a module based the
requestinput


> You keep switching what you say you want to do.  On one hand, your
> original example did this:
>
>     my $result = A::${module_call}::C->(@params);
>
> In this case, you are calling the function 'C' which is in the module
> 'A::${module_call}', but then you go on to say that you define the
> scalar $c (now lower case):
>
>     $c = {
>        b=> {
>          a => {
>            a1 =>1,
>            a2 => 2,
>          },
>          ....
>        }
>     };
>
> These are not the same thing.  Now, if you want to use Steve's method,
> you'll need to make your structure available as a subroutine; you can't
> access variables in that way.  If your data is static you can do
> something like:
>
>     package A::Foo;
>     use constant C => { b => { a => { a1 => 1, a2 => 2 } } };
>
> and since the 'use constant' really creates a subroutine for you, you
> can do something like this:
>
>     my $class = "A::$my_pkg";
>     my $value_hash = $class->C;
>
> Or if your data is dynamic, you can create regular subroutine that
> returns the correct data:
>
>     package A::Foo;
>     sub C {
>         return { b => { a => { a1 => 1, a2 => 2 } } };
>     }
>
>
>
> Garth
>
>
>
> On Tue, 2002-08-06 at 18:58, Harry Zhu wrote:
> > Nope. Even simple code like following will give me error.
> >
> > I have some code like:
> >
> > ##### GL/B1.pm
> > package GL::B1;
> > use strict;
> > use vars qw($c);
> > $c = {
> >   x => {
> >    t => 1,
> >  },
> >  ...
> > };
> >
> > 1;
> >
> > ##### GL/B.pm
> > ##### GL/B.pm
> > package GL::B;
> > use strict;
> > sub handler {
> >   my $b = shift;
> >
> > ##### it worked if "use strict" is commented out, otherwise run-time
error;
> >  my $c = "GL::${b}::c"; my %x = %{${$c}->{x}};
> >
> >  ##### it worked, but needs "no strict"; a little bit awkward
> > # my %x; {no strict; %x = %{${"GL::${b}::c"}->{x}}; }
> >
> > ##### it worked under "use strict"; not usable if the B1 should be
dynamical
> > # my %x = %{$GL::B1::c->{x}};
> >
> >   my $t = $x{t}*2;
> >   print $t;
> >
> > }
> >
> > 1;
> >
> > Compiled no problem with "use strict", but when I run
> >  > perl -e 'use GL::B1 qw($c);use GL::B; &GL::B::handler();'
> >
> > It gives the error:
> > Can't use string ("GL::B1::c") as a SCALAR ref while "strict refs" in
use at
> > GL/B.pm line 7.
> >
> > Seems the problem has nothing to do with "call different module
> > dynamically". Although if not for the dynamical call, it would directly
> > %x = %{$GL::B1::c->{x}};
> >
> > What can I do to use always the "use strict" and handle such situation?
> >
> > Harry
> >
> >
> > ----- Original Message -----
> > From: "Steve Piner" <>
> > To: "Harry Zhu" <ha...@greatlodge.com>
> > Cc: <mo...@perl.apache.org>
> > Sent: Monday, August 05, 2002 3:33 PM
> > Subject: Re: How do my handler call dynamically a module based the
request
> > input
> >
> >
> > >
> > > 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" <rl...@aol.net>
> > > > To: <mo...@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
> > >
> >
> >
>
>



Re: How do my handler call dynamically a module based the request input

Posted by Garth Winter Webb <ga...@perijove.com>.
You keep switching what you say you want to do.  On one hand, your
original example did this:

    my $result = A::${module_call}::C->(@params);

In this case, you are calling the function 'C' which is in the module
'A::${module_call}', but then you go on to say that you define the
scalar $c (now lower case):

    $c = {
       b=> {
         a => {
           a1 =>1,
           a2 => 2,
         },
         ....
       }
    };

These are not the same thing.  Now, if you want to use Steve's method,
you'll need to make your structure available as a subroutine; you can't
access variables in that way.  If your data is static you can do
something like:

    package A::Foo;
    use constant C => { b => { a => { a1 => 1, a2 => 2 } } };

and since the 'use constant' really creates a subroutine for you, you
can do something like this:

    my $class = "A::$my_pkg";
    my $value_hash = $class->C;

Or if your data is dynamic, you can create regular subroutine that
returns the correct data:

    package A::Foo;
    sub C {
        return { b => { a => { a1 => 1, a2 => 2 } } };
    }



Garth



On Tue, 2002-08-06 at 18:58, Harry Zhu wrote:
> Nope. Even simple code like following will give me error.
> 
> I have some code like:
> 
> ##### GL/B1.pm
> package GL::B1;
> use strict;
> use vars qw($c);
> $c = {
>   x => {
>    t => 1,
>  },
>  ...
> };
> 
> 1;
> 
> ##### GL/B.pm
> ##### GL/B.pm
> package GL::B;
> use strict;
> sub handler {
>   my $b = shift;
> 
> ##### it worked if "use strict" is commented out, otherwise run-time error;
>  my $c = "GL::${b}::c"; my %x = %{${$c}->{x}};
> 
>  ##### it worked, but needs "no strict"; a little bit awkward
> # my %x; {no strict; %x = %{${"GL::${b}::c"}->{x}}; }
> 
> ##### it worked under "use strict"; not usable if the B1 should be dynamical
> # my %x = %{$GL::B1::c->{x}};
> 
>   my $t = $x{t}*2;
>   print $t;
> 
> }
> 
> 1;
> 
> Compiled no problem with "use strict", but when I run
>  > perl -e 'use GL::B1 qw($c);use GL::B; &GL::B::handler();'
> 
> It gives the error:
> Can't use string ("GL::B1::c") as a SCALAR ref while "strict refs" in use at
> GL/B.pm line 7.
> 
> Seems the problem has nothing to do with "call different module
> dynamically". Although if not for the dynamical call, it would directly
> %x = %{$GL::B1::c->{x}};
> 
> What can I do to use always the "use strict" and handle such situation?
> 
> Harry
> 
> 
> ----- Original Message -----
> From: "Steve Piner" <>
> To: "Harry Zhu" <ha...@greatlodge.com>
> Cc: <mo...@perl.apache.org>
> Sent: Monday, August 05, 2002 3:33 PM
> Subject: Re: How do my handler call dynamically a module based the request
> input
> 
> 
> >
> > 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" <rl...@aol.net>
> > > To: <mo...@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
> >
> 
> 



Re: How do my handler call dynamically a module based the request input

Posted by Garth Winter Webb <ga...@perijove.com>.
On Tue, 2002-08-06 at 20:08, Steve Piner wrote:

> I think you'll have to have a "no strict 'refs'" in there somewhere, as
> you are using soft references, which is exactly what "use strict" turns
> off.

A "no strict 'refs'" is not necessary.



Re: How do my handler call dynamically a module based the request input

Posted by Steve Piner <st...@marketview.co.nz>.
OK, I can see it now.

The trick I used with the method call in my previous e-mail won't work
here - it only works for methods.

I think you'll have to have a "no strict 'refs'" in there somewhere, as
you are using soft references, which is exactly what "use strict" turns
off.

I thought about a few alternatives, such as using eval, but the
resulting code is much worse than adding that one line.


Steve



Harry Zhu wrote:
> 
> Nope. Even simple code like following will give me error.
> 
> I have some code like:
> 
> ##### GL/B1.pm
> package GL::B1;
> use strict;
> use vars qw($c);
> $c = {
>   x => {
>    t => 1,
>  },
>  ...
> };
> 
> 1;
> 
> ##### GL/B.pm
> ##### GL/B.pm
> package GL::B;
> use strict;
> sub handler {
>   my $b = shift;
> 
> ##### it worked if "use strict" is commented out, otherwise run-time error;
>  my $c = "GL::${b}::c"; my %x = %{${$c}->{x}};
> 
>  ##### it worked, but needs "no strict"; a little bit awkward
> # my %x; {no strict; %x = %{${"GL::${b}::c"}->{x}}; }
> 
> ##### it worked under "use strict"; not usable if the B1 should be dynamical
> # my %x = %{$GL::B1::c->{x}};
> 
>   my $t = $x{t}*2;
>   print $t;
> 
> }
> 
> 1;
> 
> Compiled no problem with "use strict", but when I run
>  > perl -e 'use GL::B1 qw($c);use GL::B; &GL::B::handler();'
> 
> It gives the error:
> Can't use string ("GL::B1::c") as a SCALAR ref while "strict refs" in use at
> GL/B.pm line 7.
> 
> Seems the problem has nothing to do with "call different module
> dynamically". Although if not for the dynamical call, it would directly
> %x = %{$GL::B1::c->{x}};
> 
> What can I do to use always the "use strict" and handle such situation?
> 
> Harry
> 
> ----- Original Message -----
> From: "Steve Piner" <>
> To: "Harry Zhu" <ha...@greatlodge.com>
> Cc: <mo...@perl.apache.org>
> Sent: Monday, August 05, 2002 3:33 PM
> Subject: Re: How do my handler call dynamically a module based the request
> input
> 
> >
> > 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" <rl...@aol.net>
> > > To: <mo...@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
> >

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

Re: How do my handler call dynamically a module based the request input

Posted by Harry Zhu <ha...@GreatLodge.COM>.
Nope. Even simple code like following will give me error.

I have some code like:

##### GL/B1.pm
package GL::B1;
use strict;
use vars qw($c);
$c = {
  x => {
   t => 1,
 },
 ...
};

1;

##### GL/B.pm
##### GL/B.pm
package GL::B;
use strict;
sub handler {
  my $b = shift;

##### it worked if "use strict" is commented out, otherwise run-time error;
 my $c = "GL::${b}::c"; my %x = %{${$c}->{x}};

 ##### it worked, but needs "no strict"; a little bit awkward
# my %x; {no strict; %x = %{${"GL::${b}::c"}->{x}}; }

##### it worked under "use strict"; not usable if the B1 should be dynamical
# my %x = %{$GL::B1::c->{x}};

  my $t = $x{t}*2;
  print $t;

}

1;

Compiled no problem with "use strict", but when I run
 > perl -e 'use GL::B1 qw($c);use GL::B; &GL::B::handler();'

It gives the error:
Can't use string ("GL::B1::c") as a SCALAR ref while "strict refs" in use at
GL/B.pm line 7.

Seems the problem has nothing to do with "call different module
dynamically". Although if not for the dynamical call, it would directly
%x = %{$GL::B1::c->{x}};

What can I do to use always the "use strict" and handle such situation?

Harry


----- Original Message -----
From: "Steve Piner" <>
To: "Harry Zhu" <ha...@greatlodge.com>
Cc: <mo...@perl.apache.org>
Sent: Monday, August 05, 2002 3:33 PM
Subject: Re: How do my handler call dynamically a module based the request
input


>
> 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" <rl...@aol.net>
> > To: <mo...@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
>



Re: How do my handler call dynamically a module based the request input

Posted by Steve Piner <st...@marketview.co.nz>.
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" <rl...@aol.net>
> To: <mo...@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

Re: How do my handler call dynamically a module based the request input

Posted by Harry Zhu <ha...@GreatLodge.COM>.
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" <rl...@aol.net>
To: <mo...@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
>



Re: How do my handler call dynamically a module based the request input

Posted by Robert Landrum <rl...@aol.net>.
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

Re: How do my handler call dynamically a module based the request input

Posted by Harry Zhu <ha...@GreatLodge.COM>.
For my situation I would probably stick the recursive foreach loop copy for
now since I don't need other functionality in the Storable module. I was
looking for a simpler statement to do such a simple job, something like $A =
hash_clone($B), where hash_clone is some function built in some core modules
in Perl/Apache/mod-perl, so no additional modules needed to be installed.

Harry

----- Original Message -----
From: "Steve Piner" <st...@marketview.co.nz>
To: "Harry Zhu" <ha...@GreatLodge.COM>; "mod_perl" <>
Sent: Tuesday, August 06, 2002 3:02 PM
Subject: Re: How do my handler call dynamically a module based the request
input


>
> Please reply to the mod_perl list as well: I don't know everything, and
> other people on the list can help if I get  details incorrect.
>
> Harry Zhu wrote:
> >
> > Nice to know that it exists a module Storable to copy recursively the
> > complicated data structure.
> > But looks like the it does the same thing as the recursive foreach loop.
> >
> > Thanks,
> > Harry
>
> Yes, but it is simpler for you to use, and works for bigger, more
> complicated structures.
>
> I'm sorry, did this answer your question? If not, could you perhaps try
> rephrasing it.
>
> Steve
>
> > ----- Original Message -----
> > From: "Steve Piner" <st...@marketview.co.nz>
> > To: "Harry Zhu" <ha...@greatlodge.com>
> > Cc: <mo...@perl.apache.org>
> > Sent: Monday, August 05, 2002 3:43 PM
> > Subject: Re: How do my handler call dynamically a module based the
request
> > input
> >
> > >
> > >
> > > Harry Zhu wrote:
> > >
> > > [first question deleted]
> > >
> > > > in module A::B, and if I do
> > > > my %b = %{$A::B::c->{b}};
> > > > and then even if I manipulate on %b, I found the $A::B::c also
changed
> > > > from other module calls.
> > > > for example, if $t = $b{a}{a3}; it will added a key a3 to the hash
> > > > %{A::B::c->{b}{a}} !
> > > >
> > > > This probably due to the reference of $A::B::c->{b}. I know if,
> > > > instead,
> > > > my %b = (),
> > > > foreach $b (keys %{$A::B::c->{b}}) {
> > > >   foreach (keys %{$A::B::c->{b}{$b}}) {
> > > >     $b{$b}{$_} = $A::B::c->{b}{$b}{$_};
> > > >   }
> > > > }
> > > >
> > > > and it will not affact the $A::B::c what ever you do with the %b. Is
> > > > the a simple way to copy only in values the hash of hash?
> > > >
> > > >
> > > > Harry Zhu
> > > > GreatLodge.com
> > >
> > > perldoc -q 'How do I print out or copy a recursive data structure'
> > >
> > > Hope this helps
> > >
> > > --
> > > Steve Piner
> > > Web Applications Developer
> > > Marketview Limited
> > > http://www.marketview.co.nz
> > >
>
> --
> Steve Piner
> Web Applications Developer
> Marketview Limited
> http://www.marketview.co.nz
>



Re: How do my handler call dynamically a module based the request input

Posted by Steve Piner <st...@marketview.co.nz>.
Please reply to the mod_perl list as well: I don't know everything, and
other people on the list can help if I get  details incorrect.

Harry Zhu wrote:
> 
> Nice to know that it exists a module Storable to copy recursively the
> complicated data structure.
> But looks like the it does the same thing as the recursive foreach loop.
> 
> Thanks,
> Harry

Yes, but it is simpler for you to use, and works for bigger, more
complicated structures.

I'm sorry, did this answer your question? If not, could you perhaps try
rephrasing it.

Steve

> ----- Original Message -----
> From: "Steve Piner" <st...@marketview.co.nz>
> To: "Harry Zhu" <ha...@greatlodge.com>
> Cc: <mo...@perl.apache.org>
> Sent: Monday, August 05, 2002 3:43 PM
> Subject: Re: How do my handler call dynamically a module based the request
> input
> 
> >
> >
> > Harry Zhu wrote:
> >
> > [first question deleted]
> >
> > > in module A::B, and if I do
> > > my %b = %{$A::B::c->{b}};
> > > and then even if I manipulate on %b, I found the $A::B::c also changed
> > > from other module calls.
> > > for example, if $t = $b{a}{a3}; it will added a key a3 to the hash
> > > %{A::B::c->{b}{a}} !
> > >
> > > This probably due to the reference of $A::B::c->{b}. I know if,
> > > instead,
> > > my %b = (),
> > > foreach $b (keys %{$A::B::c->{b}}) {
> > >   foreach (keys %{$A::B::c->{b}{$b}}) {
> > >     $b{$b}{$_} = $A::B::c->{b}{$b}{$_};
> > >   }
> > > }
> > >
> > > and it will not affact the $A::B::c what ever you do with the %b. Is
> > > the a simple way to copy only in values the hash of hash?
> > >
> > >
> > > Harry Zhu
> > > GreatLodge.com
> >
> > perldoc -q 'How do I print out or copy a recursive data structure'
> >
> > Hope this helps
> >
> > --
> > Steve Piner
> > Web Applications Developer
> > Marketview Limited
> > http://www.marketview.co.nz
> >

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

Re: How do my handler call dynamically a module based the request input

Posted by Steve Piner <st...@marketview.co.nz>.

Harry Zhu wrote:

[first question deleted]

> in module A::B, and if I do
> my %b = %{$A::B::c->{b}};
> and then even if I manipulate on %b, I found the $A::B::c also changed
> from other module calls.
> for example, if $t = $b{a}{a3}; it will added a key a3 to the hash
> %{A::B::c->{b}{a}} !
> 
> This probably due to the reference of $A::B::c->{b}. I know if,
> instead,
> my %b = (),
> foreach $b (keys %{$A::B::c->{b}}) {
>   foreach (keys %{$A::B::c->{b}{$b}}) {
>     $b{$b}{$_} = $A::B::c->{b}{$b}{$_};
>   }
> }
> 
> and it will not affact the $A::B::c what ever you do with the %b. Is
> the a simple way to copy only in values the hash of hash?
> 
> 
> Harry Zhu
> GreatLodge.com

perldoc -q 'How do I print out or copy a recursive data structure'

Hope this helps

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