NAME

Class::PObject::Driver::csv - CSV Pobject Driver

SYNOPSIS

use Class::PObject;
pobject Person => {
    columns => ['id', 'name', 'email'],
    driver  => 'csv',
    datasource => {
        Dir => 'data/',
        Table => 'person'
    }
};

DESCRIPTION

Class::PObject::Driver::csv is a direct subclass of Class::PObjecet::Driver::DBI. It inherits all the base functionality needed for all the DBI-related classes. For details of these methods and their specifications refer to Class::PObject::Driver and Class::PObject::Driver::DBI.

DATASOURCE

datasource attribute should be in the form of a hashref. The following keys are supported

  • Dir - points to the directory where the CSV files are stored. If this is missing will default to your system's temporary folder. If the Dir is provided, and it doesn't exist, it will be created for you.

  • Table - defines the name of the table that objects will be stored in. If this is missing will default to the name of the object, non-alphanumeric characters replaced with underscore (_).

METHODS

Class::PObject::Driver::csv (re-)defines following methods of its own

  • dbh() base DBI method is overridden with the version that creates a DBI handle through DBD::CSV.

  • save() either builds a SELECT SQL statement by calling base _prepare_select() if the object id is missing, or builds an UPDATE SQL statement by calling base _prepare_update().

    If the ID is missing, calls generate_id() method, which returns a unique ID for the object.

  • generate_id($self, $pobject_name, \%properties) returns a unique ID for new objects. This determines the new ID by performing a SELECT id FROM $table ORDER BY id DESC LIMIT 1 SQL statement to determine the latest inserted ID.

  • _tablename($self, $pobject_name, \%properties)

    Redefines base method _tablename(). If the table is missing, it will also create the table for you.

NOTES

csv driver can get incredibly processor intensive once the number of records exceeds 1,000. This can be fixed by providing indexing functionality to the driver, which it currently misses.

Main issue of the driver is in its save() method, where it first needs to SELECT the records to find out if the record being inserted exists or not. Then, depending on its discoveries either runs INSERT or UPDATE queries.

generate_id() method could also be improved by allowing it to keep track of record count in a separate file.

All these issues need to be addressed in subsequent releases of the library.

SEE ALSO

Class::PObject, Class::PObject::Driver::mysql, Class::PObject::Driver::file

COPYRIGHT AND LICENSE

For author and copyright information refer to Class::PObject's online manual.