3091d793732d4daa609c0bb61c152bfd34a0763b
[dbsrgits/SQL-Translator-2.0-ish.git] / lib / SQL / Translator / Object.pm
1 use MooseX::Declare;
2 class SQL::Translator::Object with SQL::Translator::Object::Compat {
3     use Tie::IxHash;
4     use MooseX::MultiMethods;
5     use MooseX::Types::Moose qw(Any ArrayRef HashRef Str);
6
7     has '_comments' => (
8         traits => ['Array'],
9         isa => ArrayRef,
10         coerce => 1,
11         handles => {
12             _comments           => 'elements',
13             add_comment         => 'push',
14             remove_last_comment => 'pop',
15         },
16         default => sub { [] },
17     );
18
19     has '_options' => (
20         traits => ['Array'],
21         isa => ArrayRef,
22         coerce => 1,
23         handles => {
24             _options           => 'elements',
25             add_option         => 'push',
26             remove_last_option => 'pop',
27         },
28         default => sub { [] },
29     );
30
31     has '_extra' => (
32         traits => ['Hash'],
33         is => 'rw',
34         isa => HashRef,
35         handles => {
36             exists_extra => 'exists',
37             extra_ids    => 'keys',
38             get_extras   => 'values',
39             get_extra    => 'get',
40             add_extra    => 'set',
41         },
42         default => sub { {} },
43     );
44
45     has '_error' => (
46         is => 'rw',
47         isa => Str
48     );
49
50     multi method comments(Str $comment) { $self->add_comment($comment); $self->comments }
51     multi method comments(ArrayRef $comments) { $self->add_comment($_) for @$comments; $self->comments }
52     multi method comments { wantarray ? $self->_comments : join "\n", $self->_comments }
53
54     multi method options(Str $option) { $self->add_option($option); $self->options }
55     multi method options(ArrayRef $options) { $self->add_option($_) for @$options; $self->options }
56     multi method options { wantarray ? $self->_options : $self->_options }
57
58     multi method extra(Str $extra) { $self->get_extra($extra) }
59     multi method extra(HashRef $extra) { $self->add_extra($_, $extra->{$_}) for keys %$extra; $self->extra }
60     multi method extra { wantarray ? %{$self->_extra} : $self->_extra }
61 }