Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Example using CGI::Application::Plugin::Output::XSV

by davebaker (Pilgrim)
on May 05, 2020 at 02:53 UTC ( [id://11116469]=note: print w/replies, xml ) Need Help??


in reply to Example using CGI::Application::Plugin::Output::XSV

Your code is a snippet that is designed to work as part of a CGI script that you'd put on a web server and run via a web browser. The CGI script would be written to work with a framework called CGI::Application. So to run your code you'll need to install CGI::Application and a module called CGI::Application::Plugin::Output::XSV -- both are available at metacpan.org

Here's how I am able to get your snippet to work:

First I create a file named index.cgi which I put into a directory named /www/cgi-bin/MyOutputXSV

My perl executable (filename is perl) is in a directory called /opt; change the first line of the script to point to the installed perl executable file on your web server.

#!/opt/perl use strict; use warnings; use lib ( '/www/cgi-bin/MyOutputXSV' ); use MyOutputXSV; my $app = MyOutputXSV->new(); $app->run();
Next I create a file named MyOutputXSV.pm and put it into that same directory:
package MyOutputXSV; use strict; use warnings; use parent 'CGI::Application'; use CGI::Application::Plugin::Output::XSV qw(:all); # headers generated will be [ "first", "last", "phone" ] sub setup { my $self = shift; $self->run_modes( 'generate_report' => 'generate_report', ); $self->start_mode('generate_report'); } sub generate_report { my $self = shift; return $self->xsv_report_web({ values => [ { first_name => 'Jack', last_name => 'Tors', phone => '555-1212' }, { first_name => 'Frank', last_name => 'Rizzo', phone => '555-1515' }, ], fields => [ qw(first_name last_name phone) ], headers_cb => sub { my @h = @{ +shift }; s/_name$// foreach @h; return \@h; }, }); } 1;
Next I change the Linux file permissions on index.cgi to be 705 (which lets my Apache web server read and execute the script) and then I run the script by entering https://mysitename.com/cgi-bin/MyOutputXSV/index.cgi into my web browser.

The script then returns data as a binary file named download.csv, which my browser detects and uses to present a popup box to me that asks what program I'd like to use to open it. I have Excel on my Windows 10 PC so that's what I tell the browser. Then Excel opens and I see the data in a 3x3 set of cells:

first last phone Jack Tors 555-1212 Frank Rizzo 555-1515

Replies are listed 'Best First'.
Re^2: Example using CGI::Application::Plugin::Output::XSV
by logangha (Acolyte) on May 08, 2020 at 18:31 UTC

    A lot of thanks davebaker !!!
    I will prove it
    And I will let you know if I can make it

      Super!

      If you've never installed a Perl module before, you might want to go with one of the shorter alternatives presented later in this thread. I was just wanting to make the snippet work, which would require the other modules.

      Installing Perl modules often isn't as simple as copying files from metacpan.org -- instead, you'd typically want to use a utility program called cpan or cpanm that is run from a command line. If you have Perl already installed, you might be able to do that. You'd type "cpan CGI::Application" and then (after that module and any dependencies are installed automatically) "cpan CGI::Aplication::Plugin::Output::XSV" (without the quotation marks).

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11116469]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (7)
As of 2024-04-23 19:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found