
jon+catalyst at youramigo
Mar 5, 2008, 3:57 PM
Post #2 of 3
(316 views)
Permalink
|
On Wed, 2008-03-05 at 11:34 -0700, Travis Chase wrote: > A refined focus of what Catalyst::View::CSV was to be apart of. Note: > Catalyst::View::CSV will move forward, it is instead a part of this > package as Catalyst::View::Download::CSV. Also note, I intend to add > more downloadable formats besides the simple ones (CSV, Plain) I have > listed. > Travis, I have implemented something similar locally, being a wrapper around Text::Table, Text::CSV_XS and Spreadsheet::WriteExcel to support text, csv and excel respectively. There are other wrappers on CPAN which I reviewed at the time but I found them to either have bugs w.r.t. functionality I needed, or to do things in a way which were cumbersome w.r.t. my requirements, or to not support the cross-section of formats needed. In any case it's not much extra code. I'm not making any great claims about my implementation, just trying to provide food for thought. I found it useful to support multiple worksheets (as in the spreadsheet concept), and to provide for metadata (title, sheet name, column headers, notes) as well as the data itself. The API works something like this: use Local::Tabular; my @reports = ( { title => "Top 10 Wines, by Region", sheetname => "Top Wines", headers => [ "Region", "Name", "No of. Top 10 Results" ], data => \@data, }, { add more worksheets here in similar vein ... }, ); my $output = Local::Tabular->new(format => ’txt’, outfile => $file); $output->print(\@reports); $output->close(); The Catalyst view is then a wrapper around the above, where @reports is placed in the stash as you have done with $c->stash->{'csv'}. (Note that if you end up using Spreadsheet::WriteExcel, all UTF8 strings need to be encoded as bytes first.) Another handy feature is to be able to specify data either row-wise or column-wise. Regards, -- Jon Schutz My tech notes http://notes.jschutz.net Chief Technology Officer http://www.youramigo.com YourAmigo _______________________________________________ Catalyst-dev mailing list Catalyst-dev[at]lists.scsys.co.uk http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst-dev
|