comparison lib/IMPL/SQL/Schema/Column.pm @ 407:c6e90e02dd17 ref20150831

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