Mark Stosberg wrote:
On 2005-06-17, Rhesa Rozendaal <[EMAIL PROTECTED]> wrote:
Has anybody ever mentioned Class::Trigger? It would be nice to have 'before_foo' and 'after_foo' triggers, for instance, and Class::Trigger has already proven its usefulness in Class::DBI.


I looked it in passing. If you try it with C::A, let us know how you
like it.

I've taken some time to see if I could rewrite the hook system with Class::Trigger, and it works except for all the tests in t/11callbacks.t (due to the different order in which callbacks are executed):

Failed Test     Stat Wstat Total Fail  Failed  List of Failed
-------------------------------------------------------------------------------
t/11callbacks.t    3   768     5    3  60.00%  2-4
Failed 1/12 test scripts, 91.67% okay. 3/160 subtests failed, 98.12% okay.

Before I continue, can I ask some questions about some of the design decisions you guys made?

- add_callback() accepts both a coderef and a string. Class::Trigger only accepts coderefs. Why did you decide to accept sub names as well?

- CT doesn't have the analog of new_hook(); it just creates the hook point when add_trigger is called for the first time. That looks sensible to me at first sight. What was the reason for the explicit new_hook()?

- CT says it executes hooks in the order they were registered. I _think_ this may be a drawback for us in the long run, as it doesn't give us control over the execution order at all. On the other hand, Mark decided to avoid the entire issue for now.

I'd like to stress that it's not my intention to change the current implementation. I'm just curious to see if I can get it to work with an already existing framework for triggers. I've read the posts that mentioned CT in the archives. It seems the execution order was the big thing back then, which is why it had never been seriously considered. As Mark noted quite correctly, it would add a dependency that many users wouldn't need. Then again, the callback code is _in_ cgiapp now, so that may not be such a big objection anymore.

So far this is just a weekend excursion for me. If there's any feedback, I might start to take it more seriously :-)

Rhesa

Complete test results:
athene:~/.cpan/build/CGI-Application-4.01$ make test
PERL_DL_NONLAZY=1 /usr/bin/perl "-MExtUtils::Command::MM" "-e" "test_harness(0, 'blib/lib', 'blib/arch')" t/*.t t/01cgiapp................ok t/02mailform..............ok t/03prerun................ok t/04getquery..............ok t/05arrayrefmodes.........ok t/06enhancement31.........ok t/07postrun...............ok t/09zerorm................ok t/10errormode.............ok t/11callbacks.............NOK 2
#     Failed test (t/11callbacks.t at line 370)
#     Structures begin differing at:
#          $got->[0] = 'init/My::App::cgiapp_init'
#     $expected->[0] = 'init/CGI::Application::Plugin::Bar::bar_init1'
Actual Event History:
$VAR1 = [
          'init/My::App::cgiapp_init',
          'init/CGI::Application::Plugin::Foo::foo_init1',
          'init/CGI::Application::Plugin::Foo::foo_init2',
          'init/My::Project::my_project_init',
          'init/CGI::Application::Plugin::Bar::bar_init1',
          'bar_hook/CGI::Application::Plugin::Bar::bar_custom',
          'init/CGI::Application::Plugin::Bar::bar_init2',
          'prerun/My::App::cgiapp_prerun',
          'prerun/CGI::Application::Plugin::Foo::foo_prerun',
          'prerun/CGI::Application::Plugin::Bar::bar_prerun',
          'prerun/My::App::my_app_class_prerun',
          'prerun/My::App::my_app_obj_prerun',
          'runmode/My::App::begin',
          'postrun/My::App::cgiapp_postrun',
          'postrun/CGI::Application::Plugin::Foo::foo_postrun',
          'postrun/CGI::Application::Plugin::Bar::bar_postrun',
          'teardown/My::App::teardown',
          'teardown/CGI::Application::Plugin::Foo::foo_teardown',
          'foo_hook/CGI::Application::Plugin::Foo::foo_custom',
          'teardown/CGI::Application::Plugin::Bar::bar_teardown',
          'teardown/My::App::my_app_teardown',
          'teardown/My::App::my_app_teardown'
        ];
t/11callbacks.............NOK 3
#     Failed test (t/11callbacks.t at line 438)
#     Structures begin differing at:
#          $got->[0] = 'init/My::App::cgiapp_init'
#     $expected->[0] = 'init/CGI::Application::Plugin::Bar::bar_init1'
Actual Event History:
$VAR1 = [
          'init/My::App::cgiapp_init',
          'init/CGI::Application::Plugin::Foo::foo_init1',
          'init/CGI::Application::Plugin::Foo::foo_init2',
          'init/My::Project::my_project_init',
          'init/CGI::Application::Plugin::Bar::bar_init1',
          'bar_hook/CGI::Application::Plugin::Bar::bar_custom',
          'init/CGI::Application::Plugin::Bar::bar_init2',
          'prerun/My::App::cgiapp_prerun',
          'prerun/CGI::Application::Plugin::Foo::foo_prerun',
          'prerun/CGI::Application::Plugin::Bar::bar_prerun',
          'prerun/My::App::my_app_class_prerun',
          'prerun/My::App::my_app_class_prerun',
          'runmode/My::App::begin',
          'postrun/My::App::cgiapp_postrun',
          'postrun/CGI::Application::Plugin::Foo::foo_postrun',
          'postrun/CGI::Application::Plugin::Bar::bar_postrun',
          'teardown/My::App::teardown',
          'teardown/CGI::Application::Plugin::Foo::foo_teardown',
          'foo_hook/CGI::Application::Plugin::Foo::foo_custom',
          'teardown/CGI::Application::Plugin::Bar::bar_teardown',
          'teardown/My::App::my_app_teardown',
          'teardown/My::App::my_app_teardown',
          'teardown/My::App::my_app_teardown'
        ];
t/11callbacks.............NOK 4
#     Failed test (t/11callbacks.t at line 512)
#     Structures begin differing at:
#          $got->[0] = 'init/Other::App::cgiapp_init'
#     $expected->[0] = 'init/CGI::Application::Plugin::Bam::bam_init1'
Actual Event History:
$VAR1 = [
          'init/Other::App::cgiapp_init',
          'init/My::Project::my_project_global_init',
          'init/CGI::Application::Plugin::Baz::baz_init1',
          'init/CGI::Application::Plugin::Baz::baz_init2',
          'init/CGI::Application::Plugin::Bam::bam_init1',
          'init/CGI::Application::Plugin::Bam::bam_init2',
          'init/Other::Project::other_project_init',
          'init/CGI::Application::Plugin::Bam::bam_init1',
          'init/CGI::Application::Plugin::Bam::bam_init2',
          'prerun/Other::App::cgiapp_prerun',
          'prerun/CGI::Application::Plugin::Baz::baz_prerun',
          'baz_hook/CGI::Application::Plugin::Baz::baz_custom',
          'prerun/CGI::Application::Plugin::Bam::bam_prerun',
          'prerun/CGI::Application::Plugin::Bam::bam_prerun',
          'runmode/Other::App::begin',
          'postrun/Other::App::cgiapp_postrun',
          'postrun/CGI::Application::Plugin::Baz::baz_postrun',
          'postrun/CGI::Application::Plugin::Bam::bam_postrun',
          'bam_hook/CGI::Application::Plugin::Bam::bam_custom',
          'bam_hook/CGI::Application::Plugin::Bam::bam_custom',
          'postrun/CGI::Application::Plugin::Bam::bam_postrun',
          'bam_hook/CGI::Application::Plugin::Bam::bam_custom',
          'bam_hook/CGI::Application::Plugin::Bam::bam_custom',
          'postrun/Other::App::other_app_postrun',
          'teardown/Other::App::teardown',
          'teardown/CGI::Application::Plugin::Baz::baz_teardown',
          'teardown/CGI::Application::Plugin::Bam::bam_teardown',
          'teardown/CGI::Application::Plugin::Bam::bam_teardown'
        ];
t/11callbacks.............ok 5/0# Looks like you failed 3 tests of 5. t/11callbacks.............dubious
        Test returned status 3 (wstat 768, 0x300)
DIED. FAILED tests 2-4
        Failed 3/5 tests, 40.00% okay
t/load_tmpl_hook..........ok t/mode_param_path_info....ok
Failed Test     Stat Wstat Total Fail  Failed  List of Failed
-------------------------------------------------------------------------------
t/11callbacks.t    3   768     5    3  60.00%  2-4
Failed 1/12 test scripts, 91.67% okay. 3/160 subtests failed, 98.12% okay.
make: *** [test_dynamic] Error 255

---------------------------------------------------------------------
Web Archive:  http://www.mail-archive.com/[email protected]/
             http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to