Aspect::Library::Singleton(3pm)

Aspect::Library::Singleton3pm

A singleton aspect

Usage

  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

Overview

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 "Class::Singleton" (<http://search.cpan.org/~abw/Class-Singleton/Singleton.pm>):

•

No specific name requirement on the constructor for the external interface, or for the implementation ("Class::Singleton" requires 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.

Releases

8 releases since Debian 6.0 (Squeeze); the text changed 5 times.

  1. 6.0
  2. 7
  3. 8–10
  4. 11
  5. 12
  6. 13

Authors

Adam Kennedy <[email protected]>

Marcel Grünauer <[email protected]>

Ran Eilam <[email protected]>

From libaspect-perl 1.04-3 in Debian 13 (Trixie). Parsed by carta from the page's man source.