Rechercher une page de manuel
Object::Event::Methods.3pm
Langue: en
Version: 2009-02-16 (fedora - 05/07/09)
Section: 3 (Bibliothèques de fonctions)
NAME
Object::Event::Methods - Syntactic sugar for Object::EventSYNOPSIS
package test; use base qw/Object::Event::Methods/; sub test_ev { my ($self, $a, $b) = @_; # ... } package main; my $t = test->new; $t->test_ev (1, 2); # will of course still call test_ev # like before # this call replaces the test_ev method in the test # package with something that invokes the 'test_ev' event, # and append a new callback to the call chain. $t->reg_cb (test_ev => sub { my ($self, $a, $b) = @_; # ... }); # and then this will first call the test_ev method in the test # package and after that the callback defined above. $t->test_ev (1, 2); # and that is effectively the same as this: $t->event (test_ev => 1, 2);
DESCRIPTION
This is a syntactic sugar module to Object::Event which:
- 1.
- Makes it easier to define default handlers for methods. Instead of doing this in a package:
package test; use base qw/Object::Event/; sub init { my ($self) = @_; $self->reg_cb ( test_event => \&test_event, after_test_event => \&after_test_event ); } sub test_event { my ($self, @args) = @_; # ... } sub after_test_event { my ($self, @args) = @_; # ... }
You can just do this:
package test; use base qw/Object::Event::Methods/; sub test_event { my ($self, @args) = @_; # ... } sub after_test_event { my ($self, @args) = @_; # ... }
- 2.
- You can invoke events, if they have either been callbacks for it registered, or a method defined for, via Perl's usual method call semantics:
Instead of this:
$obj->event (test => 1, 2, 3);
You can just use this:
$obj->test (1, 2, 3);
METHODS
- reg_cb ($eventname1, $cb1, [...])
- This method has the same arguments and return values as "reg_cb" of Object::Event has, with the exception that this method will (re)place methods with $eventname in the package of $self.
If a method was already defined it will be prepended to the arguments of "reg_cb" as event callback.
AUTHOR
Robin Redeker, "<elmex@ta-sa.org>"SEE ALSO
COPYRIGHT & LICENSE
Copyright 2009 Robin Redeker, all rights reserved.This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Contenus ©2006-2024 Benjamin Poulain
Design ©2006-2024 Maxime Vantorre