NAME
Class::PObject::Driver::file - default driver for Class::PObject
SYNOPSIS
pobject Person => {
columns => ['id', 'name', 'email'],
driver => 'file',
datasource=> 'data/person'
};
DESCRIPTION
Class::PObject::Driver::file is a default driver used by Class::PObject. The only required class property is 'columns'. If 'driver' is missing, Class::PObject will default to 'file' automatically. If 'datasource' is missing, the driver will default to system's temporary directory, which is /tmp on most *nix systems, and C:\TEMP on Windows.
This data source is a folder in your operating system, inside which objects will store themselves. So it's required each object to have its own distinctive data source location.
OBJECT STORAGE
Each object is stored as a separate file. Each file has the same format as "obj%05d.cpo" where "%05d" will be replaced with the id of the object, zeros padded if necessary. Extension '.cpo' stands for Class::PObject.
SERIALIZATION
Objects are serialized using standard Data::Dumper and is represented as a hash-table.
ID GENERATION
'file' driver keeps its own record counter for generating auto-incrementing values for subsequent records more efficiently. Record counter is stored inside the 'datasource' folder in a file called "counter.cpo". Newly created records should not be passed any ids, for it my cause undocumented problems.
In case the record counter is deleted accidentally, the driver doesn't re-create it, but I believe some sort of safety net should be added.
NOTES
Since the driver doesn't keep an index of any kind, the most efficient way of loading the data is by its id or by simple load() syntax. load(undef, {limit=>n}) should also be fast:
my $p = Person->load(451);
my @people = Person->load();
my @group = Person->load(undef, {limit=>100});
as load() becomes complex, the performance gets degrading:
my @people = Person->load({name=>"Sherzod"}, {sort=>'age', direction=>'desc', limit=>10, offset=>4});
To perform the above search, the driver walks through all the objects available in the 'datasource', pushes all the objects matching 'name="sherzod"' to the stack, then, just before returning the data set, performs sort, limit and offset calculations. As you could imagine, as the number of objects in the datasource increases, this operation may become more and more costly.
SEE ALSO
Class::PObject, Class::PObject::Driver::mysql, Class::PObject::Driver::file
AUTHOR
Sherzod Ruzmetov <sherzodr@cpan.org>