move backcompat into Compat.pm and apply the role to Object.pm
[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         handles => {
11             _comments           => 'elements',
12             add_comment         => 'push',
13             remove_last_comment => 'pop',
14         },
15         default => sub { [] },
16     );
17
18     has '_options' => (
19         traits => ['Array'],
20         isa => ArrayRef,
21         handles => {
22             _options           => 'elements',
23             add_option         => 'push',
24             remove_last_option => 'pop',
25         },
26         default => sub { [] },
27     );
28
29     has '_extra' => (
30         traits => ['Hash'],
31         is => 'rw',
32         isa => HashRef,
33         handles => {
34             exists_extra => 'exists',
35             extra_ids    => 'keys',
36             get_extras   => 'values',
37             get_extra    => 'get',
38             add_extra    => 'set',
39         },
40         default => sub { {} },
41     );
42
43     multi method comments(Str $comment) { $self->add_comment($comment); $self->comments }
44     multi method comments(ArrayRef $comments) { $self->add_comment($_) for @$comments; $self->comments }
45     multi method comments(Any $) { wantarray ? $self->_comments : join "\n", $self->_comments }
46
47     multi method options(Str $option) { $self->add_option($option); $self->options }
48     multi method options(ArrayRef $options) { $self->add_option($_) for @$options; $self->options }
49     multi method options(Any $) { wantarray ? $self->_options : $self->_options }
50
51     multi method extra(Str $extra) { $self->get_extra($extra) }
52     multi method extra(HashRef $extra) { $self->add_extra($_, $extra->{$_}) for keys %$extra; $self->extra }
53     multi method extra(Any $) { wantarray ? %{$self->_extra} : $self->_extra }
54 }