+=item parse_number [ OPTION => VALUE ... ]
+
+Returns two scalars, the countrycode and the rest of the number.
+
+Options are passed as name-value pairs. Currently available options are:
+
+=over 4
+
+=item column
+
+The column containing the number to be parsed. Defaults to dst.
+
+=item international_prefix
+
+The digits for international dialing. Defaults to '011' The value '+' is
+always recognized.
+
+=item domestic_prefix
+
+The digits for domestic long distance dialing. Defaults to '1'
+
+=back
+
+=cut
+
+sub parse_number {
+ my ($self, %options) = @_;
+
+ my $field = $options{column} || 'dst';
+ my $intl = $options{international_prefix} || '011';
+ # Still, don't break anyone's CDR rating if they have an empty string in
+ # there. Require an explicit statement that there's no prefix.
+ $intl = '' if lc($intl) eq 'none';
+ my $countrycode = '';
+ my $number = $self->$field();
+
+ my $to_or_from = 'concerning';
+ $to_or_from = 'from' if $field eq 'src';
+ $to_or_from = 'to' if $field eq 'dst';
+ warn "parsing call $to_or_from $number\n" if $DEBUG;
+
+ #remove non-phone# stuff and whitespace
+ $number =~ s/\s//g;
+# my $proto = '';
+# $dest =~ s/^(\w+):// and $proto = $1; #sip:
+# my $siphost = '';
+# $dest =~ s/\@(.*)$// and $siphost = $1; # @10.54.32.1, @sip.example.com
+
+ if ( $number =~ /^$intl(((\d)(\d))(\d))(\d+)$/
+ || $number =~ /^\+(((\d)(\d))(\d))(\d+)$/
+ )
+ {
+
+ my( $three, $two, $one, $u1, $u2, $rest ) = ( $1,$2,$3,$4,$5,$6 );
+ #first look for 1 digit country code
+ if ( qsearch('rate_prefix', { 'countrycode' => $one } ) ) {
+ $countrycode = $one;
+ $number = $u1.$u2.$rest;
+ } elsif ( qsearch('rate_prefix', { 'countrycode' => $two } ) ) { #or 2
+ $countrycode = $two;
+ $number = $u2.$rest;
+ } else { #3 digit country code
+ $countrycode = $three;
+ $number = $rest;
+ }
+
+ } else {
+ my $domestic_prefix =
+ exists($options{domestic_prefix}) ? $options{domestic_prefix} : '';
+ $countrycode = length($domestic_prefix) ? $domestic_prefix : '1';
+ $number =~ s/^$countrycode//;# if length($number) > 10;
+ }
+
+ return($countrycode, $number);
+
+}
+