73ca50fb65421de5e10be9aac5f5c048a0889488
[freeside.git] / FS / FS / part_router_field.pm
1 package FS::part_router_field;
2
3 use strict;
4 use vars qw( @ISA );
5 use FS::Record qw( qsearchs );
6 use FS::router_field;
7 use FS::router;
8
9
10 @ISA = qw( FS::Record );
11
12 =head1 NAME
13
14 FS::part_router_field - Object methods for part_router_field records
15
16 =head1 SYNOPSIS
17
18   use FS::part_router_field;
19
20   $record = new FS::part_router_field \%hash;
21   $record = new FS::part_router_field { 'column' => 'value' };
22
23   $error = $record->insert;
24
25   $error = $new_record->replace($old_record);
26
27   $error = $record->delete;
28
29   $error = $record->check;
30
31 =head1 DESCRIPTION
32
33 A part_router_field represents an xfield definition for routers.  For more
34 information on xfields, see L<FS::part_sb_field>.
35
36 The following fields are supported:
37
38 =over 4
39
40 =item routerfieldpart - primary key (assigned automatically)
41
42 =item name - name of field
43
44 =item length
45
46 =item check_block
47
48 =item list_source
49
50 (See L<FS::part_sb_field> for details on these fields.)
51
52 =head1 METHODS
53
54 =over 4
55
56 =item new HASHREF
57
58 Create a new record.  To add the record to the database, see "insert".
59
60 =cut
61
62 sub table { 'part_router_field'; }
63
64 =item insert
65
66 Adds this record to the database.  If there is an error, returns the error,
67 otherwise returns false.
68
69 =item delete
70
71 Deletes this record from the database.  If there is an error, returns the
72 error, otherwise returns false.
73
74 =item replace OLD_RECORD
75
76 Replaces OLD_RECORD with this one in the database.  If there is an error,
77 returns the error, otherwise returns false.
78
79 =item check
80
81 Checks all fields to make sure this is a valid record.  If there is an error,
82 returns the error, otherwise returns false.  Called by the insert and replace
83 methods.
84
85 =cut
86
87 sub check {
88   my $self = shift;
89   my $error = '';
90
91   $self->name =~ /^([a-z0-9_\-\.]{1,15})$/i
92     or return "Invalid field name for part_router_field";
93
94   ''; #no error
95 }
96
97 =item list_values
98
99 Equivalent to "eval($part_router_field->list_source)".
100
101 =cut
102
103 sub list_values {
104   my $self = shift;
105   return () unless $self->list_source;
106   my @opts = eval($self->list_source);
107   if($@) { 
108     warn $@;
109     return ();
110   } else { 
111     return @opts;
112   }
113 }
114
115 =back
116
117 =head1 VERSION
118
119 $Id: 
120
121 =head1 BUGS
122
123 Needless duplication of much of FS::part_sb_field, with the result that most of
124 the warnings about it apply here also.
125
126 =head1 SEE ALSO
127
128 FS::svc_broadband, FS::router, FS::router_field,  schema.html
129 from the base documentation.
130
131 =cut
132
133 1;
134