Aspect::Library::Singleton - A singleton aspect


NAME

Aspect::Library::Singleton - A singleton aspect


SYNOPSIS

  use Aspect::Singleton;
  aspect Singleton => 'Foo::new';
  my $f1 = Foo->new;
  my $f2 = Foo->new;
  # now $f1 and $f2 refer to the same object


SUPER

the Aspect::Modular manpage


DESCRIPTION

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):

Note that this is just a special case of memoizing.


SEE ALSO

See the Aspect pods for a guide to the Aspect module.

You can find an example comparing the OO and AOP solutions in the examples/ directory of the distribution.