in reply to Exporting data from database as HTML or CSV
You have data that you get from somewhere and you need to send it to someplace in someformat. So, you have 4 sections of your app:
This is also known as MVC, or Model-View-Controller. You can see where stuff falls.
Now, the way this all works is that you have API boundaries. So, no matter where you get your data, the Model code will return back the exact same data structure. So, you could get your data from a database, a CSV, some RPC call, or any combination of options. But, as far as the rest of the code is concerned, the data has been retrieved in some known structure. And, the same goes for the other pieces.
What does this mean for your question? It's very simple - you should have several Formatter objects that each accept a known data structure. They will then emit the appropriate stuff for the I/O section to send back to the user. In certain circumstances, the formatter may also provide metadata, such as the Content-Type (for webapps).
Template Toolkit or HTML::Template are excellent templating modules. You can use Text::xSV to construct the CSV side of things. If you need, Excel::Template and PDF::Template can be used for other formats. And, other than Text::xSV, they can all take the exact same datastructure, which (coincendentally enough) is the datastructure provided when you do something like:
my $results = $sth->fetchall_arrayref({});
|
|---|