Persistent::Base - An Abstract Persistent Base Class
### we are a subclass of ... ### use Persistent::Base; @ISA = qw(Persistent::Base);
This is an abstract class used by the Persistent framework of classes to implement persistence with various types of data stores. This class provides the methods and interface for implementing Persistent classes. Refer to the Persistent documentation for a very thorough introduction to using the Persistent framework of classes.
This class is part of the Persistent base package which is available from:
http://www.bigsnow.org/persistent ftp://ftp.bigsnow.org/pub/persistent
Before we get started describing the methods in detail, it should be noted that all error handling in this class is done with exceptions. So you should wrap an eval block around all of your code. Please see the Persistent documentation for more information on exception handling in Perl.
eval { ### set the data store ### $person->datastore(@args); ### get the data store ### $href = $person->datastore(); }; croak "Exception caught: $@" if $@;
Returns (and optionally sets) the data store of the object. This method throws Perl execeptions so use it with an eval block.
Setting the data store can involve anything from initializing a connection to opening a file. Getting a data store usually means returning information pertaining to the data store in a useful form, such as a connection to a database or a location of a file.
This method requires implementing.
Parameters:
Returns:
eval { $person->insert(); }; croak "Exception caught: $@" if $@;
Inserts an object into the data store. This method throws Perl execeptions so use it with an eval block.
See the Persistent documentation for more information.
eval { $person->delete(); }; croak "Exception caught: $@" if $@;
Deletes an object from the data store. This method throws Perl execeptions so use it with an eval block.
Values of the Identity attributes of the object. This argument is optional and will default to the Identifier values of the object as the default.
A true value if the object previously existed in the data store (it was deleted), and a false value if not (nothing to delete).
use Persistent::File; eval { my $person = new Persistent::File('people.txt', '|'); $person->restore_where( "lastname = 'Flintstone' and telnum =~ /^[(]?650/", "lastname, firstname, telnum DESC" ); while ($person->restore_next()) { print "Restored: "; print_person($person); } }; croak "Exception caught: $@" if $@;
Restores objects from the data store that meet the specified conditions. The objects are returned one at a time by using the restore_next method and in a sorted order if specified. This method throws Perl execeptions so use it with an eval block.
Since this is a Perl implemented Persistent class, the restore_where method expects all patterm matching to use Perl regular expressions.
Conditional expression for the requested objects. The format of this expression is similar to a SQL WHERE clause. This argument is optional.
Sort expression for the requested objects. The format of this expression is similar to a SQL ORDER BY clause. This argument is optional.
The number of objects that match the conditions.
Persistent, Persistent::Base, Persistent::DBM, Persistent::File, Persistent::Memory
This software is definitely a work in progress. So if you find any bugs please email them to me with a subject of 'Persistent Bug' at:
winters@bigsnow.org
And you know, include the regular stuff, OS, Perl version, snippet of code, etc.
David Winters <winters@bigsnow.org>
Copyright (c) 1998-2000 David Winters. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Persistent::Base, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Persistent::Base
CPAN shell
perl -MCPAN -e shell install Persistent::Base
For more information on module installation, please visit the detailed CPAN module installation guide.