This commit was generated by cvs2svn to compensate for changes in r4407,
[freeside.git] / install / 5.005 / DBIx-DBSchema-0.23-5.005kludge / DBSchema / ColGroup.pm
1 package DBIx::DBSchema::ColGroup;
2
3 use strict;
4 use vars qw(@ISA);
5 #use Exporter;
6
7 #@ISA = qw(Exporter);
8 @ISA = qw();
9
10 =head1 NAME
11
12 DBIx::DBSchema::ColGroup - Column group objects
13
14 =head1 SYNOPSIS
15
16   use DBIx::DBSchema::ColGroup;
17
18   $colgroup = new DBIx::DBSchema::ColGroup ( $lol_ref );
19   $colgroup = new DBIx::DBSchema::ColGroup ( \@lol );
20   $colgroup = new DBIx::DBSchema::ColGroup (
21     [
22       [ 'single_column' ],
23       [ 'multiple_columns', 'another_column', ],
24     ]
25   );
26
27   $lol_ref = $colgroup->lol_ref;
28
29   @sql_lists = $colgroup->sql_list;
30
31   @singles = $colgroup->singles;
32
33 =head1 DESCRIPTION
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   my $self = {
54     'lol' => $lol,
55   };
56
57   bless ($self, $class);
58
59 }
60
61 =item lol_ref
62
63 Returns a reference to a list of lists of column names.
64
65 =cut
66
67 sub lol_ref {
68   my($self) = @_;
69   $self->{'lol'};
70 }
71
72 =item sql_list
73
74 Returns a flat list of comma-separated values, for SQL statements.
75
76 For example:
77
78   @lol = (
79            [ 'single_column' ],
80            [ 'multiple_columns', 'another_column', ],
81          );
82
83   $colgroup = new DBIx::DBSchema::ColGroup ( \@lol );
84
85   print join("\n", $colgroup->sql_list), "\n";
86
87 Will print:
88
89   single_column
90   multiple_columns, another_column
91
92 =cut
93
94 sub sql_list { #returns a flat list of comman-separates lists (for sql)
95   my($self)=@_;
96    grep $_ ne '', map join(', ', @{$_}), @{$self->{'lol'}};
97 }
98
99 =item singles
100
101 Returns a flat list of all single item lists.
102
103 =cut
104
105 sub singles { #returns single-field groups as a flat list
106   my($self)=@_;
107   #map ${$_}[0], grep scalar(@{$_}) == 1, @{$self->{'lol'}};
108   map { 
109     ${$_}[0] =~ /^(\w+)$/
110       #aah!
111       or die "Illegal column ", ${$_}[0], " in colgroup!";
112     $1;
113   } grep scalar(@{$_}) == 1, @{$self->{'lol'}};
114 }
115
116 =back
117
118 =head1 AUTHOR
119
120 Ivan Kohler <ivan-dbix-dbschema@420.am>
121
122 =head1 COPYRIGHT
123
124 Copyright (c) 2000 Ivan Kohler
125 Copyright (c) 2000 Mail Abuse Prevention System LLC
126 All rights reserved.
127 This program is free software; you can redistribute it and/or modify it under
128 the same terms as Perl itself.
129
130 =head1 BUGS
131
132 =head1 SEE ALSO
133
134 L<DBIx::DBSchema::Table>, L<DBIx::DBSchema::ColGroup::Unique>,
135 L<DBIx::DBSchema::ColGroup::Index>, L<DBIx::DBSchema>, L<perllol>, L<perldsc>,
136 L<DBI>
137
138 =cut
139
140 1;
141