This commit was manufactured by cvs2svn to create branch 'freeside_import'.
[freeside.git] / site_perl / dbdef_colgroup.pm
1 package FS::dbdef_colgroup;
2
3 use strict;
4 use vars qw(@ISA);
5
6 @ISA = qw(Exporter);
7
8 =head1 NAME
9
10 FS::dbdef_colgroup - Column group objects
11
12 =head1 SYNOPSIS
13
14   use FS::dbdef_colgroup;
15
16   $colgroup = new FS::dbdef_colgroup ( $lol );
17   $colgroup = new FS::dbdef_colgroup (
18     [
19       [ 'single_column' ],
20       [ 'multiple_columns', 'another_column', ],
21     ]
22   );
23
24   @sql_lists = $colgroup->sql_list;
25
26   @singles = $colgroup->singles;
27
28 =head1 DESCRIPTION
29
30 FS::dbdef_colgroup objects represent sets of sets of columns.
31
32 =head1 METHODS
33
34 =over 4
35
36 =item new
37
38 Creates a new FS::dbdef_colgroup object.
39
40 =cut
41
42 sub new {
43   my($proto, $lol) = @_;
44
45   my $class = ref($proto) || $proto;
46   my $self = {
47     'lol' => $lol,
48   };
49
50   bless ($self, $class);
51
52 }
53
54 =item sql_list
55
56 Returns a flat list of comma-separated values, for SQL statements.
57
58 =cut
59
60 sub sql_list { #returns a flat list of comman-separates lists (for sql)
61   my($self)=@_;
62    grep $_ ne '', map join(', ', @{$_}), @{$self->{'lol'}};
63 }
64
65 =item singles
66
67 Returns a flat list of all single item lists.
68
69 =cut
70
71 sub singles { #returns single-field groups as a flat list
72   my($self)=@_;
73   #map ${$_}[0], grep scalar(@{$_}) == 1, @{$self->{'lol'}};
74   map { 
75     ${$_}[0] =~ /^(\w+)$/
76       #aah!
77       or die "Illegal column ", ${$_}[0], " in colgroup!";
78     $1;
79   } grep scalar(@{$_}) == 1, @{$self->{'lol'}};
80 }
81
82 =back
83
84 =head1 BUGS
85
86 =head1 SEE ALSO
87
88 L<FS::dbdef_table>, L<FS::dbdef_unique>, L<FS::dbdef_index>,
89 L<FS::dbdef_column>, L<FS::dbdef>, L<perldsc>
90
91 =head1 HISTORY
92
93 class for dealing with groups of groups of columns (used as a base class by
94 FS::dbdef_{unique,index} )
95
96 ivan@sisd.com 98-apr-19
97
98 added singles, fixed sql_list to skip empty lists ivan@sisd.com 98-jun-2
99
100 untaint things we're returning in sub singels ivan@sisd.com 98-jun-4
101
102 pod ivan@sisd.com 98-sep-24
103
104 =cut
105
106 1;
107