Mercurial > pub > Impl
diff Lib/IMPL/Config/Class.pm @ 49:16ada169ca75
migrating to the Eclipse IDE
author | wizard@linux-odin.local |
---|---|
date | Fri, 26 Feb 2010 10:49:21 +0300 |
parents | 03e58a454b20 |
children | 5f676b61fb8b |
line wrap: on
line diff
--- a/Lib/IMPL/Config/Class.pm Fri Feb 26 01:43:42 2010 +0300 +++ b/Lib/IMPL/Config/Class.pm Fri Feb 26 10:49:21 2010 +0300 @@ -1,52 +1,52 @@ -package IMPL::Config::Class; -use strict; -use warnings; - -use base qw(IMPL::Config); -use IMPL::Exception; -use IMPL::Class::Property; - -BEGIN { - public property Type => prop_all; - public property Parameters => prop_all; - public property IsSingleton => prop_all; - private property _Instance => prop_all; -} - -__PACKAGE__->PassThroughArgs; - -sub CTOR { - my $this = shift; - - die new IMPL::Exception("A Type parameter is required") unless $this->Type; - -} - -sub _is_class { - no strict 'refs'; - scalar keys %{"$_[0]::"} ? 1 : 0; -} - -sub instance { - my $this = shift; - - my $type = $this->Type; - - if ($this->IsSingleton) { - if ($this->_Instance) { - return $this->_Instance; - } else { - my %args = (%{$this->Parameters || {}},@_); - eval "require $type" unless _is_class($type); - my $inst = $type->new(%args); - $this->_Instance($inst); - return $inst; - } - } else { - my %args = (%{$this->Parameters || {}},@_); - eval "require $type" unless _is_class($type); - return $type->new(%args); - } -} - -1; +package IMPL::Config::Class; +use strict; +use warnings; + +use base qw(IMPL::Config); +use IMPL::Exception; +use IMPL::Class::Property; + +BEGIN { + public property Type => prop_all; + public property Parameters => prop_all; + public property IsSingleton => prop_all; + private property _Instance => prop_all; +} + +__PACKAGE__->PassThroughArgs; + +sub CTOR { + my $this = shift; + + die new IMPL::Exception("A Type parameter is required") unless $this->Type; + +} + +sub _is_class { + no strict 'refs'; + scalar keys %{"$_[0]::"} ? 1 : 0; +} + +sub instance { + my $this = shift; + + my $type = $this->Type; + + if ($this->IsSingleton) { + if ($this->_Instance) { + return $this->_Instance; + } else { + my %args = (%{$this->Parameters || {}},@_); + eval "require $type" unless _is_class($type); + my $inst = $type->new(%args); + $this->_Instance($inst); + return $inst; + } + } else { + my %args = (%{$this->Parameters || {}},@_); + eval "require $type" unless _is_class($type); + return $type->new(%args); + } +} + +1;