Sherzod Ruzmetov > Class-PObject > Class::PObject::Driver::file

Download:
Class-PObject-2.17.tar.gz

Dependencies

Annotate this POD

CPAN RT

New  3
Open  0
View/Report Bugs
Module Version: 2.00   Source  

NAME ^

Class::PObject::Driver::file - Default PObject driver

SYNOPSIS ^

    pobject Person => {
        columns   => ['id', 'name', 'email']
        datasource=> 'data',
        serializer => 'xml'
    };

DESCRIPTION ^

Class::PObject::Driver::file is a default driver used by Class::PObject. Class::PObject::Driver::file is a direct subclass of Class::PObject::Driver. Refer to its manual for more details.

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 your 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 be stored. Pobject will create a folder for each object type inside the datasource folder, and will store all the objects of the same type in their own folders.

Other supported property is serialiazer, which defaults to storable if the value is missing. This serializer defines the serializing and de-serializing method used by object driver. Possible values are xml, which requires XML::Dumper to have been installed, and dumper, which requires Data::Dumper and 'storable'.

SUPPORTED FEATURES ^

Class::PObject::Driver::file overrides following methods of Class::PObject::Driver

In addition to standard methods, it also defines following methods of its own. These methods are just private/utility methods that are not invoked by PObjects directly. But knowledge of these methods may prove useful if you want to subclass this driver to cater it to your needs.

OBJECT STORAGE ^

Each object is stored as a separate file. File name pattern for each object file is defined in $Class::PObject::Driver::file::f global variable, and is obj%05.cpo by default, where %05 will be replaced with the id of the object, zero-padded if necessary.

Note: extension '.cpo' stands for Class::PObject.

SERIALIZATION ^

Objects are serialized and de-serialized with the help of freeze() and thaw() methods provided by its base class, Class::PObject::Driver.

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 object directory (_dir() method returns the path to this folder) in a file called "counter.cpo".

WARNING

Removing counter.cpo from the directory will force PObject to reset object ids. This may be a problem if there already are objects in the directory, and they may be overridden by new ids. I realize this is a scary limitation, which will eventually be addressed.

In the meanwhile, just don't make habit of removing counter.cpo :-).

EFFICIENCY ^

Since the driver doesn't keep an index of any kind, the most efficient way of loading the data is by its id. A relatively simple load(undef, {limit=n})> syntax is also reasonably efficient.

    $p       = Person->load(451);
    @people  = Person->load();
    @group   = Person->load(undef, {limit=>100});

as load() becomes complex, the performance gets degrading:

    @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 data-set, then, just before returning the data set, performs sort, limit and offset calculations.

As you imagine, as the number of objects in the datasource increases, this operation will become more costly.

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.

syntax highlighting: