Mercurial > pub > Impl
diff lib/IMPL/SQL/Schema/Column.pm @ 417:3ed0c58e9da3 ref20150831
working on di container, tests
author | cin |
---|---|
date | Mon, 02 Nov 2015 01:56:53 +0300 |
parents | c6e90e02dd17 |
children |
line wrap: on
line diff
--- a/lib/IMPL/SQL/Schema/Column.pm Thu Oct 29 03:50:25 2015 +0300 +++ b/lib/IMPL/SQL/Schema/Column.pm Mon Nov 02 01:56:53 2015 +0300 @@ -1,75 +1,78 @@ use strict; + package IMPL::SQL::Schema::Column; -use IMPL::lang qw( :DEFAULT :compare :hash ); +use IMPL::lang qw( :base :compare :hash ); use IMPL::Exception(); use IMPL::Const qw(:prop); use IMPL::declare { - require => { - SchemaType => '-IMPL::SQL::Schema::Type' - }, - base => [ - 'IMPL::Object' => undef, - 'IMPL::Object::Autofill' => '@_' - ], - props => [ - name => PROP_RO | PROP_DIRECT, - type => PROP_RO | PROP_DIRECT, - isNullable => PROP_RO | PROP_DIRECT, - defaultValue => PROP_RO | PROP_DIRECT, - tag => PROP_RO | PROP_DIRECT - ] + require => { + SchemaType => '-IMPL::SQL::Schema::Type' + }, + base => [ + 'IMPL::Object' => undef, + ], + props => [ + name => PROP_RO | PROP_DIRECT, + type => PROP_RO | PROP_DIRECT, + isNullable => PROP_RO | PROP_DIRECT, + defaultValue => PROP_RO | PROP_DIRECT, + tag => PROP_RO | PROP_DIRECT + ] }; sub CTOR { - my $this = shift; - - $this->{$name} or - die new IMPL::InvalidArgumentException('A column name is required'); - - $this->{$isNullable} ||= 0; # if not exists $this->{$isNullable}; - - is( $this->{$type}, SchemaType) or - die new IMPL::InvalidArgumentException('a type is required for the column',$this->{$name}); + my ( $this, %args ) = @_; + + $this->$_( $args{$_} ) + foreach grep exists $args{$_}, qw( name type isNullable defaultValue tag); + + $this->{$name} or + die new IMPL::InvalidArgumentException('A column name is required'); + + $this->{$isNullable} ||= 0; # if not exists $this->{$isNullable}; + + is( $this->{$type}, SchemaType ) + or die new IMPL::InvalidArgumentException( + 'a type is required for the column', + $this->{$name} ); } sub SameValue { - my ($this,$other) = @_; - - return ( - $this->{$name} eq $other->{$name} - and $this->{$isNullable} == $other->{$isNullable} - and equals_s($this->{$defaultValue}, $other->{$defaultValue}) - and $this->{$type}->SameValue($other->{$type}) - ); + my ( $this, $other ) = @_; + + return ( $this->{$name} eq $other->{$name} + and $this->{$isNullable} == $other->{$isNullable} + and equals_s( $this->{$defaultValue}, $other->{$defaultValue} ) + and $this->{$type}->SameValue( $other->{$type} ) ); } sub SetType { - my ($this,$newType) = @_; - - $this->{$type} = $newType; + my ( $this, $newType ) = @_; + + $this->{$type} = $newType; } sub SetDefaultValue { - my ($this,$value) = @_; - - $this->{$defaultValue} = $value; + my ( $this, $value ) = @_; + + $this->{$defaultValue} = $value; } sub SetNullable { - my ($this, $value) = @_; - - $this->{$isNullable} = $value; + my ( $this, $value ) = @_; + + $this->{$isNullable} = $value; } sub SetOptions { - my ($this,$diff) = @_; - - return unless ref $diff eq 'HASH'; - - $this->tag({}) unless $this->tag; - - hashApply($this->tag,$diff); + my ( $this, $diff ) = @_; + + return unless ref $diff eq 'HASH'; + + $this->tag( {} ) unless $this->tag; + + hashApply( $this->tag, $diff ); } -1; +1;