Data::SingletonManager - return/set/clear instances of singletons identified by keys in different namespaces.
package My::Object; sub instance { my %args; ... my $key = "$args{userid}-$args{object_id}"; return Data::SingletonManager->instance( namespace => __PACKAGE__, # default; may omit. key => $key, creator => sub { return __PACKAGE__->new_instance($args{userid}, $args{object_id}); } ); } package main; # return all singletons loaded in a namespace: @loaded_objs = Data::SingletonManager->instances("My::Object"); # clear all singletons, in all packages (perhaps on new web request) Data::SingletonManager->clear_all; # clear all singletons in one namespace Data::SingletonManager->clear("My::Object");
This is a small utility class to help manage multiple keyed singletons in multiple namespaces. It is not a base class so you can drop it into any of your classes without namespace clashes with methods you might already have, like "new", "instance", "new_instance", etc.
All methods below are package methods. There are no instance methods.
Package method to return (or create and save) a keyed instance where %args are:
defaults to the calling package
scalar key for instance. the (namespace, key) uniquely identifies an instance
subref to return the instance if it doesn't already exist
Return an array of all loaded instances in a namespace, which defaults to the calling namespace if no namespace is given.
Clears all instances in a namespace, which defaults to the calling namespace if no namespace is given.
Clears all instances in all namespaces.
Brad Fitzpatrick <brad@danga.com>
Copyright 2005 by Six Apart, Ltd.
License is granted to use and distribute this module under the same terms as Perl itself.
1 POD Error
The following errors were encountered while parsing the POD:
You forgot a '=back' before '=head1'
To install Data::SingletonManager, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Data::SingletonManager
CPAN shell
perl -MCPAN -e shell install Data::SingletonManager
For more information on module installation, please visit the detailed CPAN module installation guide.