perl-modperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tatsuhiko Miyagawa <>
Subject ANNOUNCE: Class::Trigger 0.03
Date Tue, 25 Dec 2001 10:28:40 GMT
Class::Trigger is a mixin class to invoke triggers (or hooks) in
arbitrary point, which can be registered from outside the class.
Useful for extending your own framework like Class::DBI. (In fact,
this module first implementation is extracted out from Class::DBI


has entered CPAN as

  file: $CPAN/authors/id/M/MI/MIYAGAWA/Class-Trigger-0.03.tar.gz
  size: 3651 bytes
   md5: 052ed38aaf3d6b9820fa71b46937dd57

    Class::Trigger - Mixin to add / call inheritable triggers

      package Foo;
      use Class::Trigger;

      sub foo {
          my $self = shift;

      package main;
      Foo->add_trigger(before_foo => \&sub1);
      Foo->add_trigger(after_foo => \&sub2);

      my $foo = Foo->new;
      $foo->foo;                    # then sub1, sub2 called

      # triggers are inheritable
      package Bar;
      use base qw(Foo);

      Bar->add_trigger(before_foo => \&sub);

      # triggers can be object based
      $foo->add_hook(after_foo => \&sub3);
      $foo->foo;                    # sub3 would appply only to this object

    Class::Trigger is a mixin class to add / call triggers (or hooks) that
    get called at some points you specify.

    By using this module, your class is capable of following two methods.

          Foo->add_trigger($triggerpoint => $sub);
          $foo->add_trigger($triggerpoint => $sub);

        Adds triggers for trigger point. You can have any number of triggers
        for each point. Each coderef will be passed a copy of the object,
        and return values will be ignored.

        If "add_trigger" is called as object method, whole trigger table
        will be copied onto the object. Then the object should be
        implemented as hash.

          my $foo = Foo->new;

          # this trigger ($sub_foo) would apply only to $foo object
          $foo->add_trigger($triggerpoint => $sub_foo);

          # And not to another $bar object
          my $bar = Foo->new;


        Calls triggers for trigger point, which were added via "add_trigger"
        method. Each triggers will be passed a copy of the object.

    By default you can make any number of trigger points, but if you want to
    declare names of trigger points explicitly, you can do it via "import".

      package Foo;
      use Class::Trigger qw(foo bar baz);

      package main;
      Foo->add_trigger(foo  => \&sub1); # okay
      Foo->add_trigger(hoge => \&sub2); # exception

    Original idea by Tony Bowden <> in Class::DBI.

    Code by Tatsuhiko Miyagawa <>.

    This library is free software; you can redistribute it and/or modify it
    under the same terms as Perl itself.

    the Class::Data::Inheritable manpage

Tatsuhiko Miyagawa <>

View raw message