|
Posted by Eric Folley on May 13, 2005, 2:45 pm
Please log in for more thread options
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
think.
Thank you....
NAME
Class::DataStore - Generic OO data storage/retrieval
SYNOPSIS
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;
$store->clear;
DESCRIPTION
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
faster.
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
subclass:
use base 'Class::DataStore';
*AUTOLOAD = \&Class::DataStore::AUTOLOAD;
METHODS
new( $data_hashref )
The $data_hashref is stored in $self->. Returns the blessed
object.
exists( $key )
Returns 1 if the $key exists in the $self-> hashref. Otherwise,
returns 0.
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
returned unaltered.
set( $key => $value )
Sets $self->-> to $value, and returns $value. Values must
be scalars, including, of course, references.
dump()
Returns the hashref $self->.
clear()
Deletes all the keys from $self->. Returns the number of keys
deleted.
AUTOLOAD()
Tries to determine $key from the method call. Returns
$self->->, or undef.
AUTHOR
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.
--
Eric Folley
http://www.folley.net/
|
| Similar Threads | Posted | | Class::DBI::Schema2Code V 1.01 | July 29, 2004, 7:14 am |
| Class::Tree V 1.24 | July 29, 2004, 7:15 am |
| RFC: new module Class::MakeIntrospecMethods | October 18, 2004, 4:30 pm |
| Perl Class::Struct | October 13, 2005, 3:18 am |
| A doubt in using Class::Struct | October 5, 2006, 2:33 pm |
| [ANNOUNCE] New module Class::IntrospectionMethods | December 6, 2004, 2:12 pm |
| Class::MethodMaker v2 syntax help requested | February 7, 2005, 9:33 pm |
| Namespace for MMS Parser class and a request for help | August 13, 2005, 8:43 pm |
| Class::Std causing compilation errors | November 24, 2007, 5:08 pm |
| Unable to set the XValues property of the Series class | November 9, 2005, 10:29 am |
|