8945a39d72b56111f1994ae4f08faf0073906fc4
[freeside.git] / site_perl / table_template.pm
1 package FS::table_name;
2
3 use strict;
4 use vars qw (@ISA);
5 use Exporter;
6 #use FS::UID qw(getotaker);
7 use FS::Record qw(hfields qsearch qsearchs);
8
9 @ISA = qw(FS::Record);
10
11 =head1 NAME
12
13 FS::table_name - Object methods for table_name records
14
15 =head1 SYNOPSIS
16
17   use FS::table_name;
18
19   $record = create FS::table_name \%hash;
20   $record = create FS::table_name { 'column' => 'value' };
21
22   $error = $record->insert;
23
24   $error = $new_record->replace($old_record);
25
26   $error = $record->delete;
27
28   $error = $record->check;
29
30 =head1 DESCRIPTION
31
32 An FS::table_name object represents an example.  FS::table_name inherits from
33 FS::Record.  The following fields are currently supported:
34
35 =over 4
36
37 =item field - description
38
39 =back
40
41 =head1 METHODS
42
43 =over 4
44
45 =item create HASHREF
46
47 Creates a new example.  To add the example to the database, see L<"insert">.
48
49 Note that this stores the hash reference, not a distinct copy of the hash it
50 points to.  You can ask the object for a copy with the I<hash> method.
51
52 =cut
53
54 sub create {
55   my($proto,$hashref)=@_;
56
57   $proto->new('table_name',$hashref);
58
59 }
60
61 =item insert
62
63 Adds this record to the database.  If there is an error, returns the error,
64 otherwise returns false.
65
66 =cut
67
68 sub insert {
69   my($self)=@_;
70
71   #local $SIG{HUP} = 'IGNORE';
72   #local $SIG{INT} = 'IGNORE';
73   #local $SIG{QUIT} = 'IGNORE';
74   #local $SIG{TERM} = 'IGNORE';
75   #local $SIG{TSTP} = 'IGNORE';
76
77   $self->check or
78   $self->add;
79 }
80
81 =item delete
82
83 Delete this record from the database.
84
85 =cut
86
87 sub delete {
88   my($self)=@_;
89
90   $self->del;
91 }
92
93 =item replace OLD_RECORD
94
95 Replaces the OLD_RECORD with this one in the database.  If there is an error,
96 returns the error, otherwise returns false.
97
98 =cut
99
100 sub replace {
101   my($new,$old)=@_;
102   return "(Old) Not a table_name record!" unless $old->table eq "table_name";
103
104   return "Can't change keyfield!"
105      unless $old->getfield('keyfield') eq $new->getfield('keyfield');
106
107   $new->check or
108   $new->rep($old);
109 }
110
111
112 =item check
113
114 Checks all fields to make sure this is a valid example.  If there is
115 an error, returns the error, otherwise returns false.  Called by the insert
116 and repalce methods.
117
118 =cut
119
120 sub check {
121   my($self)=@_;
122   return "Not a table_name record!" unless $self->table eq "table_name";
123
124
125   ''; #no error
126 }
127
128 =back
129
130 =head1 VERSION
131
132 $Id: table_template.pm,v 1.3 1998-11-15 04:33:00 ivan Exp $
133
134 =head1 BUGS
135
136 The author forgot to customize this manpage.
137
138 =head1 SEE ALSO
139
140 L<FS::Record>
141
142 =head1 HISTORY
143
144 ivan@voicenet.com 97-jul-1
145
146 added hfields
147 ivan@sisd.com 97-nov-13
148
149 $Log: table_template.pm,v $
150 Revision 1.3  1998-11-15 04:33:00  ivan
151 updates for newest versoin
152
153 Revision 1.2  1998/11/15 03:48:49  ivan
154 update for current version
155
156
157 =cut
158
159 1;
160