NAME
DBIx::TableLoader::CSV - Easily load a CSV into a database table
VERSION
version 1.001
SYNOPSIS
my $dbh = DBI->connect(@connection_args);
DBIx::TableLoader::CSV->new(dbh => $dbh, file => $path_to_csv)->load();
# interact with new database table full of data in $dbh
In most cases simply calling load() is sufficient, but all methods are documented below in case you are curious or want to do something a little trickier.
There are many options available for configuration. See "OPTIONS" for those specific to this module and also "OPTIONS" in DBIx::TableLoader for options from the base module.
DESCRIPTION
This is a subclass of DBIx::TableLoader that handles the common operations of reading a CSV file (using the powerful Text::CSV (which uses Text::CSV_XS if available)).
This module simplifies the task of transforming a CSV file into a database table. This functionality was the impetus for the parent module (DBIx::TableLoader).
METHODS
new
Accepts all options described in "OPTIONS" in DBIx::TableLoader plus some CSV specific options.
See "OPTIONS".
get_raw_row
Returns $csv->getline($io).
default_name
If the name option is not provided, and the file option is, returns the file basename.
Falls back to 'csv'.
prepare_data
This is called automatically from the constructor to make things as simple and automatic as possible.
Load
csv_classif it is not.Instantiate
csv_classwithcsv_defaultsandcsv_opts.Open the
fileprovided unlessiois passed instead.Discard the first row if
columnsis provided andno_headeris not.
OPTIONS
The most common usage might include these options:
csv_opts- Hashref of options to pass to thenewmethod ofcsv_classSee Text::CSV for its list of accepted options.
file- Path to a csv fileThe file will be opened (unless
iois provided) and its basename will be the default table name (which can be overwritten with thenameoption).
If you need more customization or are using this inside of a larger application you may find some of these useful:
csv- A Text::CSV compatible object instanceIf not supplied an instance will be created using
$csv_class->new(\%csv_opts).csv_class- The class to instantiate ifcsvis not suppliedDefaults to
Text::CSV(which will attempt to load Text::CSV_XS and fall back to Text::CSV_PP).csv_defaults- Hashref of default options forcsv_classconstructorIncludes
{ binary => 1 }(as encouraged by Text::CSV); To turn off thebinaryoption you can pass{ binary => 0 }tocsv_opts. If you are using a differentcsv_classthat does not accept thebinaryoption you may need to overwrite this with an empty hash.io- A filehandle or IO-like object from which to read CSV linesThis will be used as
$csv->getline($io). When providing this option you can still providefileif you want the table name to be determined automatically (but no attempt will be made to openfile).name- Table nameIf not given the table name will be set to the file basename or
'csv'iffileis not provided.no_header- BooleanUsually the first row [header] of a CSV is the column names. If you specify
columnsthis module assumes you are overwriting the usual header row so the first row of the CSV will be discarded. If there is no header row on the CSV (the first row is data), you must setno_headerto true in order to preserve the first row of the CSV.
SEE ALSO
SUPPORT
Perldoc
You can find documentation for this module with the perldoc command.
perldoc DBIx::TableLoader::CSV
Websites
The following websites have more information about this module, and may be of help to you. As always, in addition to those websites please use your favorite search engine to discover more resources.
Search CPAN
RT: CPAN's Bug Tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=DBIx-TableLoader-CSV
AnnoCPAN: Annotated CPAN documentation
CPAN Ratings
CPAN Forum
CPANTS Kwalitee
CPAN Testers Results
CPAN Testers Matrix
Bugs / Feature Requests
Please report any bugs or feature requests by email to bug-dbix-tableloader-csv at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=DBIx-TableLoader-CSV. You will be automatically notified of any progress on the request by the system.
Source Code
http://github.com/magnificent-tears/DBIx-TableLoader-CSV/tree
git clone git://github.com/magnificent-tears/DBIx-TableLoader-CSV.git
AUTHOR
Randy Stauner <rwstauner@cpan.org>
COPYRIGHT AND LICENSE
This software is copyright (c) 2011 by Randy Stauner.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.