X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FSQL%2FTranslator%2FSchema%2FProcedure.pm;h=97e55cb054768e7bd0fa61549c24bf01e2c2f0dd;hb=da93ce6850901652d43fa1033a1ea58fa82230b4;hp=1768e1d219f4cd552835adbbf6ee629d1a979018;hpb=da06ac74ada30aacf656943306679a28605ad5c8;p=dbsrgits%2FSQL-Translator.git diff --git a/lib/SQL/Translator/Schema/Procedure.pm b/lib/SQL/Translator/Schema/Procedure.pm index 1768e1d..97e55cb 100644 --- a/lib/SQL/Translator/Schema/Procedure.pm +++ b/lib/SQL/Translator/Schema/Procedure.pm @@ -1,25 +1,5 @@ package SQL::Translator::Schema::Procedure; -# ---------------------------------------------------------------------- -# $Id: Procedure.pm 1440 2009-01-17 16:31:57Z jawnsy $ -# ---------------------------------------------------------------------- -# Copyright (C) 2002-2009 SQLFairy Authors -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License as -# published by the Free Software Foundation; version 2. -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -# 02111-1307 USA -# ------------------------------------------------------------------- - =pod =head1 NAME @@ -47,22 +27,15 @@ stored procedures (and possibly other pieces of nameable SQL code?). =cut -use strict; -use SQL::Translator::Utils 'parse_list_arg'; - -use base 'SQL::Translator::Schema::Object'; - -use vars qw($VERSION); +use Moo; +use SQL::Translator::Utils qw(ex2err); +use SQL::Translator::Role::ListAttr; +use SQL::Translator::Types qw(schema_obj); +use Sub::Quote qw(quote_sub); -$VERSION = '1.99'; +extends 'SQL::Translator::Schema::Object'; -# ---------------------------------------------------------------------- - -__PACKAGE__->_attributes( qw/ - name sql parameters comments owner sql schema order -/); - -=pod +our $VERSION = '1.60'; =head2 new @@ -72,11 +45,6 @@ Object constructor. =cut -# ---------------------------------------------------------------------- -sub parameters { - -=pod - =head2 parameters Gets and set the parameters of the stored procedure. @@ -91,27 +59,7 @@ Gets and set the parameters of the stored procedure. =cut - my $self = shift; - my $parameters = parse_list_arg( @_ ); - - if ( @$parameters ) { - my ( %unique, @unique ); - for my $p ( @$parameters ) { - next if $unique{ $p }; - $unique{ $p } = 1; - push @unique, $p; - } - - $self->{'parameters'} = \@unique; - } - - return wantarray ? @{ $self->{'parameters'} || [] } : ($self->{'parameters'} || ''); -} - -# ---------------------------------------------------------------------- -sub name { - -=pod +with ListAttr parameters => ( uniq => 1 ); =head2 name @@ -122,15 +70,7 @@ Get or set the procedure's name. =cut - my $self = shift; - $self->{'name'} = shift if @_; - return $self->{'name'} || ''; -} - -# ---------------------------------------------------------------------- -sub sql { - -=pod +has name => ( is => 'rw', default => quote_sub(q{ '' }) ); =head2 sql @@ -141,15 +81,7 @@ Get or set the procedure's SQL. =cut - my $self = shift; - $self->{'sql'} = shift if @_; - return $self->{'sql'} || ''; -} - -# ---------------------------------------------------------------------- -sub order { - -=pod +has sql => ( is => 'rw', default => quote_sub(q{ '' }) ); =head2 order @@ -160,15 +92,8 @@ Get or set the order of the procedure. =cut - my $self = shift; - $self->{'order'} = shift if @_; - return $self->{'order'}; -} +has order => ( is => 'rw' ); -# ---------------------------------------------------------------------- -sub owner { - -=pod =head2 owner @@ -179,15 +104,7 @@ Get or set the owner of the procedure. =cut - my $self = shift; - $self->{'owner'} = shift if @_; - return $self->{'owner'} || ''; -} - -# ---------------------------------------------------------------------- -sub comments { - -=pod +has owner => ( is => 'rw', default => quote_sub(q{ '' }) ); =head2 comments @@ -199,27 +116,24 @@ Get or set the comments on a procedure. =cut - my $self = shift; +has comments => ( + is => 'rw', + coerce => quote_sub(q{ ref($_[0]) eq 'ARRAY' ? $_[0] : [$_[0]] }), + default => quote_sub(q{ [] }), +); - for my $arg ( @_ ) { - $arg = $arg->[0] if ref $arg; - push @{ $self->{'comments'} }, $arg if $arg; - } +around comments => sub { + my $orig = shift; + my $self = shift; + my @comments = ref $_[0] ? @{ $_[0] } : @_; - if ( @{ $self->{'comments'} || [] } ) { - return wantarray - ? @{ $self->{'comments'} || [] } - : join( "\n", @{ $self->{'comments'} || [] } ); - } - else { - return wantarray ? () : ''; + for my $arg ( @comments ) { + $arg = $arg->[0] if ref $arg; + push @{ $self->$orig }, $arg if defined $arg && $arg; } -} - -# ---------------------------------------------------------------------- -sub schema { -=pod + return wantarray ? @{ $self->$orig } : join( "\n", @{ $self->$orig } ); +}; =head2 schema @@ -230,20 +144,9 @@ Get or set the procedures's schema object. =cut - my $self = shift; - if ( my $arg = shift ) { - return $self->error('Not a schema object') unless - UNIVERSAL::isa( $arg, 'SQL::Translator::Schema' ); - $self->{'schema'} = $arg; - } - - return $self->{'schema'}; -} - -# ---------------------------------------------------------------------- -sub equals { +has schema => ( is => 'rw', isa => schema_obj('Schema'), weak_ref => 1 ); -=pod +around schema => \&ex2err; =head2 equals @@ -253,14 +156,16 @@ Determines if this procedure is the same as another =cut +around equals => sub { + my $orig = shift; my $self = shift; my $other = shift; my $case_insensitive = shift; my $ignore_sql = shift; - - return 0 unless $self->SUPER::equals($other); + + return 0 unless $self->$orig($other); return 0 unless $case_insensitive ? uc($self->name) eq uc($other->name) : $self->name eq $other->name; - + unless ($ignore_sql) { my $selfSql = $self->sql; my $otherSql = $other->sql; @@ -272,29 +177,24 @@ Determines if this procedure is the same as another $otherSql =~ s/\s+/ /sg; return 0 unless $selfSql eq $otherSql; } - + return 0 unless $self->_compare_objects(scalar $self->parameters, scalar $other->parameters); # return 0 unless $self->comments eq $other->comments; # return 0 unless $case_insensitive ? uc($self->owner) eq uc($other->owner) : $self->owner eq $other->owner; return 0 unless $self->_compare_objects(scalar $self->extra, scalar $other->extra); return 1; -} +}; -# ---------------------------------------------------------------------- -sub DESTROY { - my $self = shift; - undef $self->{'schema'}; # destroy cyclical reference -} +# Must come after all 'has' declarations +around new => \&ex2err; 1; -# ---------------------------------------------------------------------- - =pod =head1 AUTHORS -Ken Y. Clark Ekclark@cshl.orgE, +Ken Youens-Clark Ekclark@cshl.orgE, Paul Harrington EPaul-Harrington@deshaw.comE. =cut