1 package DBIx::DBSchema::Index;
4 use vars qw($VERSION $DEBUG);
11 DBIx::DBSchema::Index - Index objects
15 use DBIx::DBSchema::Index;
17 $index = new DBIx::DBSchema::Index (
24 DBIx::DBSchema::Index objects represent a unique or non-unique database index.
30 =item new HASHREF | OPTION, VALUE, ...
32 Creates a new DBIx::DBschema::Index object.
34 Accepts either a hashref or a list of options and values.
40 =item name - Index name
42 =item using - Optional index method
44 =item unique - Boolean indicating whether or not this is a unique index.
46 =item columns - List reference of column names (or expressions)
54 my $class = ref($proto) || $proto;
55 my %opt = ref($_[0]) ? %{$_[0]} : @_; #want a new reference
60 =item name [ INDEX_NAME ]
62 Returns or sets the index name.
67 my($self, $value) = @_;
68 if ( defined($value) ) {
69 $self->{name} = $value;
75 =item using [ INDEX_METHOD ]
77 Returns or sets the optional index method.
82 my($self, $value) = @_;
83 if ( defined($value) ) {
84 $self->{using} = $value;
86 defined($self->{using})
94 Returns or sets the unique flag.
99 my($self, $value) = @_;
100 if ( defined($value) ) {
101 $self->{unique} = $value;
104 $self->{unique} ? 1 : 0;
108 =item columns [ LISTREF ]
110 Returns or sets the indexed columns (or expressions).
115 my($self, $value) = @_;
116 if ( defined($value) ) {
117 $self->{columns} = $value;
125 Returns a comma-joined list of columns, suitable for an SQL statement.
131 join(', ', @{ $self->columns } );
134 =item sql_create_index TABLENAME
136 Returns an SQL statment to create this index on the specified table.
140 sub sql_create_index {
141 my( $self, $table ) = @_;
143 my $unique = $self->unique ? 'UNIQUE' : '';
144 my $name = $self->name;
145 my $col_sql = $self->columns_sql;
147 "CREATE $unique INDEX $name ON $table ( $col_sql )";
150 =item cmp OTHER_INDEX_OBJECT
152 Compares this object to another supplied object. Returns true if they are
153 identical, or false otherwise.
158 my( $self, $other ) = @_;
160 $self->name eq $other->name and $self->cmp_noname($other);
163 =item cmp_noname OTHER_INDEX_OBJECT
165 Compares this object to another supplied object. Returns true if they are
166 identical, disregarding index name, or false otherwise.
171 my( $self, $other ) = @_;
173 $self->using eq $other->using
174 and $self->unique == $other->unique
175 and $self->columns_sql eq $other->columns_sql;
183 Ivan Kohler <ivan-dbix-dbschema@420.am>
185 Copyright (c) 2007 Ivan Kohler
186 Copyright (c) 2007 Freeside Internet Services, Inc.
188 This program is free software; you can redistribute it and/or modify it under
189 the same terms as Perl itself.
193 Is there any situation in which sql_create_index needs to return a list of
198 L<DBIx::DBSchema::Table>, L<DBIx::DBSchema>, L<DBI>