Upped version numbers, cleaned up code, fixed my name.
[dbsrgits/SQL-Translator.git] / lib / SQL / Translator / Schema / Object.pm
index 96cc00d..41ce4a7 100644 (file)
@@ -1,9 +1,7 @@
 package SQL::Translator::Schema::Object;
 
 # ----------------------------------------------------------------------
-# $Id: Object.pm,v 1.5 2005-06-27 21:58:42 duality72 Exp $
-# ----------------------------------------------------------------------
-# Copyright (C) 2002-4 SQLFairy Authors
+# 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
@@ -39,16 +37,15 @@ use strict;
 use Class::Base;
 use base 'Class::Data::Inheritable';
 use base 'Class::Base';
-use Data::Compare;
+use Class::MakeMethods::Utility::Ref qw( ref_compare );
 
 use vars qw[ $VERSION ];
 
-$VERSION = sprintf "%d.%02d", q$Revision: 1.5 $ =~ /(\d+)\.(\d+)/;
-
+$VERSION = '1.60';
 
 =head1 Construction
 
-Derived classes should decalare their attributes using the C<_attributes>
+Derived classes should declare their attributes using the C<_attributes>
 method. They can then inherit the C<init> method from here which will call
 accessors of the same name for any values given in the hash passed to C<new>.
 Note that you will have to impliment the accessors your self and we expect perl
@@ -153,6 +150,32 @@ Returns a hash or a hashref.
     return wantarray ? %$extra : $extra;
 }
 
+# ----------------------------------------------------------------------
+sub remove_extra {
+
+=head2 remove_extra
+
+L</extra> can only be used to get or set "extra" attributes but not to
+remove some. Call with no args to remove all extra attributes that
+have been set before. Call with a list of key names to remove
+certain extra attributes only.
+
+  # remove all extra attributes
+  $field->remove_extra(); 
+  
+  # remove timezone and locale attributes only
+  $field->remove_extra(qw/timezone locale/);
+
+=cut
+
+    my ( $self, @keys ) = @_;
+    unless (@keys) {
+        $self->{'extra'} = {};
+    }
+    else {
+        delete $self->{'extra'}{$_} for @keys;
+    }
+}
 
 # ----------------------------------------------------------------------
 sub equals {
@@ -171,17 +194,19 @@ Determines if this object is the same as another.
     my $other = shift;
     
     return 0 unless $other;
-    return 1 if $self eq $other;
+    return 1 if overload::StrVal($self) eq overload::StrVal($other);
     return 0 unless $other->isa( __PACKAGE__ );
     return 1;
 }
 
 # ----------------------------------------------------------------------
-sub _compare_objects($$;$) {
-       my $self = shift;
-       # Suppress spurious Data::Compare warnings
-       local $SIG{__WARN__} = sub {};
-       Data::Compare::Compare(shift, shift, shift);
+sub _compare_objects {
+       my $self   = shift;
+       my $obj1   = shift;
+       my $obj2   = shift;
+       my $result = (ref_compare($obj1, $obj2) == 0);
+
+       return $result;
 }
 
 #=============================================================================
@@ -190,14 +215,9 @@ sub _compare_objects($$;$) {
 
 =pod
 
-=head1 SEE ALSO
-
-=head1 TODO
-
-=head1 BUGS
-
 =head1 AUTHOR
 
-Ken Y. Clark E<lt>kclark@cpan.orgE<gt>, Mark Addison E<lt>mark.addison@itn.co.ukE<gt> 
+Ken Youens-Clark E<lt>kclark@cpan.orgE<gt>, 
+Mark Addison E<lt>mark.addison@itn.co.ukE<gt>.
 
 =cut