view Lib/IMPL/Object/Singleton.pm @ 148:e6447ad85cb4

DOM objects now have a schema and schemaSource properties RegExp now can launder data Improved post to DOM transformation (multiple values a now supported) Added new axes to navigation queries: ancestor and descendant minor changes and bug fixes
author wizard
date Mon, 16 Aug 2010 08:26:44 +0400
parents b56ebc31bf18
children 4267a2ac3d46
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 base 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