Mercurial > pub > Impl
comparison Lib/IMPL/SQL/Schema/Column.pm @ 167:1f7a6d762394
SQL schema in progress
author | sourcer |
---|---|
date | Thu, 12 May 2011 08:57:19 +0400 |
parents | 76515373dac0 |
children | 6148f89bb7bf |
comparison
equal
deleted
inserted
replaced
166:4267a2ac3d46 | 167:1f7a6d762394 |
---|---|
1 use strict; | 1 use strict; |
2 package IMPL::SQL::Schema::Column; | 2 package IMPL::SQL::Schema::Column; |
3 use parent qw(IMPL::Object IMPL::Object::Autofill); | 3 use parent qw(IMPL::Object IMPL::Object::Autofill); |
4 | 4 |
5 use IMPL::Class::Property; | 5 use IMPL::lang qw( :DEFAULT :compare :declare :constants ); |
6 use IMPL::Class::Property::Direct; | 6 use IMPL::Class::Property::Direct; |
7 use IMPL::Exception(); | |
7 | 8 |
8 BEGIN { | 9 BEGIN { |
9 public _direct property name => prop_get; | 10 public _direct property name => PROP_GET; |
10 public _direct property type => prop_get; | 11 public _direct property type => PROP_GET; |
11 public _direct property isNullable => prop_get; | 12 public _direct property isNullable => PROP_GET; |
12 public _direct property defaultValue => prop_get; | 13 public _direct property defaultValue => PROP_GET; |
13 public _direct property tag => prop_get; | 14 public _direct property tag => PROP_GET; |
14 } | 15 } |
15 | 16 |
16 __PACKAGE__->PassThroughArgs; | 17 __PACKAGE__->PassThroughArgs; |
17 | 18 |
18 sub CTOR { | 19 sub CTOR { |
19 my $this = shift; | 20 my $this = shift; |
20 | 21 |
21 $this->{$name} or die new IMPL::InvalidArgumentException('a column name is required'); | 22 $this->{$name} or |
23 die new IMPL::InvalidArgumentException('A column name is required'); | |
24 | |
22 $this->{$isNullable} = 0 if not exists $this->{$isNullable}; | 25 $this->{$isNullable} = 0 if not exists $this->{$isNullable}; |
23 UNIVERSAL::isa($this->{$type},'IMPL::SQL::Schema::Type') or die new IMPL::InvalidArgumentException('a type is required for the column',$this->{$name}); | 26 |
27 is( $this->{$type}, typeof IMPL::SQL::Schema::Type) or | |
28 die new IMPL::InvalidArgumentException('a type is required for the column',$this->{$name}); | |
24 } | 29 } |
25 | 30 |
26 sub isEqualsStr { | 31 sub SameValue { |
27 my ($a,$b) = @_; | |
28 | |
29 if (defined $a and defined $b) { | |
30 return $a eq $b; | |
31 } else { | |
32 if (defined $a or defined $b) { | |
33 return 0; | |
34 } else { | |
35 return 1; | |
36 } | |
37 } | |
38 } | |
39 | |
40 sub isEquals { | |
41 my ($a,$b) = @_; | |
42 | |
43 if (defined $a and defined $b) { | |
44 return $a == $b; | |
45 } else { | |
46 if (defined $a or defined $b) { | |
47 return 0; | |
48 } else { | |
49 return 1; | |
50 } | |
51 } | |
52 } | |
53 | |
54 sub isSame { | |
55 my ($this,$other) = @_; | 32 my ($this,$other) = @_; |
56 | 33 |
57 return ($this->{$name} eq $other->{$name} and $this->{$isNullable} == $other->{$isNullable} and isEqualsStr($this->{$defaultValue}, $other->{$defaultValue}) and $this->{$type}->isSame($other->{$type})); | 34 return ( |
35 $this->{$name} eq $other->{$name} | |
36 and $this->{$isNullable} == $other->{$isNullable} | |
37 and equals_s($this->{$defaultValue}, $other->{$defaultValue}) | |
38 and $this->{$type}->SameValue($other->{$type}) | |
39 ); | |
58 } | 40 } |
59 | 41 |
60 1; | 42 1; |