NAME
SQL::Translator::Schema::Object - Base class SQL::Translator Schema objects.
SYNOPSIS
DESCSIPTION
Base class for Schema objects. Sub classes Class::Base and adds the following extra functionality.
Construction
Derived classes should declare their attributes using the _attributes
method. They can then inherit the init
method from here which will call accessors of the same name for any values given in the hash passed to new
. Note that you will have to impliment the accessors your self and we expect perl style methods; call with no args to get and with arg to set.
e.g. If we setup our class as follows;
package SQL::Translator::Schema::Table;
use base qw/SQL::Translator::Schema::Object/;
__PACKAGE__->_attributes( qw/schema name/ );
sub name { ... }
sub schema { ... }
Then we can construct it with
my $table = SQL::Translator::Schema::Table->new(
schema => $schema,
name => 'foo',
);
and init will call $table->name("foo")
and $table->schema($schema)
to set it up. Any undefined args will be ignored.
Multiple calls to _attributes
are cumulative and sub classes will inherit their parents attribute names.
This is currently experimental, but will hopefull go on to form an introspection API for the Schema objects.
Global Attributes
The following attributes are defined here, therefore all schema objects will have them.
extra
Get or set the objects "extra" attibutes (e.g., "ZEROFILL" for MySQL fields). Call with no args to get all the extra data. Call with a single name arg to get the value of the named extra attribute, returned as a scalar. Call with a hash or hashref to set extra attributes. Returns a hash or a hashref.
$field->extra( qualifier => 'ZEROFILL' );
$qualifier = $field->extra('qualifier');
%extra = $field->extra;
$extra = $field->extra;
remove_extra
"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/);
equals
Determines if this object is the same as another.
my $isIdentical = $object1->equals( $object2 );
SEE ALSO
TODO
BUGS
AUTHOR
Ken Youens-Clark <kclark@cpan.org>, Mark Addison <mark.addison@itn.co.uk>.