Main > Programming > Libraries >

Class::StrongSingleton 0.02

Class::StrongSingleton 0.02

Sponsored Links

Class::StrongSingleton 0.02 Ranking & Summary

RankingClick at the star to rank
Ranking Level
User Review: 0 (0 times)
File size: 0.006 MB
Platform: Any Platform
License: Perl Artistic License
Price:
Downloads: 861
Date added: 2007-06-19
Publisher: Stevan Little

Class::StrongSingleton 0.02 description

Class::StrongSingleton is a stronger and more secure Singleton base class.

SYNOPSIS

package My::Singleton::Class;

use base qw(Class::StrongSingleton);

sub new {
my ($class, %my_params) = @_;
# create our object instance
my $instance = { %my_params };
bless($instance, $class);
# and initialize it as a singleton
$instance->_init_StrongSingleton();
return $instance;
}

1;

# later in your code ...

# create the first instance of our class
my $instance = My::Singleton::Class->new(param => "value");

# try to create a new one again, and
# you end up with the same instance, not
# a new one
my $instance2 = My::Singleton::Class->new(param => "other value");

# calling instance returns the singleton
# instance expected
my $instance3 = My::Singleton::Class->instance();

# although rarely needed, if you have to
# you can destroy the singleton

# either through the instance
$instance->DESTROY();
# or through the class
My::Singleton::Class->DESTROY();

# of course, this is assuming you
# did not override DESTORY yourself

# Also calling instance before calling new
# will returns a new singleton instance
my $instance = My::Singleton::Class->instance();

This module is an alternative to Class::Singleton and Class::WeakSingleton, and provides a more secure Singleton class in that it takes steps to prevent the possibility of accidental creation of multiple instances and/or the overwriting of existsing Singleton instances. For a detailed comparison please see the "SEE ALSO" section.

Here is a description of how it all works. First, the user creates the first Singleton instance of the class in the normal way.

my $obj = My::Singleton::Class->new("variable", "parameter");

This instance is then stored inside a lexically scoped variable within the Class::StrongSingleton package. This prevents the variable from being accessed by anything but methods from the Class::StrongSingleton package. At this point as well, the new method to the class is overridden so that it will always return the Singleton instance. This prevents any accidental overwriting of the Singleton instance. This means that any of the follow lines of code all produce the same instance:

my $instance = $obj->instance();
my $instance = My::Singleton::Class->instance();
my $instance = $obj->new();
my $instance = My::Singleton::Class->new();

Personally, I see this an an improvement over the usual Gang of Four style Singletons which discourages the use of the new method entirely. Through this method, a user can be able to use the Singleton class in a normal way, not having to know its actually a Singleton. This can be handy if your design changes and you no longer need the class as a Singleton.

Class::StrongSingleton 0.02 Screenshot

Advertisements

Class::StrongSingleton 0.02 Keywords

Bookmark Class::StrongSingleton 0.02

Hyperlink code:
Link for forum:

Class::StrongSingleton 0.02 Copyright

WareSeeker periodically updates pricing and software information of Class::StrongSingleton 0.02 full version from the publisher, so some information may be slightly out-of-date. You should confirm all information before relying on it. Software piracy is theft, Using crack, password, serial numbers, registration codes, key generators is illegal and prevent future development of Class::StrongSingleton 0.02 Edition. Download links are directly from our publisher sites, torrent files or links from rapidshare.com, yousendit.com or megaupload.com are not allowed

Allok Video Splitter 2.2.0 Review:

Name (Required)
Email(Required)
Captcha
Featured Software

Want to place your software product here?
Please contact us for consideration.

Contact WareSeeker.com
Related Software
Test::Singleton is a test for Singleton classes. Free Download
Class::Simple is a simple Object-Oriented Base Class. Free Download
Class::Cloneable is a base class for Cloneable objects. Free Download
Class::Agreement is a Perl module that add contracts to your Perl classes easily. Free Download
Class::DataStore is a Perl module for generic OO data storage/retrieval. Free Download
Class::Driver is a Perl module to generate driver ("composite") class hierarchies on-the-fly. Free Download
Class::ArrayObjects is a Perl utility class for array based objects. Free Download
Class::AbstractLogic is a Perl module to handle Logic Abstractions. Free Download