1 package SQL::Translator::Schema::Role::Extra;
5 SQL::Translator::Schema::Role::Extra - "extra" attribute for schema classes
11 with qw(SQL::Translator::Schema::Role::Extra);
15 This role provides methods to set and get a hashref of extra attributes
21 use Sub::Quote qw(quote_sub);
28 Get or set the objects "extra" attributes (e.g., "ZEROFILL" for MySQL fields).
29 Call with no args to get all the extra data.
30 Call with a single name arg to get the value of the named extra attribute,
31 returned as a scalar. Call with a hash or hashref to set extra attributes.
32 Returns a hash or a hashref.
34 $field->extra( qualifier => 'ZEROFILL' );
36 $qualifier = $field->extra('qualifier');
38 %extra = $field->extra;
39 $extra = $field->extra;
43 has extra => ( is => 'rwp', default => quote_sub(q{ +{} }) );
46 my ($orig, $self) = (shift, shift);
48 @_ = %{$_[0]} if ref $_[0] eq "HASH";
49 my $extra = $self->$orig;
52 return $extra->{$_[0]};
56 while ( my ( $key, $value ) = each %args ) {
57 $extra->{$key} = $value;
61 return wantarray ? %$extra : $extra;
66 L</extra> can only be used to get or set "extra" attributes but not to
67 remove some. Call with no args to remove all extra attributes that
68 have been set before. Call with a list of key names to remove
69 certain extra attributes only.
71 # remove all extra attributes
72 $field->remove_extra();
74 # remove timezone and locale attributes only
75 $field->remove_extra(qw/timezone locale/);
80 my ( $self, @keys ) = @_;
82 $self->_set_extra({});
85 delete @{$self->extra}{@keys};