Mercurial > pub > Impl
diff Lib/IMPL/Object/Factory.pm @ 194:4d0e1962161c
Replaced tabs with spaces
IMPL::Web::View - fixed document model, new features (control classes, document constructor parameters)
author | cin |
---|---|
date | Tue, 10 Apr 2012 20:08:29 +0400 |
parents | 6c0fee769b0c |
children | 5c82eec23bb6 |
line wrap: on
line diff
--- a/Lib/IMPL/Object/Factory.pm Tue Apr 10 08:13:22 2012 +0400 +++ b/Lib/IMPL/Object/Factory.pm Tue Apr 10 20:08:29 2012 +0400 @@ -6,70 +6,70 @@ use IMPL::lang qw(:declare :constants); BEGIN { - public property factory => PROP_GET | PROP_OWNERSET; - public property parameters => PROP_GET | PROP_OWNERSET; - public property method => PROP_GET | PROP_OWNERSET; + public property factory => PROP_GET | PROP_OWNERSET; + public property parameters => PROP_GET | PROP_OWNERSET; + public property method => PROP_GET | PROP_OWNERSET; } # custom factory, overrides default sub new { - my $self = shift; - - return ref $self ? $self->CreateObject(@_) : $self->IMPL::Object::new(@_); + my $self = shift; + + return ref $self ? $self->CreateObject(@_) : $self->IMPL::Object::new(@_); } sub CTOR { - my ($this,$factory,$parameters,$method) = @_; - - $this->factory($factory) or die new IMPL::InvalidArgumentException("The argument 'factory' is mandatory"); - $this->parameters($parameters) if $parameters; - $this->method($method) if $method; + my ($this,$factory,$parameters,$method) = @_; + + $this->factory($factory) or die new IMPL::InvalidArgumentException("The argument 'factory' is mandatory"); + $this->parameters($parameters) if $parameters; + $this->method($method) if $method; } # override default restore method sub restore { - my ($class,$data,$surrogate) = @_; - - my %args = @$data; - - if ($surrogate) { - $surrogate->self::CTOR($args{factory},$args{parameters},$args{method}); - return $surrogate; - } else { - return $class->new($args{factory},$args{parameters},$args{method}); - } + my ($class,$data,$surrogate) = @_; + + my %args = @$data; + + if ($surrogate) { + $surrogate->self::CTOR($args{factory},$args{parameters},$args{method}); + return $surrogate; + } else { + return $class->new($args{factory},$args{parameters},$args{method}); + } } sub CreateObject { - my $this = shift; - - if (my $method = $this->method) { - $this->factory->$method($this->MergeParameters(@_)); - } else { - $this->factory->new($this->MergeParameters(@_)); - } + my $this = shift; + + if (my $method = $this->method) { + $this->factory->$method($this->MergeParameters(@_)); + } else { + $this->factory->new($this->MergeParameters(@_)); + } } sub MergeParameters { - my $this = shift; - - $this->parameters ? (_as_list($this->parameters),@_) : @_; + my $this = shift; + + $this->parameters ? (_as_list($this->parameters),@_) : @_; } sub _as_list { - ref $_[0] ? - (ref $_[0] eq 'HASH' ? - %{$_[0]} - : - (ref $_[0] eq 'ARRAY'? - @{$_[0]} - : - $_[0] - ) - ) - : - ($_[0]); + ref $_[0] ? + (ref $_[0] eq 'HASH' ? + %{$_[0]} + : + (ref $_[0] eq 'ARRAY'? + @{$_[0]} + : + $_[0] + ) + ) + : + ($_[0]); } @@ -84,10 +84,10 @@ =begin code my $factory = new IMPL::Object::Factory( - 'MyApp::User', - { - isAdmin => 1 - } + 'MyApp::User', + { + isAdmin => 1 + } ); my $class = 'MyApp::User'; @@ -96,7 +96,7 @@ $user = $class->new(name => 'nobody'); # will create object MyApp::User # and pass parameters (name=>'nobody') - + $user = $factory->new(name => 'root'); # will create object MyApp::User # and pass paremeters (isAdmin => 1, name => 'root') @@ -107,10 +107,10 @@ =begin code xml <factory type="IMPL::Object::Factory"> - <factory>MyApp::User</factory>, - <parameters type="HASH"> - <isAdmin>1</isAdmin> - </parameters> + <factory>MyApp::User</factory>, + <parameters type="HASH"> + <isAdmin>1</isAdmin> + </parameters> </factory> =end code xml @@ -191,11 +191,11 @@ =begin code sub new { - my ($this,@params) = @_; - - my $method = $this->method || 'new'; - - return $this->factory->$method(_as_list($this->parameters), @params); + my ($this,@params) = @_; + + my $method = $this->method || 'new'; + + return $this->factory->$method(_as_list($this->parameters), @params); } =end code