Subject: | Feature: specify filename of CSV file |
Here's a patch to the 1.1.2 distribution to allow setting the filename of the resulting CSV file:
$ diff -u CSV.pm.orig CSV.pm
--- CSV.pm.orig 2011-08-04 11:48:00.000000000 +1000
+++ CSV.pm 2011-08-04 11:47:07.000000000 +1000
@@ -71,6 +71,12 @@
Set to C<undef> to prevent any manipulation of the filename suffix.
+=head2 filename
+
+The filename for the generated CSV file. If not specified, it will
+default to the last path segment of the request URI. This works in
+conjunction with the C<suffix> option.
+
=head2 charset
The character set stated in the MIME type of the downloaded CSV file.
@@ -226,7 +232,8 @@
my $cursor = $c->stash->{cursor};
# Determine resulting CSV filename
- my $filename = [ $c->req->uri->path_segments ]->[-1];
+ my $filename = $c->stash->{filename} ||
+ [ $c->req->uri->path_segments ]->[-1];
if ( $suffix ) {
$filename =~ s/\.[^.]*$//;
$filename .= ".".$suffix;