sub owl::startup { use DBI; use DateTime; use DateTime::Format::Strptime; $owl::strp = DateTime::Format::Strptime->new(pattern => "%a %b %d %T %Y"); } sub owl::db_connect { return if $owl::dbh and $owl::dbh->ping; $owl::dbh = DBI->connect("DBI:mysql:database=zephyr_log", "owl", "", {RaiseError => 1}); $owl::sth = $owl::dbh->prepare("INSERT INTO messages(sender, class, instance, opcode, sent, received, host, zsig, body) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"); } sub owl::receive_msg { my $msg = shift; return unless $msg->is_zephyr and not $msg->is_personal; my $sent = $owl::strp->parse_datetime($msg->time); owl::db_connect(); $owl::sth->execute($msg->sender, $msg->class, $msg->instance, $msg->opcode ? $msg->opcode : undef, $sent->datetime, DateTime->now->datetime, lc $msg->hostname, $msg->zsig, $msg->body, ); }