Subject: | Ping->parse : Interface inconsistency ? |
The parse method of the Ping object sometimes returns Message objects (to report errors) and sometimes returns a Ping object.
I would have prefered if it always returned the same class of object, because checking the type is not so aesthetic :
my $ping = Net::Trackback::Server->receive_ping($apr);
if (ref $ping eq 'Net::Trackback::Message') {
print STDERR "oops !\n" if $ping->is_success;
$apr->send_http_header('text/xml');
$apr->print($ping->to_xml);
}
Problem : It's an interface change, interface changes are risky.
Just suggestions according to my personnal feelings :
my $server = Net::Trackback::Server->new;
if (!$server->receive_ping($apr)) {
$apr->send_http_header('text/xml');
$apr->print($server->error->to_xml);
}
or
#...
my $msg = $server->receive_ping($apr);
if ($msg->is_error) {
# ...
}
$server->ping->blog_name;
or for fewer change
my ($msg, $ping) = Net::Trackback::Server->receive_ping($apr);
if ($msg->is_error) {
$apr->send_http_header('text/xml');
$apr->print($msg->to_xml);
}
$ping->blog_name
Regards,
Yann Kerherve