Search code examples
perlcgi-application

How can I run a CGI::Application run mode from the command line?


I have a run mode in my CGI::Application web-app that I would like to be able to trigger from the command line so i can automate it. From the web-app's perspective it does some processing then sends the results in an email.

When called from the web interface it passes in a set of parameters (email address, which query to run, date, etc) so these need to be passed in.

How can I construct a call to the CGI::Application app that will be the same as if I ran it from the web?


Solution

  • Upon further digging through the CGI::App and the CGI documentation, it appeared to be more straightforward than I thought. The simplest case (no real argument handling or dealing with the output from the webapp run call) is:

    #!/usr/bin/perl
    
    use strict;
    use warnings;
    
    use CGI;
    use WebApp;
    
    my $cgi = new CGI( \%{@ARGV} );
    
    my $webapp = WebApp->new( QUERY => $cgi );
    $webapp->run();
    

    It just takes a series of space separated name value pairs to create the CGI. You need to pass in the run mode and all the arguments.