add skip_dcontext_suffix to skip CDRs with dcontext ending in a definable string...
[freeside.git] / FS / FS / areacode.pm
1 package FS::areacode;
2
3 use strict;
4 use base qw( FS::Record );
5 use FS::Record qw( qsearch qsearchs );
6
7 =head1 NAME
8
9 FS::areacode - Object methods for areacode records
10
11 =head1 SYNOPSIS
12
13   use FS::areacode;
14
15   $record = new FS::areacode \%hash;
16   $record = new FS::areacode { 'column' => 'value' };
17
18   $error = $record->insert;
19
20   $error = $new_record->replace($old_record);
21
22   $error = $record->delete;
23
24   $error = $record->check;
25
26 =head1 DESCRIPTION
27
28 An FS::areacode object represents an area code.  FS::areacode inherits from
29 FS::Record.  The following fields are currently supported:
30
31 =over 4
32
33 =item areanum - primary key
34
35 =item code - area code
36
37 =item country - two-letter country code
38
39 =item state - two-letter state code, if appropriate
40
41 =item description - description (optional)
42
43 =back
44
45 =head1 METHODS
46
47 =over 4
48
49 =cut
50
51 sub table { 'areacode'; }
52
53 =item insert
54
55 Adds this record to the database.  If there is an error, returns the error,
56 otherwise returns false.
57
58 =cut
59
60 =item delete
61
62 Delete this record from the database.
63
64 =cut
65
66 =item replace OLD_RECORD
67
68 Replaces the OLD_RECORD with this one in the database.  If there is an error,
69 returns the error, otherwise returns false.
70
71 =cut
72
73 =item check
74
75 Checks all fields to make sure this is a valid example.  If there is
76 an error, returns the error, otherwise returns false.  Called by the insert
77 and replace methods.
78
79 =cut
80
81 # the check method should currently be supplied - FS::Record contains some
82 # data checking routines
83
84 sub check {
85   my $self = shift;
86
87   my $error = 
88     $self->ut_numbern('areanum')
89     || $self->ut_number('code')
90     || $self->ut_text('country')
91     || $self->ut_textn('state')
92     || $self->ut_textn('description')
93   ;
94   return $error if $error;
95
96   $self->SUPER::check;
97 }
98
99 =back
100
101 =head1 CLASS METHODS
102
103 locate CODE
104
105 Returns the country, state, and description for an area code.
106
107 =cut
108
109 sub locate {
110   my $class = shift;
111   my $code = shift;
112   my $areacode = qsearchs('areacode', { code => $code })
113     or return ();
114   return ($areacode->country, $areacode->state, $areacode->description);
115 }
116
117 =head1 SEE ALSO
118
119 L<FS::Record>, schema.html from the base documentation.
120
121 =cut
122
123 1;
124