no more wantarray
[dbsrgits/SQL-Translator-2.0-ish.git] / lib / SQL / Translator / Object / Trigger.pm
CommitLineData
4f4fd192 1use MooseX::Declare;
ebf2721d 2class SQL::Translator::Object::Trigger extends SQL::Translator::Object {
c53f9843 3 use MooseX::Types::Moose qw(Any ArrayRef HashRef Str);
37ae885e 4 use MooseX::MultiMethods;
5 use SQL::Translator::Types qw(Column Schema Table);
6
7 has 'schema' => (
8 is => 'rw',
9 isa => Schema,
10 weak_ref => 1,
11 );
12
13 has 'table' => (
14 is => 'rw',
15 isa => Table,
16 weak_ref => 1,
17 );
18
4f4fd192 19 has 'name' => (
20 is => 'ro',
21 isa => Str,
22 required => 1
23 );
3fb92fdf 24
25 has 'columns' => (
28bd628e 26 traits => ['Hash'],
3fb92fdf 27 is => 'rw',
28 isa => HashRef[Column],
28bd628e 29 handles => {
30 exists_column => 'exists',
31 column_ids => 'keys',
32 get_columns => 'values',
33 get_column => 'get',
34 add_column => 'set',
452c34e6 35 clear_columns => 'clear',
3fb92fdf 36 },
37 default => sub { my %hash = (); tie %hash, 'Tie::IxHash'; return \%hash },
38 );
39
40 has 'on_table' => (
41 is => 'rw',
42 isa => Str,
37ae885e 43 required => 1,
44# trigger => sub { my ($self, $new, $old) = @_; $self->table($self->schema->get_table($new)) },
3fb92fdf 45 );
46
47 has 'action' => (
48 is => 'rw',
c53f9843 49 isa => Any
3fb92fdf 50 );
51
52 has 'perform_action_when' => (
53 is => 'rw',
54 isa => Str,
55 required => 1
56 );
57
37ae885e 58 has '_database_events' => (
37ae885e 59 traits => ['Array'],
3fb92fdf 60 isa => ArrayRef,
37ae885e 61 handles => {
8bc0d91f 62 _database_events => 'elements',
f2600b26 63 add_database_event => 'push',
37ae885e 64 remove_last_database_option => 'pop',
65 },
66 default => sub { [] },
67 required => 1,
3fb92fdf 68 );
69
51700db2 70 around add_column(Column $column) { $self->$orig($column->name, $column) }
37ae885e 71
72 multi method database_events(Str $database_event) { $self->add_database_event($database_event); $self->database_events }
73 multi method database_events(ArrayRef $database_events) { $self->add_database_event($_) for @$database_events; $self->database_events }
5b7d1de7 74 multi method database_events { $self->_database_events }
4f4fd192 75}