X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FSQL%2FTranslator%2FObject.pm;h=82ee0b65d4f21e1eb1c4d9ac738195d1f76a84b8;hb=88765147fdd499da4c0c870d1da59e1f8f182f7b;hp=b593f023ead32203bb777d3d5db8893ee5f2ec01;hpb=b3cafe33d88446bade2be146b6d999c7a2a143a3;p=dbsrgits%2FSQL-Translator-2.0-ish.git diff --git a/lib/SQL/Translator/Object.pm b/lib/SQL/Translator/Object.pm index b593f02..82ee0b6 100644 --- a/lib/SQL/Translator/Object.pm +++ b/lib/SQL/Translator/Object.pm @@ -1,57 +1,71 @@ use MooseX::Declare; -class SQL::Translator::Object { +class SQL::Translator::Object with SQL::Translator::Object::Compat { use Tie::IxHash; use MooseX::MultiMethods; - use MooseX::Types::Moose qw(Any ArrayRef HashRef Str); + use MooseX::Types::Moose qw(ArrayRef HashRef Str); has '_comments' => ( - metaclass => 'Collection::Array', - is => 'rw', + traits => ['Array'], isa => ArrayRef, - provides => { - push => 'add_comment', - pop => 'remove_last_comment', + coerce => 1, + handles => { + _comments => 'elements', + add_comment => 'push', + remove_last_comment => 'pop', }, default => sub { [] }, - auto_deref => 1, ); has '_options' => ( - metaclass => 'Collection::Array', - is => 'rw', + traits => ['Array'], isa => ArrayRef, - provides => { - push => 'add_option', - pop => 'remove_last_option', + coerce => 1, + handles => { + _options => 'elements', + add_option => 'push', + remove_last_option => 'pop', }, default => sub { [] }, - auto_deref => 1, ); has '_extra' => ( - metaclass => 'Collection::Hash', + traits => ['Hash'], is => 'rw', isa => HashRef, - provides => { - exists => 'exists_extra', - keys => 'extra_ids', - values => 'get_extras', - get => 'get_extra', - set => 'add_extra', + handles => { + exists_extra => 'exists', + extra_ids => 'keys', + get_extras => 'values', + get_extra => 'get', + add_extra => 'set', }, default => sub { {} }, - auto_deref => 1, ); - multi method comments(Str $comment) { $self->add_comment($comment) } - multi method comments(ArrayRef $comments) { $self->add_comment($_) for @$comments } - multi method comments(Any $) { wantarray ? @{$self->_comments} : join "\n", $self->_comments } + has '_error' => ( + is => 'rw', + isa => Str + ); + + multi method comments(Str $comment) { $self->add_comment($comment); $self->comments } + multi method comments(ArrayRef $comments) { $self->add_comment($_) for @$comments; $self->comments } + multi method comments { wantarray ? $self->_comments : join "\n", $self->_comments } - multi method options(Str $option) { $self->add_option($option) } - multi method options(ArrayRef $options) { $self->add_option($_) for @$options } - multi method options(Any $) { wantarray ? @{$self->_options} : $self->_options } + multi method options(Str $option) { $self->add_option($option); $self->options } + multi method options(ArrayRef $options) { $self->add_option($_) for @$options; $self->options } + multi method options { wantarray ? $self->_options : $self->_options } multi method extra(Str $extra) { $self->get_extra($extra) } - multi method extra(HashRef $extra) { $self->_extra($extra) } - multi method extra(Any $) { wantarray ? %{$self->_extra} : $self->_extra } + multi method extra(HashRef $extra) { $self->add_extra($_, $extra->{$_}) for keys %$extra; $self->extra } + multi method extra { wantarray ? %{$self->_extra} : $self->_extra } + + around BUILDARGS(ClassName $self: @args) { + my $args = $self->$orig(@args); + + $args->{_comments} = delete $args->{comments} || []; + $args->{_options} = delete $args->{options} || []; + $args->{_extra} = delete $args->{extra} || {}; + + return $args; + } }