annotate Lib/IMPL/SQL/Schema/Traits/Diff.pm @ 165:76515373dac0

Added Class::Template, Rewritten SQL::Schema 'use parent' directive instead of 'use base'
author wizard
date Sat, 23 Apr 2011 23:06:48 +0400
parents
children 1f7a6d762394
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
165
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
1 package IMPL::SQL::Schema::Traits::Diff;
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
2 use strict;
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
3 use warnings;
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
4 use IMPL::lang;
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
5
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
6 use IMPL::SQL::Schema();
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
7 use IMPL::SQL::Schema::Traits();
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
8
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
9 use constant {
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
10 schema_t => typeof IMPL::SQL::Schema # defining a constant is a good style to enable compile checks
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
11 };
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
12
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
13 sub Diff {
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
14 my ($self,$src,$dst) = @_;
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
15
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
16 die new IMPL::InvalidArgumentException( src => "A valid source schema is required") unless is($src,schema_t);
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
17 die new IMPL::InvalidArgumentException( dst => "A valid desctination schema is requried" ) unless is($src,schema_t);
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
18
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
19 my %dstTables = map { $_->name, $_ } $dst->GetTables;
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
20
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
21 my @operations;
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
22
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
23 foreach my $srcTable ( $src->GetTables) {
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
24 my $dstTable = delete $dstTables{$srcTable->name};
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
25
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
26 if (not $dstTable) {
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
27 push @operations, new IMPL::SQL::Schema::Traits::DropTable()
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
28 } else {
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
29
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
30 }
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
31
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
32 }
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
33 }
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
34
76515373dac0 Added Class::Template,
wizard
parents:
diff changeset
35 1;