09 Apr 2013 05:38:16 UTC
- Distribution: Aspect
- Module version: 1.04
- Source (raw)
- Browse (raw)
- How to Contribute
- Clone repository
- Issues (6)
- Testers (2790 / 27 / 10)
- KwaliteeBus factor: 1
- 84.41% Coverage
- License: perl_5
- Perl: v5.8.2
- Activity24 month
- Download (110.38KB)
- MetaCPAN Explorer
- Subscribe to distribution
- This version
- Latest version
Aspect::Library::Singleton - A singleton aspect
use Aspect; use Aspect::Singleton; aspect Singleton => 'Foo::new'; my $f1 = Foo->new; my $f2 = Foo->new; # Both $f1 and $f2 refer to the same object
A reusable aspect that forces singleton behavior on a constructor. The constructor is defined by a pointcut spec: a string. regexp, or code ref.
It is slightly different from
No specific name requirement on the constructor for the external interface, or for the implementation (
Class::Singletonrequires clients use
instance(), and that subclasses override
_new_instance()). With aspects, you can change the cardinality of your objects without changing the clients, or the objects themselves.
No need to inherit from anything- use pointcuts to specify the constructors you want to memoize. Instead of pulling singleton behavior from a base class, you are pushing it in, using the aspect.
No package variable or method is added to the callers namespace
Note that this is just a special case of memoizing.
Adam Kennedy <firstname.lastname@example.org>
Marcel Grünauer <email@example.com>
Ran Eilam <firstname.lastname@example.org>
Copyright 2001 by Marcel Grünauer
Some parts copyright 2009 - 2013 Adam Kennedy.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.