SLOOPS::Factory - a general persistent object managing class.
This is the main class to use this persistance framework. Use it to seek objects, to save them, to delete them ...
jerome@eteve.net
use SLOOPS::Factory [ { debug => 0|1 } ];
my $f = SLOOPS::Factory->instance();
[ $f->setCache(0|1) ; ]
[ my $dbDriver = # A valid dbDriver ; # Only one time needed for the life of the instance. $f->dbDriver($dbDriver); ]
# Then use the methods..
Sets the cache on 1 /off 0 : $f->setCache(1); $f->setCache(0);
Setting the cache on allows to get always the same instance of object that old exactly the same data when you fetch object.
Usage:
my $o = $f->createObject("ObjectClass");
Fetch an object of class $oclass identified by $id from the database.
usage :
my $o = $f->fetchObject($oclass,$id);
Utility function. Returns the base class of any persistent class.
Fetch the object $dbid. $oclass is the real class of this object.
Stores the object in the database and add an _dbid_ to it. If _dbid_ is allready set, redirect to syncObject .
Returns the object database id (_dbid_)
SQL equiv: insert.
Synchronize the object value with the database. Returns the object database id ( _dbid_ )
SQL equiv: update.
Removes the object from the database.
Empty the object from all database properties, turning it into a plain perl-space object.
SQL equiv: delete
Returns the only instance found with the given constraints and existence. Returns Undef if none found. Dies if more than one instance is found.
my $contraints = { ... } ; # See seekIds for syntax my $existences = { ... } ; # See seekIds for syntax
my $o = $f->find($class,$constraints,$existences);
Returns a newly created object with the equality constraints and the reference constraints used to initiate the object if it doesn't exists in the database.
Returns the object from the database if it's allready there.
Dies if more than one object fullfills the given constraints.
my $o = $f->findOrCreate($class,$constraints,$existences);
Same usage as seekIds, but return a set of allready constructed objects.
Returns a collection of id of object for the class $class in the database. These object matches the constraints.
Contraints can concern super class attributes and references.
my $constraint = { 'field1' => [ $operator , $value ], ... 'reference1' => $referencedObject };
my $existence = { 'field1' => 'exist' , # Field is set 'field2' => undef , # field is not set 'reference1' => 'exist' , # idem 'reference2' => undef # idem ... };
my $ids = $self->seekIds('ClassName' , $constraint , $existence );
Finds the distinct values of the given $field in the instances of the $class that match the constraints $constraints and $existence like in seekIds .
If $field is a name of reference instead of a plain field, it returns the collection of corresponding object.
my $ObjsOrScalars = $f->findDistinctFieldsFrom($field , $class , $constraints , $existence );
To install SLOOPS, copy and paste the appropriate command in to your terminal.
cpanm
cpanm SLOOPS
CPAN shell
perl -MCPAN -e shell install SLOOPS
For more information on module installation, please visit the detailed CPAN module installation guide.