1 package SQL::Translator::Schema::Role::Extra;
3 use Sub::Quote qw(quote_sub);
8 The following methods are defined here, therefore all schema objects
9 using this role will have them.
13 Get or set the objects "extra" attibutes (e.g., "ZEROFILL" for MySQL fields).
14 Call with no args to get all the extra data.
15 Call with a single name arg to get the value of the named extra attribute,
16 returned as a scalar. Call with a hash or hashref to set extra attributes.
17 Returns a hash or a hashref.
19 $field->extra( qualifier => 'ZEROFILL' );
21 $qualifier = $field->extra('qualifier');
23 %extra = $field->extra;
24 $extra = $field->extra;
28 has extra => ( is => 'rwp', default => quote_sub(q{ +{} }) );
31 my ($orig, $self) = (shift, shift);
33 @_ = %{$_[0]} if ref $_[0] eq "HASH";
34 my $extra = $self->$orig;
37 return exists($extra->{$_[0]}) ? $extra->{$_[0]} : undef ;
41 while ( my ( $key, $value ) = each %args ) {
42 $extra->{$key} = $value;
46 return wantarray ? %$extra : $extra;
51 L</extra> can only be used to get or set "extra" attributes but not to
52 remove some. Call with no args to remove all extra attributes that
53 have been set before. Call with a list of key names to remove
54 certain extra attributes only.
56 # remove all extra attributes
57 $field->remove_extra();
59 # remove timezone and locale attributes only
60 $field->remove_extra(qw/timezone locale/);
65 my ( $self, @keys ) = @_;
67 $self->_set_extra({});
70 delete @{$self->extra}{@keys};