Changeset 413

Show
Ignore:
Timestamp:
12/28/01 12:43:21
Author:
miyagawa
Message:

add FAQ

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • Class-Trigger/trunk/Changes

    r408 r413  
    11Revision history for Perl extension Class::Trigger. 
     2 
     30.04 
     4        - Added FAQ section in pod 
     5          (Thanks to people at POOP mailing list) 
    26 
    370.03  Tue Dec 25 03:30:31 JST 2001 
  • Class-Trigger/trunk/README

    r405 r413  
    7676      Foo->add_trigger(hoge => \&sub2); # exception 
    7777 
     78FAQ 
     79    Acknowledgement: Thanks to everyone at POOP mailing-list 
     80    (http://poop.sourceforge.net/). 
     81 
     82    Q.  This module lets me add subs to be run before/after a specific 
     83        subroutine is run. Yes? 
     84 
     85    A.  You put various call_trigger() method in your class. Then your class 
     86        users can call add_trigger() method to add subs to be run in points 
     87        just you specify (exactly where you put call_trigger()). 
     88 
     89    Q.  Are you aware of the perl-aspects project and the Aspect module? 
     90        Very similar to Class::Trigger by the look of it, but its not nearly 
     91        as explicit. Its not necessary for foo() to actually say "triggers 
     92        go *here*", you just add them. 
     93 
     94    A.  Yep ;) 
     95 
     96        But the difference with Aspect would be that Class::Trigger is so 
     97        simple that it's easy to learn, and doesn't require 5.6 or over. 
     98 
     99    Q.  How does this compare to Sub::Versive, or Hook::LexWrap? 
     100 
     101    A.  Very similar. But the difference with Class::Trigger would be the 
     102        explicitness of trigger points. 
     103 
     104        In addition, you can put hooks in any point, rather than pre or post 
     105        of a method. 
     106 
     107    Q.  It looks interesting, but I just can't think of a practical example 
     108        of its use... 
     109 
     110    A.  (by Tony Bowden) 
     111 
     112        I originally added code like this to Class::DBI to cope with one 
     113        particular case: auto-upkeep of full-text search indices. 
     114 
     115        So I added functionality in Class::DBI to be able to trigger an 
     116        arbitary subroutine every time something happened - then it was a 
     117        simple matter of setting up triggers on INSERT and UPDATE to reindex 
     118        that row, and on DELETE to remove that index row. 
     119 
     120        See the Class::DBI::mysql::FullTextSearch manpage and its source 
     121        code to see it in action. 
     122 
    78123AUTHOR 
    79124    Original idea by Tony Bowden <tony@kasei.com> in Class::DBI. 
  • Class-Trigger/trunk/lib/Class/Trigger.pm

    r408 r413  
    182182  Foo->add_trigger(hoge => \&sub2); # exception 
    183183 
     184=head1 FAQ 
     185 
     186B<Acknowledgement:> Thanks to everyone at POOP mailing-list 
     187(http://poop.sourceforge.net/). 
     188 
     189=over 4 
     190 
     191=item Q. 
     192 
     193This module lets me add subs to be run before/after a specific 
     194subroutine is run.  Yes? 
     195 
     196=item A. 
     197 
     198You put various call_trigger() method in your class.  Then your class 
     199users can call add_trigger() method to add subs to be run in points 
     200just you specify (exactly where you put call_trigger()). 
     201 
     202=item Q. 
     203 
     204Are you aware of the perl-aspects project and the Aspect module?  Very 
     205similar to Class::Trigger by the look of it, but its not nearly as 
     206explicit.  Its not necessary for foo() to actually say "triggers go 
     207*here*", you just add them. 
     208 
     209=item A. 
     210 
     211Yep ;) 
     212 
     213But the difference with Aspect would be that Class::Trigger is so 
     214simple that it's easy to learn, and doesn't require 5.6 or over. 
     215 
     216=item Q. 
     217 
     218How does this compare to Sub::Versive, or Hook::LexWrap? 
     219 
     220=item A. 
     221 
     222Very similar. But the difference with Class::Trigger would be the 
     223explicitness of trigger points. 
     224 
     225In addition, you can put hooks in any point, rather than pre or post 
     226of a method. 
     227 
     228=item Q. 
     229 
     230It looks interesting, but I just can't think of a practical example of 
     231its use... 
     232 
     233=item A. 
     234 
     235(by Tony Bowden) 
     236 
     237I originally added code like this to Class::DBI to cope with one 
     238particular case: auto-upkeep of full-text search indices. 
     239 
     240So I added functionality in Class::DBI to be able to trigger an 
     241arbitary subroutine every time something happened - then it was a 
     242simple matter of setting up triggers on INSERT and UPDATE to reindex 
     243that row, and on DELETE to remove that index row. 
     244 
     245See L<Class::DBI::mysql::FullTextSearch> and its source code to see it 
     246in action. 
     247 
     248=back 
     249 
    184250=head1 AUTHOR 
    185251 
  • Class-Trigger/trunk/t/01_trigger.t

    r400 r413  
    55 
    66use lib 't/lib'; 
    7 use Foo;                       # should be use() 
     7use Foo; 
    88 
    9 ok(Foo->add_trigger(before_foo => sub { print "before_foo\n" }), 'add_trigger'); 
    10 ok(Foo->add_trigger(after_foo  => sub { print "after_foo\n" }), 'add_trigger'); 
     9ok(Foo->add_trigger(before_foo => sub { print "before_foo\n" }), 
     10   'add_trigger in Foo'); 
     11ok(Foo->add_trigger(after_foo  => sub { print "after_foo\n" }), 
     12   'add_trigger in foo'); 
    1113 
    1214my $foo = Foo->new; 
     
    1921} 
    2022 
    21 ok(Foo->add_trigger(after_foo  => sub { print "after_foo2\n" }), 'add_trigger'); 
     23ok(Foo->add_trigger(after_foo  => sub { print "after_foo2\n" }), 
     24   'add_trigger in Foo'); 
    2225 
    2326{ 
     
    2831} 
    2932 
    30 ok(Foo->add_trigger(after_foo  => sub { print ref $_[0] }), 'add_trigger'); 
     33ok(Foo->add_trigger(after_foo  => sub { print ref $_[0] }), 
     34   'add_trigger in Foo'); 
    3135 
    3236{