4830a46d0659dbc0758f06e84a072335faf10f31
[dbsrgits/SQL-Translator-2.0-ish.git] / lib / SQL / Translator / Object / Schema.pm
1 use MooseX::Declare;
2 class SQL::Translator::Object::Schema {
3     use MooseX::Types::Moose qw(HashRef Maybe Str);
4     use MooseX::AttributeHelpers;
5     use SQL::Translator::Types qw(Procedure Table View);
6     extends 'SQL::Translator::Object';
7     
8     has 'name' => (
9         is => 'rw',
10         isa => Maybe[Str],
11         required => 1,
12         default => ''
13     );
14     
15     has 'tables' => (
16         metaclass => 'Collection::Hash',
17         is => 'rw',
18         isa => HashRef[Table],
19         provides => {
20             exists => 'exists_table',
21             keys   => 'table_ids',
22             values => 'get_tables',
23             get    => 'get_table',
24         },
25         curries => {
26             set => {
27                 add_table => sub {
28                     my ($self, $body, $table) = @_;
29                     $self->$body($table->name, $table);
30                 }
31             }
32         },
33         default => sub { my %hash = (); tie %hash, 'Tie::IxHash'; return \%hash },
34     );
35     
36     has 'views' => (
37         metaclass => 'Collection::Hash',
38         is => 'rw',
39         isa => HashRef[View],
40         provides => {
41             exists => 'exists_view',
42             keys   => 'view_ids',
43             values => 'get_views',
44             get    => 'get_view',
45         },
46         curries => {
47             set => { 
48                 add_view => sub {
49                     my ($self, $body, $view) = @_;
50                     $self->$body($view->name, $view);
51                 }
52             }
53         },
54         default => sub { my %hash = (); tie %hash, 'Tie::IxHash'; return \%hash },
55     );
56     
57     has 'procedures' => (
58         metaclass => 'Collection::Hash',
59         is => 'rw',
60         isa => HashRef[Procedure],
61         provides => {
62             exists => 'exists_procedure',
63             keys   => 'procedure_ids',
64             values => 'get_procedures',
65             get    => 'get_procedure',
66         },
67         curries => {
68             set => {
69                 add_procedure => sub {
70                     my ($self, $body, $procedure) = @_;
71                     $self->$body($procedure->name, $procedure);
72                 }
73             }
74         },
75         default => sub { {} },
76     );
77
78     method is_valid { 1 }
79 }