Mercurial > pub > Impl
view Lib/IMPL/Object/Singleton.pm @ 197:6b1dda998839
Added IMPL::declare, IMPL::require, to simplify module definitions
IMPL::Transform now admires object inheritance while searching for the transformation
Added HTTP some exceptions
IMPL::Web::Application::RestResource almost implemented
author | sergey |
---|---|
date | Thu, 19 Apr 2012 02:10:02 +0400 |
parents | 4d0e1962161c |
children | 0f59b2de72af |
line wrap: on
line source
package IMPL::Object::Singleton; use strict; use warnings; my %instances; sub CTOR { die new IMPL::InvalidOperationException("Only one instance of the singleton can be created",ref $_[0], $instances{ref $_[0]}) if $instances{ref $_[0]}; $instances{ref $_[0]} = $_[0]; } sub instance { $instances{$_[0]} } 1; __END__ =pod =head1 SYNOPSIS =begin code package Foo; use parent qw(IMPL::Object IMPL::Object::Singleton); #.... Foo->isnatnce->some_work(); Foo->isnatnce->get_result(); =end code =head1 DESCRIPTION Реализует шаблон Singleton =head1 MEMBERS =head2 OPERATORS =list =item C<instance CLASS(@params)> Создает или возвращает экземпляр класса, если экземляр не существует, то он создается с параметрами C<@params>. =over =cut