Mercurial > pub > Impl
view Lib/IMPL/Config/Class.pm @ 104:196bf443b5e1
DOM::Schema RC0 inflators support, validation and some other things,
Minor and major fixes almost for everything.
A 'Source' property of the ValidationErrors generated from a NodeSet or a NodeList is subject to change in the future.
author | wizard |
---|---|
date | Tue, 11 May 2010 02:42:59 +0400 |
parents | 5f676b61fb8b |
children | 76515373dac0 |
line wrap: on
line source
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; warn "IMPL::Config::Class is absolute, use IMPL::Config::Activator instead"; } 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;