Callerid - Perl extension for interpreting raw caller ID information (a la AT#CID=2)


Callerid documentation  | view source Contained in the Callerid distribution.

Index


NAME

Top

Callerid - Perl extension for interpreting raw caller ID information (a la AT#CID=2)

SYNOPSIS

Top

  use Callerid;
  my($hex) = "8024010830...";

  # OO-style
  my($cid) = new Callerid($hex);
  print $cid->{name}; # prints callers name

  -or-

  # Procedural style
  my(%cid) = Callerid::parse_raw_cid_string($hex);
  print $cid{name}; # prints callers name

  # prints phone number pretty
  print Callerid::format_phone_number($cid{number});

DESCRIPTION

Top

The Callerid module aims to provide a quick and easy method (YMMV) of decoding raw caller ID information as supplied by a modem.

This module does not talk to modems. It also does not mangle input. If you don't supply a hex string of the right format then you lose.

Methods

$cid = Callerid->new()

$cid = Callerid->new($string_of_hex)

Returns a newly created Callerid object. If you supply it with a hex string then (assuming it's not malformed) it will populate data fields in the new Callerid object appropriately.

Currently the (public) fields provided are: name number hour minute month day.

$cid->parse_raw_cid_string($string_of_hex)

%info = Callerid::parse_raw_cid_string($string_of_hex)

When called as an object method parse_raw_cid_string() will fill the objects data fields with appropriate information. When called as a class method parse_raw_cid_string() will return a hash with the same data fields.

$pretty_number = $cid->format_phone_number()

$pretty_number = Callerid::format_phone_number($number)

When called as an object method, format_phone_number() will return the object's number field formatted pretty. When called as a class method, format_phone_number() will take a single argument and will do the same thing.

"Formatted pretty" means 7-digit phone numbers become ###-####, 10-digit numbers become ###-###-####, 11-digit numbers become #-###-###-#### and everything else is passed through unchanged.

EXPORT

None by default.

SAMPLE CODE

Top

 use Callerid;

 # read in a list of raw caller ID codes
 while(<>) {
 	chomp;
 	s/#.*$//; # remove comments
 	s/^\s*//; # remove leading spaces
 	s/\s*$//; # remove trailing spaces
 	next unless $_; # skip if there's nothing left

 	my($cid);
 	eval {
 		$cid = new Callerid($_);
 	};

 	if($@) {
 		warn "error parsing $_: $@";
 	} else {
 		printf "%s parses to name=%s number=%s date=%02d/%02d time=%02d:%02d\n",
 			$_,
 			$cid->{name},
 			$cid->format_phone_number(),
 			$cid->{month},
 			$cid->{day},
 			$cid->{hour},
 			$cid->{minute};
 	}
 }

SEE ALSO

Top

Device::Modem to do I/O with a modem.

Modem command set for putting modem into caller ID mode

AUTHOR

Top

Mike Carr, <mcarr@pachogrande.com>

COPYRIGHT AND LICENSE

Top


Callerid documentation  | view source Contained in the Callerid distribution.