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

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});

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.
$cid = Callerid->new()$cid = Callerid->new($string_of_hex)Returns a newly created
Calleridobject. If you supply it with a hex string then (assuming it's not malformed) it will populate data fields in the newCalleridobject 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 methodparse_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.
None by default.

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};
}
}

Device::Modem to do I/O with a modem.
Modem command set for putting modem into caller ID mode

Mike Carr, <mcarr@pachogrande.com>

Copyright (C) 2004 by Mike Carr
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.4 or, at your option, any later version of Perl 5 you may have available.