Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Eric Folley
May 13, 2005, 6:45 pm
rate this thread
I have written a module called Class::DataStore that I am planning to put on
CPAN. Please take a look at the documentation below and tell me what you
Class::DataStore - Generic OO data storage/retrieval
my %values = ( one => 1, two => 2 );
my $store = Class::DataStore->new( \%values );
# using get/set methods
$store->set( 'three', 3 );
my $three = $store->get( 'three' );
# using AUTOLOAD method
$store->four( 4 );
my $four = $store->four;
my @four = $store->four; # returns a list
my $exists = $store->exists( 'three' ); # $exists = 1
my $data_hashref = $store->dump;
Class::DataStore implements a simple storage system for object data.
This data can be accessed via get/set methods and AUTOLOAD. AUTOLOAD
calls are not added to the symbol table, so using get/set will be
This module was written originally as part of a website framework that
was used for the Democratic National Committee website in 2004. Some of
the implementations here, such as get() optionally returning a list if
called in array context, reflect the way this module was originally used
for building web applications.
Class::DataStore is most useful when subclassed. To preserve the
AUTOLOAD functionality, be sure to add the following when setting up the
use base 'Class::DataStore';
*AUTOLOAD = \&Class::DataStore::AUTOLOAD;
new( $data_hashref )
The $data_hashref is stored in $self->. Returns the blessed
exists( $key )
Returns 1 if the $key exists in the $self-> hashref. Otherwise,
get( $key )
Returns the value of $self->->, or undef.
If the value is stored as an ARRAYREF or a scalar, and wantarray is
true, the return value will be a list. Otherwise, the value will be
set( $key => $value )
Sets $self->-> to $value, and returns $value. Values must
be scalars, including, of course, references.
Returns the hashref $self->.
Deletes all the keys from $self->. Returns the number of keys
Tries to determine $key from the method call. Returns
$self->->, or undef.
COPYRIGHT AND LICENSE
Copyright 2004-2005 by Eric Folley
This library is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
- » ssh on command line: force using a group size (prime size) of 1024 (and no...
- — The site's Newest Thread. Posted in » Secure Shell Forum