DBIx::SQLEngine::Schema::ColumnSet - Array of Schema::Column objects


DBIx-SQLEngine documentation Contained in the DBIx-SQLEngine distribution.

Index


Code Index:

NAME

Top

DBIx::SQLEngine::Schema::ColumnSet - Array of Schema::Column objects

SYNOPSIS

Top

  my $colset = DBIx::SQLEngine::Schema::ColumnSet->new( $column1, $column2 );

  print $colset->count;

  foreach my $column ( $colset->columns ) {
    print $column->name;
  }

  $column = $colset->column_named( $name );




DESCRIPTION

Top

DBIx::SQLEngine::Schema::ColumnSet objects contain an array of DBIx::SQLEngine::Schema::Column objects

REFERENCE

Top

Creation

new()
  DBIx::SQLEngine::Schema::ColumnSet->new( @columns ) : $colset

Basic array constructor.

Access to Columns

columns()
  $colset->columns () : @columns

Returns a list of column objects.

Column Names

column_names()
  $colset->column_names () : @column_names

Returns the result of calling name() on each column.

column_named()
  $colset->column_named ( $name ) : $column

Finds the column with that name, or dies trying.

SEE ALSO

Top

See DBIx::SQLEngine for the overall interface and developer documentation.

See DBIx::SQLEngine::Docs::ReadMe for general information about this distribution, including installation and license information.


DBIx-SQLEngine documentation Contained in the DBIx-SQLEngine distribution.
package DBIx::SQLEngine::Schema::ColumnSet;
use strict;
use Carp;

########################################################################

sub new {
  my $package = shift;
  my @cols = map {
    ( ref($_) eq 'HASH' ) ? DBIx::SQLEngine::Schema::Column->new_from_hash(%$_)
			  : $_
  } @_;
  bless \@cols, $package;
}

########################################################################

sub columns {
  my $colset = shift;
  @$colset
}

sub call_method_on_columns {
  my $columns = shift;
  my $method = shift;
  return map { $_->$method( @_ ) } @$columns;
}

########################################################################

# @colnames = $colset->column_names;
sub column_names {
  (shift)->call_method_on_columns( 'name' )
}

# $column = $colset->column_named( $column_name );
# $column = $colset->column_named( $column_name );
sub column_named {
  my $colset = shift;
  my $column_name = shift;
  foreach ( @$colset ) {
    return $_ if ( $_->name eq $column_name );
  }
  croak(
    "No column named $column_name in $colset->{name} table\n" . 
    "  (Perhaps you meant one of these: " . join(', ', map { $_->name() . " (". $_->type() .")" } @$colset) . "?)"
  );
}

########################################################################

########################################################################

1;