[Pdx-pm] I think that I'm trying to make things too hard.

Eric Wilhelm scratchcomputing at gmail.com
Mon Oct 23 23:05:10 PDT 2006


# from benh
# on Monday 23 October 2006 09:59 pm:

>local::$action::generate_page_data();

To get what you were trying to get here, that would have to be

  my $subref = eval('\&local::' . $action . '::generate_page_data');
  $subref->();

Juan's is a bit cleaner, but you'll need to build your subs as methods.

Either way, you're using a string eval though, so I hope $action has 
been detainted.  Given that there was no require() in your original 
code, maybe this stuff has already been loaded.  Thus, you could skip 
the string eval if you just use it as a class name.

  my $class = 'local::' . $action;
  eval { $class->can('generate_page_data') } or
    croak("invalid action '$action'");
  $data->{'body'} = $class->generate_page_data;

I prefer that.  You'll still need to add "my $class = shift;" to the 
front of the generate_page_data() definition.

--Eric
-- 
Turns out the optimal technique is to put it in reverse and gun it.
--Steven Squyres (on challenges in interplanetary robot navigation)
---------------------------------------------------
    http://scratchcomputing.com
---------------------------------------------------


More information about the Pdx-pm-list mailing list