… | |
… | |
163 | |
163 | |
164 | The L<AnyEvent::TLS> object to use. See C<tls>, above. |
164 | The L<AnyEvent::TLS> object to use. See C<tls>, above. |
165 | |
165 | |
166 | =item on_XYZ => $coderef |
166 | =item on_XYZ => $coderef |
167 | |
167 | |
168 | You can specify event callbacks either by subclassing and overriding the |
168 | You can specify event callbacks either by sub-classing and overriding the |
169 | respective methods or by specifying coderefs as key-value pairs when |
169 | respective methods or by specifying code-refs as key-value pairs when |
170 | constructing the object. You add or remove event handlers at any time with |
170 | constructing the object. You add or remove event handlers at any time with |
171 | the C<event> method. |
171 | the C<event> method. |
172 | |
172 | |
173 | =back |
173 | =back |
174 | |
174 | |
… | |
… | |
178 | my $class = shift; |
178 | my $class = shift; |
179 | |
179 | |
180 | my $self = bless { |
180 | my $self = bless { |
181 | id => "a", |
181 | id => "a", |
182 | ids => [], |
182 | ids => [], |
183 | queue => [], # ininitially queue everything |
183 | queue => [], # initially queue everything |
184 | @_, |
184 | @_, |
185 | }, $class; |
185 | }, $class; |
186 | |
186 | |
187 | { |
187 | { |
188 | Scalar::Util::weaken (my $self = $self); |
188 | Scalar::Util::weaken (my $self = $self); |
… | |
… | |
465 | |
465 | |
466 | =back |
466 | =back |
467 | |
467 | |
468 | =head1 EVENTS |
468 | =head1 EVENTS |
469 | |
469 | |
470 | AnyEvent::Porttracker conenctions are fully event-driven, and naturally |
470 | AnyEvent::Porttracker connections are fully event-driven, and naturally |
471 | there are a number of events that can occur. All these events have a name |
471 | there are a number of events that can occur. All these events have a name |
472 | starting with C<on_> (example: C<on_login_failure>). |
472 | starting with C<on_> (example: C<on_login_failure>). |
473 | |
473 | |
474 | Programs can catch these events in two ways: either by providing |
474 | Programs can catch these events in two ways: either by providing |
475 | constructor arguments with the event name as key and a coderef as value: |
475 | constructor arguments with the event name as key and a code-ref as value: |
476 | |
476 | |
477 | my $api = new AnyEvent::Porttracker |
477 | my $api = new AnyEvent::Porttracker |
478 | host => ..., |
478 | host => ..., |
479 | user => ..., pass => ..., |
479 | user => ..., pass => ..., |
480 | on_error => sub { |
480 | on_error => sub { |
… | |
… | |
482 | warn $msg; |
482 | warn $msg; |
483 | exit 1; |
483 | exit 1; |
484 | }, |
484 | }, |
485 | ; |
485 | ; |
486 | |
486 | |
487 | Or by subclassing C<AnyEvent::Porttracker> and overriding methods of the |
487 | Or by sub-classing C<AnyEvent::Porttracker> and overriding methods of the |
488 | same name: |
488 | same name: |
489 | |
489 | |
490 | package MyClass; |
490 | package MyClass; |
491 | |
491 | |
492 | use base AnyEvent::Porttracker; |
492 | use base AnyEvent::Porttracker; |
… | |
… | |
540 | |
540 | |
541 | =item on_start_tls_notify $api |
541 | =item on_start_tls_notify $api |
542 | |
542 | |
543 | Called when the server wants to start TLS negotiation. This is used |
543 | Called when the server wants to start TLS negotiation. This is used |
544 | internally and - while it is possible to override it - should not be |
544 | internally and - while it is possible to override it - should not be |
545 | overriden. |
545 | overridden. |
546 | |
546 | |
547 | =item on_event_notify $api, $eventname, @args |
547 | =item on_event_notify $api, $eventname, @args |
548 | |
548 | |
549 | Called when the server broadcasts an event the API object is subscribed |
549 | Called when the server broadcasts an event the API object is subscribed |
550 | to. The default implementation (which should not be overridden) simply |
550 | to. The default implementation (which should not be overridden) simply |