Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Separate callbacks for 'normal', non-fatal errors and fatal ones

  • Loading branch information...
commit ebbc675fd28759ac4155648c0c12ca1a13cf1c2b 1 parent bca2667
@sanko authored
Showing with 20 additions and 11 deletions.
  1. +6 −2 examples/client.pl
  2. +14 −9 lib/AnyEvent/MSN.pm
View
8 examples/client.pl
@@ -26,9 +26,13 @@
$msn->nudge($head->{From});
},
on_error => sub {
+ my ($msn, $msg) = @_;
+ warn 'Error: '. $msg;
+ },
+
+ on_fatal_error => sub {
my ($msn, $msg, $fatal) = @_;
- warn ucfirst sprintf '%serror: %s', ($fatal ? 'fatal ' : ''), $msg;
- return if !$fatal;
+ warn sprintf 'Fatal error: ' . $msg;
$msn->connected ? $msn->connect : $cv->send # auto-reconnect
}
);
View
23 lib/AnyEvent/MSN.pm
@@ -211,7 +211,7 @@ package AnyEvent::MSN 0.001;
)
for qw[
im nudge
- error connect
+ error fatal_error connect
addressbook_update
buddylist_update
user_notification
@@ -301,10 +301,10 @@ package AnyEvent::MSN 0.001;
$s->_set_ping_timer(AE::timer 120,
180, sub { $s->send('PNG') });
},
- on_connect_error => sub { $s->trigger_error(shift, 1) },
+ on_connect_error => sub { $s->trigger_fatal_error(shift) },
on_error => sub {
my $h = shift;
- $s->trigger_error(reverse @_);
+ $s->trigger_fatal_error(reverse @_);
$h->destroy;
},
on_eof => sub {
@@ -395,8 +395,9 @@ package AnyEvent::MSN 0.001;
sub _handle_packet_nfy {
my ($s, $type, $len, $headers, $data) = @_;
-
- #ddx $type, $len, $headers, $data;
+ use Data::Dump;
+ ddx $type, $len, $headers, $data;
+ ddx $s->_parse_xml($data);
given ($type) {
when ('PUT') {
my $xml = $s->_parse_xml($data);
@@ -413,6 +414,10 @@ package AnyEvent::MSN 0.001;
#
}
+ when ('DEL') {
+
+ # Remove from list
+ }
default {...}
}
}
@@ -890,11 +895,11 @@ XML
&& !defined $xml->{'S:Fault'};
#ddx $hdr;
- $s->trigger_error(
+ $s->trigger_fatal_error(
$xml->{'S:Fault'}{'soap:Reason'}{'soap:Text'}
{'content'} // $xml->{'S:Fault'}{'faultstring'}
- // $hdr->{Reason},
- 1
+ // $hdr->{Reason}
+
);
}
)
@@ -1007,7 +1012,7 @@ XML
$xml_twig->parse($data);
$xml = $xml_twig->simplify(keyattr => [qw[type id value]]);
}
- catch { $s->trigger_error(qq[parsing XML: $_], 1) };
+ catch { $s->trigger_fatal_error(qq[parsing XML: $_]) };
$xml;
}
Please sign in to comment.
Something went wrong with that request. Please try again.