annotate lib/IMPL/SQL/Schema/Column.pm @ 424:87af445663d7 ref20150831

IMPL::Object::_Base
author cin
date Tue, 03 Apr 2018 10:54:09 +0300
parents 3ed0c58e9da3
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
407
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
1 use strict;
417
3ed0c58e9da3 working on di container, tests
cin
parents: 407
diff changeset
2
407
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
3 package IMPL::SQL::Schema::Column;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
4
417
3ed0c58e9da3 working on di container, tests
cin
parents: 407
diff changeset
5 use IMPL::lang qw( :base :compare :hash );
407
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
6 use IMPL::Exception();
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
7 use IMPL::Const qw(:prop);
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
8 use IMPL::declare {
417
3ed0c58e9da3 working on di container, tests
cin
parents: 407
diff changeset
9 require => {
3ed0c58e9da3 working on di container, tests
cin
parents: 407
diff changeset
10 SchemaType => '-IMPL::SQL::Schema::Type'
3ed0c58e9da3 working on di container, tests
cin
parents: 407
diff changeset
11 },
3ed0c58e9da3 working on di container, tests
cin
parents: 407
diff changeset
12 base => [
3ed0c58e9da3 working on di container, tests
cin
parents: 407
diff changeset
13 'IMPL::Object' => undef,
3ed0c58e9da3 working on di container, tests
cin
parents: 407
diff changeset
14 ],
3ed0c58e9da3 working on di container, tests
cin
parents: 407
diff changeset
15 props => [
3ed0c58e9da3 working on di container, tests
cin
parents: 407
diff changeset
16 name => PROP_RO | PROP_DIRECT,
3ed0c58e9da3 working on di container, tests
cin
parents: 407
diff changeset
17 type => PROP_RO | PROP_DIRECT,
3ed0c58e9da3 working on di container, tests
cin
parents: 407
diff changeset
18 isNullable => PROP_RO | PROP_DIRECT,
3ed0c58e9da3 working on di container, tests
cin
parents: 407
diff changeset
19 defaultValue => PROP_RO | PROP_DIRECT,
3ed0c58e9da3 working on di container, tests
cin
parents: 407
diff changeset
20 tag => PROP_RO | PROP_DIRECT
3ed0c58e9da3 working on di container, tests
cin
parents: 407
diff changeset
21 ]
407
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
22 };
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
23
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
24 sub CTOR {
417
3ed0c58e9da3 working on di container, tests
cin
parents: 407
diff changeset
25 my ( $this, %args ) = @_;
3ed0c58e9da3 working on di container, tests
cin
parents: 407
diff changeset
26
3ed0c58e9da3 working on di container, tests
cin
parents: 407
diff changeset
27 $this->$_( $args{$_} )
3ed0c58e9da3 working on di container, tests
cin
parents: 407
diff changeset
28 foreach grep exists $args{$_}, qw( name type isNullable defaultValue tag);
3ed0c58e9da3 working on di container, tests
cin
parents: 407
diff changeset
29
3ed0c58e9da3 working on di container, tests
cin
parents: 407
diff changeset
30 $this->{$name} or
3ed0c58e9da3 working on di container, tests
cin
parents: 407
diff changeset
31 die new IMPL::InvalidArgumentException('A column name is required');
3ed0c58e9da3 working on di container, tests
cin
parents: 407
diff changeset
32
3ed0c58e9da3 working on di container, tests
cin
parents: 407
diff changeset
33 $this->{$isNullable} ||= 0; # if not exists $this->{$isNullable};
3ed0c58e9da3 working on di container, tests
cin
parents: 407
diff changeset
34
3ed0c58e9da3 working on di container, tests
cin
parents: 407
diff changeset
35 is( $this->{$type}, SchemaType )
3ed0c58e9da3 working on di container, tests
cin
parents: 407
diff changeset
36 or die new IMPL::InvalidArgumentException(
3ed0c58e9da3 working on di container, tests
cin
parents: 407
diff changeset
37 'a type is required for the column',
3ed0c58e9da3 working on di container, tests
cin
parents: 407
diff changeset
38 $this->{$name} );
407
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
39 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
40
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
41 sub SameValue {
417
3ed0c58e9da3 working on di container, tests
cin
parents: 407
diff changeset
42 my ( $this, $other ) = @_;
3ed0c58e9da3 working on di container, tests
cin
parents: 407
diff changeset
43
3ed0c58e9da3 working on di container, tests
cin
parents: 407
diff changeset
44 return ( $this->{$name} eq $other->{$name}
3ed0c58e9da3 working on di container, tests
cin
parents: 407
diff changeset
45 and $this->{$isNullable} == $other->{$isNullable}
3ed0c58e9da3 working on di container, tests
cin
parents: 407
diff changeset
46 and equals_s( $this->{$defaultValue}, $other->{$defaultValue} )
3ed0c58e9da3 working on di container, tests
cin
parents: 407
diff changeset
47 and $this->{$type}->SameValue( $other->{$type} ) );
407
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
48 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
49
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
50 sub SetType {
417
3ed0c58e9da3 working on di container, tests
cin
parents: 407
diff changeset
51 my ( $this, $newType ) = @_;
3ed0c58e9da3 working on di container, tests
cin
parents: 407
diff changeset
52
3ed0c58e9da3 working on di container, tests
cin
parents: 407
diff changeset
53 $this->{$type} = $newType;
407
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
54 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
55
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
56 sub SetDefaultValue {
417
3ed0c58e9da3 working on di container, tests
cin
parents: 407
diff changeset
57 my ( $this, $value ) = @_;
3ed0c58e9da3 working on di container, tests
cin
parents: 407
diff changeset
58
3ed0c58e9da3 working on di container, tests
cin
parents: 407
diff changeset
59 $this->{$defaultValue} = $value;
407
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
60 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
61
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
62 sub SetNullable {
417
3ed0c58e9da3 working on di container, tests
cin
parents: 407
diff changeset
63 my ( $this, $value ) = @_;
3ed0c58e9da3 working on di container, tests
cin
parents: 407
diff changeset
64
3ed0c58e9da3 working on di container, tests
cin
parents: 407
diff changeset
65 $this->{$isNullable} = $value;
407
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
66 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
67
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
68 sub SetOptions {
417
3ed0c58e9da3 working on di container, tests
cin
parents: 407
diff changeset
69 my ( $this, $diff ) = @_;
3ed0c58e9da3 working on di container, tests
cin
parents: 407
diff changeset
70
3ed0c58e9da3 working on di container, tests
cin
parents: 407
diff changeset
71 return unless ref $diff eq 'HASH';
3ed0c58e9da3 working on di container, tests
cin
parents: 407
diff changeset
72
3ed0c58e9da3 working on di container, tests
cin
parents: 407
diff changeset
73 $this->tag( {} ) unless $this->tag;
3ed0c58e9da3 working on di container, tests
cin
parents: 407
diff changeset
74
3ed0c58e9da3 working on di container, tests
cin
parents: 407
diff changeset
75 hashApply( $this->tag, $diff );
407
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
76 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
77
417
3ed0c58e9da3 working on di container, tests
cin
parents: 407
diff changeset
78 1;