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

Juan Jose Natera naterajj at gmail.com
Mon Oct 23 22:38:43 PDT 2006


make that:

eval "require $action" && $data->{body} = $action->generate_page();

On 10/23/06, Juan Jose Natera <naterajj at gmail.com> wrote:
> Hi,
>
> One way of doing this is:
>
> my $action = CGI::param('action');
> eval 'require $action;' && $data->{body} = $action->generate_page();
>
> given that $action contains the name of your module, say 'PageA'.
>
> package PageA;
> use strict;
> use warnings;
>
> sub generate_page {
>     my $class = shift;
>    # generate the page here
> }
>
> 1;
>
> This has a few holes though, what if the user forces $action to be
> something undersirable? what if you forgot to create generate_page? or
> if you misspelled it? etc.
>
> You'll be better off by using an existing web framework, like
> CGI::Prototype or CGI::Application.
>
> Regards,
>
> JJ
>
> On 10/23/06, benh <ben.hengst at gmail.com> wrote:
> > So I'm building a small site for a client. Durring the process I
> > started playing with the idea that every page is a module, there are
> > some that just needed to be text, others that needed to do things.
> > Though, things didn't go as easily as I would have liked, and I ended
> > up going about things the longer way to make it all go. But I was
> > wondering if there was a cleaner/better way of doing this.
> >
> > The crux of things is that I am attempting to use a var to call these
> > module/pages. So I was hopeing for something along the lines of:
> >
> > my $action=CGI::param('action');
> > $data->{'body'}=local::$action::generate_page_data();
> >
> > problem is that I get a 'bad name after local::' error.
> >
> > So my second go was to use require, and then just call
> > generate_page_data(). But it looks like require doesn't append to name
> > space the way use does so I keep getting undefined subroutine
> > &main::generate_page_data();
> >
> > so in the end I just ditched things and built subs in page and called
> > them... it works but its not as elegant as I would like it to be....
> > so I'm tossing this out to the group. How would you have solved this
> > kinda problem? Is my thinking off? I think that it's an idea that I
> > want to take another stab at but just looking for some input.
> >
> > thanks
> > --
> > benh~
> > _______________________________________________
> > Pdx-pm-list mailing list
> > Pdx-pm-list at pm.org
> > http://mail.pm.org/mailman/listinfo/pdx-pm-list
> >
>


More information about the Pdx-pm-list mailing list