comparison Lib/IMPL/SQL/Schema/Traits/Diff.pm @ 315:77df11605d3a

code cleanup
author cin
date Tue, 07 May 2013 02:19:24 +0400
parents 4d0e1962161c
children
comparison
equal deleted inserted replaced
314:109f28643025 315:77df11605d3a
1 package IMPL::SQL::Schema::Traits::Diff; 1 package IMPL::SQL::Schema::Traits::Diff;
2 use strict; 2 use strict;
3 use warnings; 3 use warnings;
4 use IMPL::lang qw(:compare :hash is); 4 use IMPL::lang qw(:compare :hash is typeof);
5 5
6 use IMPL::SQL::Schema(); 6 use IMPL::SQL::Schema();
7 use IMPL::SQL::Schema::Traits(); 7 use IMPL::SQL::Schema::Traits();
8 8
9 # defining a constant is a good style to enable compile checks
9 use constant { 10 use constant {
10 schema_t => typeof IMPL::SQL::Schema # defining a constant is a good style to enable compile checks 11 schema_t => 'IMPL::SQL::Schema',
12 ConstraintForeignKey => 'IMPL::SQL::Schema::Constraint::ForeignKey',
13 TraitsForeignKey => 'IMPL::SQL::Schema::Traits::ForeignKey',
14 ConstraintPrimaryKey => 'IMPL::SQL::Schema::Constraint::PrimaryKey',
15 TraitsPrimaryKey => 'IMPL::SQL::Schema::Traits::PrimaryKey',
16 ConstraintUnique => 'IMPL::SQL::Schema::Constraint::Unique',
17 TraitsUnique => 'IMPL::SQL::Schema::Traits::Unique',
18 ConstraintIndex => 'IMPL::SQL::Schema::Constraint::Index',
19 TraitsIndex => 'IMPL::SQL::Schema::Traits::Index'
11 }; 20 };
12 21
13 sub Diff { 22 sub Diff {
14 my ($self,$src,$dst) = @_; 23 my ($self,$src,$dst) = @_;
15 24
146 155
147 sub _Constraint2Traits { 156 sub _Constraint2Traits {
148 my ($constraint) = @_; 157 my ($constraint) = @_;
149 158
150 my $map = { 159 my $map = {
151 typeof IMPL::SQL::Schema::Constraint::ForeignKey , typeof IMPL::SQL::Schema::Traits::ForeignKey, 160 ConstraintForeignKey , TraitsForeignKey,
152 typeof IMPL::SQL::Schema::Constraint::PrimaryKey , typeof IMPL::SQL::Schema::Traits::PrimaryKey, 161 ConstraintPrimaryKey , TraitsPrimaryKey,
153 typeof IMPL::SQL::Schema::Constraint::Unique , typeof IMPL::SQL::Schema::Traits::Unique, 162 ConstraintUnique , TraitsUnique,
154 typeof IMPL::SQL::Schema::Constraint::Index , typeof IMPL::SQL::Schema::Traits::Index 163 ConstraintIndex , TraitsIndex
155 }; 164 };
156 165
157 my $class = $map->{$constraint->typeof} or die new IMPL::Exception("Can't map the constraint",$constraint->typeof); 166 my $class = $map->{typeof($constraint)} or die new IMPL::Exception("Can't map the constraint",typeof($constraint));
158 167
159 return $class->new( 168 return $class->new(
160 $constraint->name, 169 $constraint->name,
161 [ map $_->name, $constraint->columns ] 170 [ map $_->name, $constraint->columns ]
162 ) 171 )