Class::DBI::Lite::TableInfo - Utility class for database table meta-information.


Class-DBI-Lite documentation Contained in the Class-DBI-Lite distribution.

Index


Code Index:

NAME

Top

Class::DBI::Lite::TableInfo - Utility class for database table meta-information.

SYNOPSIS

Top

  # Methods:
  my $info = Class::DBI::Lite::TableInfo->new( 'users' );
  $info->add_column(
    name          => 'user_id',
    type          => 'integer',
    length        => 10,
    is_nullable   => 0,
    default_value => undef,
    is_pk         => 1,
    key           => 'primary_key',
  );
  my $col = $info->column( 'user_id' );

  # Properties:
  my @cols = $info->columns();
  print $info->table; # "users"

DESCRIPTION

Top

Class::DBI::Lite::TableInfo provides a consistent means to discover the meta-info about tables and their fields in a database.

PUBLIC PROPERTIES

Top

table

Returns the name of the table.

columns

Returns a list of Class::DBI::Lite::ColumnInfo objects that pertain to the current table.

PUBLIC METHODS

Top

new( $table_name )

Returns a new Class::DBI::Lite::TableInfo object for the table named $table_name.

column( $name )

Returns a Class::DBI::Lite:ColumnInfo object that matches $name.

add_column( %args )

Adds a new Class::DBI::Lite::ColumnInfo object to the table's collection.

%args is passed to the Class::DBI::Lite::ColumnInfo constructor and should contain its required parameters.

AUTHOR

Top

John Drago <jdrago_999@yahoo.com>

http://www.devstack.com/

COPYRIGHT AND LICENSE

Top


Class-DBI-Lite documentation Contained in the Class-DBI-Lite distribution.

package Class::DBI::Lite::TableInfo;

use strict;
use warnings 'all';
use Class::DBI::Lite::ColumnInfo;


#==============================================================================
sub new
{
  my ($class, $table) = @_;
  return bless {
    table   => $table,
    columns => [ ]
  }, $class;
}# end new()


#==============================================================================
sub table
{
  $_[0]->{table};
}# end table()


#==============================================================================
sub columns
{
  @{ $_[0]->{columns} };
}# end columns()


#==============================================================================
sub column
{
  my ($s, $name) = @_;
  
  my ($item) = grep { $_->{name} eq $name } @{$s->{columns}};
  return $item;
}# end column()


#==============================================================================
sub add_column
{
  my ($s, %column) = @_;
  
  push @{$s->{columns}}, Class::DBI::Lite::ColumnInfo->new( %column );
}# end add_column()

1;# return true: