view Lib/IMPL/Object/Singleton.pm @ 171:59e5fcb59d86

Исправления, изменена концепция веб-форм
author sourcer
date Mon, 06 Jun 2011 03:30:36 +0400
parents 4267a2ac3d46
children d1676be8afcc
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