How can I provide a temp file download using mod_perl and CGI::Application?
You shouldn't need to mess with STDOUT
; CGI-App should handle that properly for you under the hood. You'll also may need to close the filehandle before you try to send the data.
It looks like you're not setting a proper content type for the Excel data, though. For anything other than text/html, you'll need to set it manually. Try something like this:
sub export_list {
my $self = shift;
my $str;
open my $fh, '>', \$str or die "Can't open to var: $!";
my $workbook = Spreadsheet::WriteExcel->new($fh);
my $worksheet = $workbook->add_worksheet();
$worksheet->write_col(0,0, ['some','data','here']);
$workbook->close;
close $fh;
warn $str;
$self->header_add( -type => 'application/vnd.ms-excel' );
return $str;
}
You may also be interested in CGI::Application::Plugin::Stream
Write a simple mod_perl handler
This is just an example. You need to create the files yourself. (You'll see your example refers to "file:MyApache2/CurrentTime.pm").
mkdir -p example-lib/MyApache2
touch example-lib/MyApache2/CurrentTime.pm
Then paste the contents from the example into the file you just created.
In order for this to run under mod_perl, you'll also have to let the server know where your MyApache2 is located. You should be able to add something like this to your Apache config:
PerlSwitches -I/path/to/example-lib
Don't forget to restart Apache before you test this out.
How to install mod_perl 2.0.9 in Apache 2.4 on OS X Yosemite?
mod_perl 2.0.8 (latest stable) won't cut it--it's unaware of the deprecation of MPM_NAME in apache 2.4.x
Download the latest dev via svn:
svn checkout https://svn.apache.org/repos/asf/perl/modperl/trunk/ mod_perl-2.0
The Changes file lists this version as 2.0.9-dev
Xcode 6.01 won't cut it--it's apache headers will make mod_perl think you're running apache 2.2.26; get Xcode 6.1 (released Oct 20).
Makefile.PL will still have trouble finding ap_release.h (to get your apache version). It's here:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/apache2/ap_release.h
Makefile.PL will look by default in /usr/include/apache2
. It will also look for apr headers in /usr/include/apr-1
because the Yosemite-included /usr/bin/apr-1-config
will tell it that's where they are (they're actually in /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/apr-1
)
/usr/bin/apr-1-config --includedir
/usr/include/apr-1
I tried setting env vars MP_AP_PREFIX
and MP_APR_CONFIG
appropriately, but those values seemed to be ignored. So I made things easier on myself:
$ sudo ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/apache2 /usr/include/apache2
$ sudo ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/apr-1 /usr/include/apr-1
(thanks to Sean Coyne) Per Jason A. Crome's blog post
"llvm/clang on OS X defaults to C99, but mod_perl expects the 89 "standard"
$ perl Makefile.PL MP_CCOPTS=-std=gnu89; make ; sudo make install
The LoadModule
line for mod_perl
has been removed from Yosemite's /etc/apache2/httpd.conf
file.
Add
LoadModule perl_module libexec/apache2/mod_perl.so
to the module section of /etc/apache2/httpd.conf
Related Topics
Clearing Large Apache Domain Logs
Linux Module to Hook Process Functions
Iptables Remove Specific Rules by Comment
Detect If Something Is Modified in Directory, and If So, Backup - Otherwise Do Nothing
How to Do "For Each" on Output from Find
How to Dynamic Load The Library with Same Name But in Different Directory in Linux
Find Is Returning "Find: .: Permission Denied", But I Am Not Searching In
Bash Script to Mkdir on Each Line of a File That Has Been Split by a Delimiter
Downgrade R Version and R Package Bioconductor
Is There Any Difference Between '=' and '==' Operators in Bash or Sh
How to Store Multiple Pats/Passwords for Use by Git
How My Custom Module on Linux 3.2.28 Can Make a Call to Print_Cpu_Info
Editing The Sudo File in a Shell Script
Jmeter:Difference Between Jmeter.Sh and Jmeter Without Extension File in Jmeter
Graphics Card Memory Usage in Linux