FS::Record::qsearch - more portable, doesn't depend on $sth->execute returning
[freeside.git] / FS / FS / dbdef_colgroup.pm
1 package FS::dbdef_colgroup;
2
3 use strict;
4 use vars qw(@ISA);
5 use Exporter;
6
7 @ISA = qw(Exporter);
8
9 =head1 NAME
10
11 FS::dbdef_colgroup - Column group objects
12
13 =head1 SYNOPSIS
14
15   use FS::dbdef_colgroup;
16
17   $colgroup = new FS::dbdef_colgroup ( $lol );
18   $colgroup = new FS::dbdef_colgroup (
19     [
20       [ 'single_column' ],
21       [ 'multiple_columns', 'another_column', ],
22     ]
23   );
24
25   @sql_lists = $colgroup->sql_list;
26
27   @singles = $colgroup->singles;
28
29 =head1 DESCRIPTION
30
31 FS::dbdef_colgroup objects represent sets of sets of columns.
32
33 =head1 METHODS
34
35 =over 4
36
37 =item new
38
39 Creates a new FS::dbdef_colgroup object.
40
41 =cut
42
43 sub new {
44   my($proto, $lol) = @_;
45
46   my $class = ref($proto) || $proto;
47   my $self = {
48     'lol' => $lol,
49   };
50
51   bless ($self, $class);
52
53 }
54
55 =item sql_list
56
57 Returns a flat list of comma-separated values, for SQL statements.
58
59 =cut
60
61 sub sql_list { #returns a flat list of comman-separates lists (for sql)
62   my($self)=@_;
63    grep $_ ne '', map join(', ', @{$_}), @{$self->{'lol'}};
64 }
65
66 =item singles
67
68 Returns a flat list of all single item lists.
69
70 =cut
71
72 sub singles { #returns single-field groups as a flat list
73   my($self)=@_;
74   #map ${$_}[0], grep scalar(@{$_}) == 1, @{$self->{'lol'}};
75   map { 
76     ${$_}[0] =~ /^(\w+)$/
77       #aah!
78       or die "Illegal column ", ${$_}[0], " in colgroup!";
79     $1;
80   } grep scalar(@{$_}) == 1, @{$self->{'lol'}};
81 }
82
83 =back
84
85 =head1 BUGS
86
87 =head1 SEE ALSO
88
89 L<FS::dbdef_table>, L<FS::dbdef_unique>, L<FS::dbdef_index>,
90 L<FS::dbdef_column>, L<FS::dbdef>, L<perldsc>
91
92 =cut
93
94 1;
95