add wantarray for return and only push new options on if array has elements
[dbsrgits/SQL-Translator-2.0-ish.git] / lib / SQL / Translator / Object.pm
1 use MooseX::Declare;
2 class SQL::Translator::Object {
3     use Tie::IxHash;
4     use MooseX::MultiMethods;
5     use MooseX::Types::Moose qw(Any ArrayRef Str);
6
7     has '_comments' => (
8         metaclass => 'Collection::Array',
9         is => 'rw',
10         isa => ArrayRef,
11         provides => {
12             push => 'add_comment',
13             pop  => 'remove_last_comment',
14         },
15         default => sub { [] },
16         auto_deref => 1,
17     );
18
19     has '_options' => (
20         metaclass => 'Collection::Array',
21         is => 'rw',
22         isa => ArrayRef,
23         provides => {
24             push => 'add_option',
25             pop  => 'remove_last_option',
26         },
27         default => sub { [] },
28         auto_deref => 1,
29     );
30
31     multi method comments(Str $comment) { $self->add_comment($comment) }
32     multi method comments(ArrayRef $comment) { $self->add_comment($comment) }
33     multi method comments(Any $) { return wantarray ? @{$self->_comments} : join "\n", $self->_comments }
34
35     multi method options(Str $option) { $self->add_option($option) }
36     multi method options(ArrayRef $option) { $self->add_option($option) if scalar @$option }
37     multi method options(Any $) { wantarray ? @{$self->_options} : $self->_options }
38 }