Alzabo

 view release on metacpan or  search on metacpan

lib/Alzabo/Index.pm  view on Meta::CPAN

package Alzabo::Index;

use strict;
use vars qw($VERSION);

use Alzabo;

use Tie::IxHash;

$VERSION = 2.0;

1;

sub columns
{
    my $self = shift;

    my @c;
    foreach my $c ($self->{columns}->Keys)
    {
        push @c, ($self->{columns}->FETCH($c))->{column};
    }

    return @c;
}

sub prefix
{
    my $self = shift;
    my $c = shift;

    Alzabo::Exception::Params->throw( error => "Column " . $c->name . " is not part of index." )
        unless $self->{columns}->EXISTS( $c->name );

    return ($self->{columns}->FETCH( $c->name ))->{prefix};
}

sub unique { $_[0]->{unique} }

sub fulltext { $_[0]->{fulltext} }

sub function { $_[0]->{function} }

sub id
{
    my $self = shift;

    my $function;

    if ( defined $self->function )
    {
        ($function) = $self->function =~ /^(\w+)/;
    }

    return join '___', ( $self->{table}->name,
# making this change would break schemas when the user tries to
# delete/drop the index.  save for later, maybe?

#                        ( $self->unique ? 'U' : () ),
#                        ( $self->fulltext ? 'F' : () ),
                         ( $function ? $function : () ),
                         ( map { $_->name, $self->prefix($_) || () }
                           $self->columns ),
                       );
}

sub table
{
    my $self = shift;

    return $self->{table};
}

__END__

=head1 NAME

Alzabo::Index - Index objects

=head1 SYNOPSIS

  foreach my $i ($table->indexes)
  {
     foreach my $c ($i->columns)
     {
        print $c->name;
        print '(' . $i->prefix($c) . ')' if $i->prefix($c);
    }
 }

=head1 DESCRIPTION



( run in 1.310 second using v1.01-cache-2.11-cpan-75ffa21a3d4 )