From a71d67e04a9f414f7d02a9db0d13115eb04231f1 Mon Sep 17 00:00:00 2001 From: Mike Taylor Date: Wed, 10 May 2006 15:51:10 +0000 Subject: [PATCH] Guard against the possibility of zero connection in the Pod. Handling of errors during wait(): they are detected, passed to a callback if one has been defined, or thrown as exceptions otherwise. Log unhandled events. Skeleton of proper documentation. --- lib/ZOOM/Pod.pm | 67 +++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 60 insertions(+), 7 deletions(-) diff --git a/lib/ZOOM/Pod.pm b/lib/ZOOM/Pod.pm index 9a72b07..1907d9b 100644 --- a/lib/ZOOM/Pod.pm +++ b/lib/ZOOM/Pod.pm @@ -1,4 +1,4 @@ -# $Id: Pod.pm,v 1.3 2006-05-09 16:31:05 mike Exp $ +# $Id: Pod.pm,v 1.4 2006-05-10 15:51:10 mike Exp $ package ZOOM::Pod; @@ -7,6 +7,16 @@ use warnings; use ZOOM; +BEGIN { + # Just register the name + ZOOM::Log::mask_str("pod"); + ZOOM::Log::mask_str("pod_unhandled"); +} + +=head1 NAME + +ZOOM::Pod - Perl extension for handling pods of concurrent ZOOM connections + =head1 SYNOPSIS use ZOOM::Pod; @@ -33,21 +43,26 @@ use ZOOM; return 0; } -=cut +=head1 DESCRIPTION -BEGIN { - # Just register the name - ZOOM::Log::mask_str("pod"); -} +I<###> + +=head1 METHODS + +=cut sub new { my $class = shift(); my(@conn) = @_; + die "$class with no connections" if @conn == 0; my @state; # Hashrefs with application state associated with connections foreach my $conn (@conn) { if (!ref $conn) { $conn = new ZOOM::Connection($conn, 0, async => 1); + # The $conn object is always made, even if no there's no + # server. Such errors are caught later, by the _check() + # call in wait(). } push @state, {}; } @@ -96,12 +111,27 @@ sub wait { while ((my $i = ZOOM::event($this->{conn})) != 0) { my $conn = $this->{conn}->[$i-1]; my $ev = $conn->last_event(); - ZOOM::Log::log("pod", "connection ", $i-1, ": ", ZOOM::event_str($ev)); + my $evstr = ZOOM::event_str($ev); + ZOOM::Log::log("pod", "connection ", $i-1, ": $evstr"); + + eval { + $conn->_check(); + }; if ($@) { + my $sub = $this->{callback}->{exception}; + die $@ if !defined $sub; + $res = &$sub($conn, $this->{state}->[$i-1], + $this->{rs}->[$i-1], $@); + last if $res != 0; + next; + } + my $sub = $this->{callback}->{$ev}; if (defined $sub) { $res = &$sub($conn, $this->{state}->[$i-1], $this->{rs}->[$i-1], $ev); last if $res != 0; + } else { + ZOOM::Log::log("pod_unhandled", "unhandled event $ev ($evstr)"); } } @@ -109,4 +139,27 @@ sub wait { } +=head1 SEE ALSO + +The underlying +C +module (part of the +C +distribution). + +=head1 AUTHOR + +Mike Taylor, Emike@indexdata.comE + +=head1 COPYRIGHT AND LICENCE + +Copyright (C) 2006 by Index Data. + +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. + +=cut + + 1; -- 1.7.10.4