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