summaryrefslogtreecommitdiff
path: root/install/5.005/DBIx-DBSchema-0.23-5.005kludge/DBSchema/ColGroup.pm
blob: ceeb223cacc4b546f05aa1210cb17b166d03b8e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
package DBIx::DBSchema::ColGroup;

use strict;
use vars qw(@ISA);
#use Exporter;

#@ISA = qw(Exporter);
@ISA = qw();

=head1 NAME

DBIx::DBSchema::ColGroup - Column group objects

=head1 SYNOPSIS

  use DBIx::DBSchema::ColGroup;

  $colgroup = new DBIx::DBSchema::ColGroup ( $lol_ref );
  $colgroup = new DBIx::DBSchema::ColGroup ( \@lol );
  $colgroup = new DBIx::DBSchema::ColGroup (
    [
      [ 'single_column' ],
      [ 'multiple_columns', 'another_column', ],
    ]
  );

  $lol_ref = $colgroup->lol_ref;

  @sql_lists = $colgroup->sql_list;

  @singles = $colgroup->singles;

=head1 DESCRIPTION

DBIx::DBSchema::ColGroup objects represent sets of sets of columns.  (IOW a
"list of lists" - see L<perllol>.)

=head1 METHODS

=over 4

=item new [ LOL_REF ]

Creates a new DBIx::DBSchema::ColGroup object.  Pass a reference to a list of
lists of column names.

=cut

sub new {
  my($proto, $lol) = @_;

  my $class = ref($proto) || $proto;
  my $self = {
    'lol' => $lol,
  };

  bless ($self, $class);

}

=item lol_ref

Returns a reference to a list of lists of column names.

=cut

sub lol_ref {
  my($self) = @_;
  $self->{'lol'};
}

=item sql_list

Returns a flat list of comma-separated values, for SQL statements.

For example:

  @lol = (
           [ 'single_column' ],
           [ 'multiple_columns', 'another_column', ],
         );

  $colgroup = new DBIx::DBSchema::ColGroup ( \@lol );

  print join("\n", $colgroup->sql_list), "\n";

Will print:

  single_column
  multiple_columns, another_column

=cut

sub sql_list { #returns a flat list of comman-separates lists (for sql)
  my($self)=@_;
   grep $_ ne '', map join(', ', @{$_}), @{$self->{'lol'}};
}

=item singles

Returns a flat list of all single item lists.

=cut

sub singles { #returns single-field groups as a flat list
  my($self)=@_;
  #map ${$_}[0], grep scalar(@{$_}) == 1, @{$self->{'lol'}};
  map { 
    ${$_}[0] =~ /^(\w+)$/
      #aah!
      or die "Illegal column ", ${$_}[0], " in colgroup!";
    $1;
  } grep scalar(@{$_}) == 1, @{$self->{'lol'}};
}

=back

=head1 AUTHOR

Ivan Kohler <ivan-dbix-dbschema@420.am>

=head1 COPYRIGHT

Copyright (c) 2000 Ivan Kohler
Copyright (c) 2000 Mail Abuse Prevention System LLC
All rights reserved.
This program is free software; you can redistribute it and/or modify it under
the same terms as Perl itself.

=head1 BUGS

=head1 SEE ALSO

L<DBIx::DBSchema::Table>, L<DBIx::DBSchema::ColGroup::Unique>,
L<DBIx::DBSchema::ColGroup::Index>, L<DBIx::DBSchema>, L<perllol>, L<perldsc>,
L<DBI>

=cut

1;