comparison 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
comparison
equal deleted inserted replaced
416:cc2cf8c0edc2 417:3ed0c58e9da3
1 use strict; 1 use strict;
2
2 package IMPL::SQL::Schema::Column; 3 package IMPL::SQL::Schema::Column;
3 4
4 use IMPL::lang qw( :DEFAULT :compare :hash ); 5 use IMPL::lang qw( :base :compare :hash );
5 use IMPL::Exception(); 6 use IMPL::Exception();
6 use IMPL::Const qw(:prop); 7 use IMPL::Const qw(:prop);
7 use IMPL::declare { 8 use IMPL::declare {
8 require => { 9 require => {
9 SchemaType => '-IMPL::SQL::Schema::Type' 10 SchemaType => '-IMPL::SQL::Schema::Type'
10 }, 11 },
11 base => [ 12 base => [
12 'IMPL::Object' => undef, 13 'IMPL::Object' => undef,
13 'IMPL::Object::Autofill' => '@_' 14 ],
14 ], 15 props => [
15 props => [ 16 name => PROP_RO | PROP_DIRECT,
16 name => PROP_RO | PROP_DIRECT, 17 type => PROP_RO | PROP_DIRECT,
17 type => PROP_RO | PROP_DIRECT, 18 isNullable => PROP_RO | PROP_DIRECT,
18 isNullable => PROP_RO | PROP_DIRECT, 19 defaultValue => PROP_RO | PROP_DIRECT,
19 defaultValue => PROP_RO | PROP_DIRECT, 20 tag => PROP_RO | PROP_DIRECT
20 tag => PROP_RO | PROP_DIRECT 21 ]
21 ]
22 }; 22 };
23 23
24 sub CTOR { 24 sub CTOR {
25 my $this = shift; 25 my ( $this, %args ) = @_;
26 26
27 $this->{$name} or 27 $this->$_( $args{$_} )
28 die new IMPL::InvalidArgumentException('A column name is required'); 28 foreach grep exists $args{$_}, qw( name type isNullable defaultValue tag);
29 29
30 $this->{$isNullable} ||= 0; # if not exists $this->{$isNullable}; 30 $this->{$name} or
31 31 die new IMPL::InvalidArgumentException('A column name is required');
32 is( $this->{$type}, SchemaType) or 32
33 die new IMPL::InvalidArgumentException('a type is required for the column',$this->{$name}); 33 $this->{$isNullable} ||= 0; # if not exists $this->{$isNullable};
34
35 is( $this->{$type}, SchemaType )
36 or die new IMPL::InvalidArgumentException(
37 'a type is required for the column',
38 $this->{$name} );
34 } 39 }
35 40
36 sub SameValue { 41 sub SameValue {
37 my ($this,$other) = @_; 42 my ( $this, $other ) = @_;
38 43
39 return ( 44 return ( $this->{$name} eq $other->{$name}
40 $this->{$name} eq $other->{$name} 45 and $this->{$isNullable} == $other->{$isNullable}
41 and $this->{$isNullable} == $other->{$isNullable} 46 and equals_s( $this->{$defaultValue}, $other->{$defaultValue} )
42 and equals_s($this->{$defaultValue}, $other->{$defaultValue}) 47 and $this->{$type}->SameValue( $other->{$type} ) );
43 and $this->{$type}->SameValue($other->{$type})
44 );
45 } 48 }
46 49
47 sub SetType { 50 sub SetType {
48 my ($this,$newType) = @_; 51 my ( $this, $newType ) = @_;
49 52
50 $this->{$type} = $newType; 53 $this->{$type} = $newType;
51 } 54 }
52 55
53 sub SetDefaultValue { 56 sub SetDefaultValue {
54 my ($this,$value) = @_; 57 my ( $this, $value ) = @_;
55 58
56 $this->{$defaultValue} = $value; 59 $this->{$defaultValue} = $value;
57 } 60 }
58 61
59 sub SetNullable { 62 sub SetNullable {
60 my ($this, $value) = @_; 63 my ( $this, $value ) = @_;
61 64
62 $this->{$isNullable} = $value; 65 $this->{$isNullable} = $value;
63 } 66 }
64 67
65 sub SetOptions { 68 sub SetOptions {
66 my ($this,$diff) = @_; 69 my ( $this, $diff ) = @_;
67 70
68 return unless ref $diff eq 'HASH'; 71 return unless ref $diff eq 'HASH';
69 72
70 $this->tag({}) unless $this->tag; 73 $this->tag( {} ) unless $this->tag;
71 74
72 hashApply($this->tag,$diff); 75 hashApply( $this->tag, $diff );
73 } 76 }
74 77
75 1; 78 1;