artist has asked for the wisdom of the Perl Monks concerning the following question:

I have started using CGI::Application and like to know how I can pass arguments to this application ? My code can explain little better to the familiars with this module.
package main; use MyApp; my $app = MyApp->new(id=> '123'); $app->run(); package MyApp; use base CGI::Application; sub setup { my $self = shift; my $query = $self->query(); my $id = $query->param('id'); }
In the above code, I don't have way to check the value of $id. I like to make value of $id available to all the run modes. How I can do that? I need to pass the 'id' from the main application, because I am getting it from another application via CGI.

Thanks,
artist.

Replies are listed 'Best First'.
Re: CGI::Application question
by Limbic~Region (Chancellor) on Mar 22, 2005 at 21:07 UTC
    artist,
    First you need to understand that $self->param() ne $self->query()->param(). The former is more like a internal scratch pad available to all run-modes while the latter is the CGI query parameter method.
    sub setup { my $self = shift; $self->param('id' => 123); }
    Not knowing what you are trying to accomplish, you may also want to look into CGI::Session.

    Cheers - L~R

Re: CGI::Application question
by johnnywang (Priest) on Mar 22, 2005 at 21:03 UTC
    you can pass in parameters in new:
    my $app = MyApp->new(PARAMS=>{'id'=>123}); # then access it as: my $id = $app->param('id');
    Check the perldoc for CGI::Application.
Re: CGI::Application question
by dragonchild (Archbishop) on Mar 22, 2005 at 21:00 UTC
    Every runmode can do $self->query(). In addition, you can set it with $self->param( 'id' => $id ); in setup() and get it later, if you want.

    Being right, does not endow the right to be rude; politeness costs nothing.
    Being unknowing, is not the same as being stupid.
    Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
    Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.

Re: CGI::Application question
by kprasanna_79 (Hermit) on Mar 23, 2005 at 06:03 UTC