5b560a2e71890036403c8a764de49ddaa245b828
[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
82 =item delete
83
84 Delete this record from the database.
85
86 =cut
87
88 sub delete {
89   my($self)=@_;
90
91   $self->del;
92 }
93
94 =item replace OLD_RECORD
95
96 Replaces the OLD_RECORD with this one in the database.  If there is an error,
97 returns the error, otherwise returns false.
98
99 =cut
100
101 sub replace {
102   my($new,$old)=@_;
103   return "(Old) Not a table_name record!" unless $old->table eq "table_name";
104
105   return "Can't change keyfield!"
106      unless $old->getfield('keyfield') eq $new->getfield('keyfield');
107
108   $new->check or
109   $new->rep($old);
110 }
111
112
113 =item check
114
115 Checks all fields to make sure this is a valid example.  If there is
116 an error, returns the error, otherwise returns false.  Called by the insert
117 and repalce methods.
118
119 =cut
120
121 sub check {
122   my($self)=@_;
123   return "Not a table_name record!" unless $self->table eq "table_name";
124
125
126   ''; #no error
127 }
128
129 =head1 BUGS
130
131 The author forgot to customize this manpage.
132
133 =head1 SEE ALSO
134
135 L<FS::Record>
136
137 =head1 HISTORY
138
139 ivan@voicenet.com 97-jul-1
140
141 added hfields
142 ivan@sisd.com 97-nov-13
143
144 $Log: table_template.pm,v $
145 Revision 1.2  1998-11-15 03:48:49  ivan
146 update for current version
147
148
149 =cut
150
151 1;
152