95d854c0337e8d5ce0b166e7231795e54036bf74
[DBIx-DBSchema.git] / DBSchema / ColGroup.pm
1 package DBIx::DBSchema::ColGroup;
2
3 use strict;
4 use Carp;
5
6 =head1 NAME
7
8 DBIx::DBSchema::ColGroup - Column group objects
9
10 =head1 SYNOPSIS
11
12   use DBIx::DBSchema::ColGroup;
13
14   $colgroup = new DBIx::DBSchema::ColGroup ( $lol_ref );
15   $colgroup = new DBIx::DBSchema::ColGroup ( \@lol );
16   $colgroup = new DBIx::DBSchema::ColGroup (
17     [
18       [ 'single_column' ],
19       [ 'multiple_columns', 'another_column', ],
20     ]
21   );
22
23   $lol_ref = $colgroup->lol_ref;
24
25   @sql_lists = $colgroup->sql_list;
26
27   @singles = $colgroup->singles;
28
29 =head1 DESCRIPTION
30
31 This class is deprecated and included for backwards-compatibility only.
32 See L<DBIx::DBSchema::Index> for the current class used to store unique
33 and non-unique indices.
34
35 DBIx::DBSchema::ColGroup objects represent sets of sets of columns.  (IOW a
36 "list of lists" - see L<perllol>.)
37
38 =head1 METHODS
39
40 =over 4
41
42 =item new [ LOL_REF ]
43
44 Creates a new DBIx::DBSchema::ColGroup object.  Pass a reference to a list of
45 lists of column names.
46
47 =cut
48
49 sub new {
50   my($proto, $lol) = @_;
51
52   my $class = ref($proto) || $proto;
53
54   carp "WARNING: $proto is deprecated; switch to DBIx::DBSchema::Index";
55
56   my $self = {
57     'lol' => $lol,
58   };
59
60   bless ($self, $class);
61
62 }
63
64 =item lol_ref
65
66 Returns a reference to a list of lists of column names.
67
68 =cut
69
70 sub lol_ref {
71   my($self) = @_;
72   $self->{'lol'};
73 }
74
75 =item sql_list
76
77 Returns a flat list of comma-separated values, for SQL statements.
78
79 For example:
80
81   @lol = (
82            [ 'single_column' ],
83            [ 'multiple_columns', 'another_column', ],
84          );
85
86   $colgroup = new DBIx::DBSchema::ColGroup ( \@lol );
87
88   print join("\n", $colgroup->sql_list), "\n";
89
90 Will print:
91
92   single_column
93   multiple_columns, another_column
94
95 =cut
96
97 sub sql_list { #returns a flat list of comman-separates lists (for sql)
98   my($self)=@_;
99    grep $_ ne '', map join(', ', @{$_}), @{$self->{'lol'}};
100 }
101
102 =item singles
103
104 Returns a flat list of all single item lists.
105
106 =cut
107
108 sub singles { #returns single-field groups as a flat list
109   my($self)=@_;
110   #map ${$_}[0], grep scalar(@{$_}) == 1, @{$self->{'lol'}};
111   map { 
112     ${$_}[0] =~ /^(\w+)$/
113       #aah!
114       or die "Illegal column ", ${$_}[0], " in colgroup!";
115     $1;
116   } grep scalar(@{$_}) == 1, @{$self->{'lol'}};
117 }
118
119 =back
120
121 =head1 AUTHOR
122
123 Ivan Kohler <ivan-dbix-dbschema@420.am>
124
125 =head1 COPYRIGHT
126
127 Copyright (c) 2000 Ivan Kohler
128 Copyright (c) 2000 Mail Abuse Prevention System LLC
129 All rights reserved.
130 This program is free software; you can redistribute it and/or modify it under
131 the same terms as Perl itself.
132
133 =head1 BUGS
134
135 =head1 SEE ALSO
136
137 L<DBIx::DBSchema::Index>, L<DBIx::DBSchema::Table>,
138 L<DBIx::DBSchema::ColGroup::Unique>, L<DBIx::DBSchema::ColGroup::Index>,
139 L<DBIx::DBSchema>, L<perllol>, L<perldsc>, L<DBI>
140
141 =cut
142
143 1;
144