FAQ
i am overriding a handful of catalyst methods so that i can inject
some custom debugging/timing code into the request cycle.

in MyApp.pm, i have methods

handle_request
prepare
dispatch
forward
finalize

that each do their thing and then return $c->NEXT::foo(@_) or $c-
SUPER::foo(@_), but i am having a difficult time telling when i
should use SUPER and when i should use NEXT.

recent benchmarks pointing to the slowness of NEXT (plus the
annoyances caused by stepping into a NEXT call in the debugger) has
led me to use SUPER instead where it seems safe, and trial and error
has led to apparently needing NEXT for finalize, while SUPER works
for the others, but i am not convinced it is Right.

could/should i just call NEXT for all of them? or is NEXT only
appropriate for certain overrides? is there an easy way to determine
when to use one versus the other?

Search Discussions

  • Jay Shirley at Nov 20, 2006 at 10:04 pm
    Take a look at Class::C3 and next::method, much faster than using NEXT
    and you still get the benefits.

    -J
    On 11/20/06, Michael Reece wrote:
    i am overriding a handful of catalyst methods so that i can inject
    some custom debugging/timing code into the request cycle.

    in MyApp.pm, i have methods

    handle_request
    prepare
    dispatch
    forward
    finalize

    that each do their thing and then return $c->NEXT::foo(@_) or $c-
    SUPER::foo(@_), but i am having a difficult time telling when i
    should use SUPER and when i should use NEXT.

    recent benchmarks pointing to the slowness of NEXT (plus the
    annoyances caused by stepping into a NEXT call in the debugger) has
    led me to use SUPER instead where it seems safe, and trial and error
    has led to apparently needing NEXT for finalize, while SUPER works
    for the others, but i am not convinced it is Right.

    could/should i just call NEXT for all of them? or is NEXT only
    appropriate for certain overrides? is there an easy way to determine
    when to use one versus the other?



    _______________________________________________
    List: Catalyst@lists.rawmode.org
    Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
    Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
    Dev site: http://dev.catalyst.perl.org/
  • Michael Reece at Nov 20, 2006 at 10:50 pm
    i will, but not until the warnings in Catalyst::Plugin::C3 are less
    foreboding.

    but let's pretend i am talking about Class::C3 instead; my question
    still stands.

    should i just call next::method in all cases, or is it only
    appropriate for certain overrides? is there an easy way to determine
    when to use one (NEXT or Class::C3) versus the other (SUPER)?
    On Nov 20, 2006, at 2:04 PM, J. Shirley wrote:

    Take a look at Class::C3 and next::method, much faster than using NEXT
    and you still get the benefits.

    -J
    On 11/20/06, Michael Reece wrote:
    i am overriding a handful of catalyst methods so that i can inject
    some custom debugging/timing code into the request cycle.

    in MyApp.pm, i have methods

    handle_request
    prepare
    dispatch
    forward
    finalize

    that each do their thing and then return $c->NEXT::foo(@_) or $c-
    SUPER::foo(@_), but i am having a difficult time telling when i
    should use SUPER and when i should use NEXT.

    recent benchmarks pointing to the slowness of NEXT (plus the
    annoyances caused by stepping into a NEXT call in the debugger) has
    led me to use SUPER instead where it seems safe, and trial and error
    has led to apparently needing NEXT for finalize, while SUPER works
    for the others, but i am not convinced it is Right.

    could/should i just call NEXT for all of them? or is NEXT only
    appropriate for certain overrides? is there an easy way to determine
    when to use one versus the other?



    _______________________________________________
    List: Catalyst@lists.rawmode.org
    Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
    Searchable archive: http://www.mail-archive.com/
    catalyst@lists.rawmode.org/
    Dev site: http://dev.catalyst.perl.org/
    _______________________________________________
    List: Catalyst@lists.rawmode.org
    Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
    Searchable archive: http://www.mail-archive.com/
    catalyst@lists.rawmode.org/
    Dev site: http://dev.catalyst.perl.org/
    ---
    michael reece :: software engineer :: mreece@vinq.com


    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20061120/4239a130/attachment.htm
  • Brandon Black at Nov 21, 2006 at 12:05 am

    On 11/20/06, Michael Reece wrote:
    i will, but not until the warnings in Catalyst::Plugin::C3 are less
    foreboding.

    but let's pretend i am talking about Class::C3 instead; my question still
    stands.

    should i just call next::method in all cases, or is it only appropriate for
    certain overrides? is there an easy way to determine when to use one (NEXT
    or Class::C3) versus the other (SUPER)?
    Generally speaking, it's more correct to always use NEXT or
    next::method instead of SUPER when working in an MI hierarchy based on
    NEXT or Class::C3. All three ways have very different sets of rules
    for walking @ISA. In many trivial cases, SUPER, NEXT, and
    next::method will all resolve your call in the same manner, but one
    subtle change in some underlying base class could break that and cause
    all three to resolve things differently from each other.

    -- Brandon
  • Matt S Trout at Nov 21, 2006 at 3:21 pm

    Michael Reece wrote:
    i will, but not until the warnings in Catalyst::Plugin::C3 are less
    foreboding.
    They're unlikely to get any less foreboding unless people test it and report
    back - you could at least *try* loading it and provide the results ...
    but let's pretend i am talking about Class::C3 instead; my question
    still stands.

    should i just call next::method in all cases, or is it only appropriate
    for certain overrides? is there an easy way to determine when to use
    one (NEXT or Class::C3) versus the other (SUPER)?
    I don't remember the last time I used SUPER.

    Then again, I never use the debugger, I'm of the "you can have (printf|warn)
    when you pry it from my cold, dead fingers" debugging school :)
  • Michael Reece at Nov 21, 2006 at 5:15 pm
    retracing my steps, i see that NEXT works for all of the methods i
    listed except 'forward'.

    sub forward {
    my $c = shift;
    my $action = shift;
    local $" = ", ";
    my @args = (@_ and ref $_[0] eq 'ARRAY') ? @{ $_[0] } : ();
    $c->timer(2, "Forward to " . (ref($action) || $action) .
    (@args ? "(@args)" : ''));
    return $c->NEXT::forward($action, @_);
    }

    with that, i get

    [debug] "GET" request for "/" from "x.x.x.x"
    [debug] Found sessionid "d4a42345c52677ec5e5ded26790e91edd4389287" in
    cookie
    [debug] Restored session "d4a42345c52677ec5e5ded26790e91edd4389287"
    [info] Request took 0.018640s (53.648/s)
    .----------------------------------------------------------------
    +-----------.
    Action |
    Time |
    +----------------------------------------------------------------
    +-----------+
    '----------------------------------------------------------------
    +-----------'

    but if i s/NEXT/SUPER/, then it works as expected.
    Then again, I never use the debugger, I'm of the "you can have
    (printf|warn) when you pry it from my cold, dead fingers" debugging
    school :)
    that it my usual method and works great for in-house code, but
    copying CPAN modules into my personal lib directories so i can fill
    them with warn statements has its own annoyances, so sometimes i
    resort to the debugger using the guidance of
    Catalyst::Manual::Tutorial::Debugging.


    On Nov 21, 2006, at 7:21 AM, Matt S Trout wrote:

    Michael Reece wrote:
    i will, but not until the warnings in Catalyst::Plugin::C3 are
    less foreboding.
    They're unlikely to get any less foreboding unless people test it
    and report back - you could at least *try* loading it and provide
    the results ...
    but let's pretend i am talking about Class::C3 instead; my
    question still stands.
    should i just call next::method in all cases, or is it only
    appropriate for certain overrides? is there an easy way to
    determine when to use one (NEXT or Class::C3) versus the other
    (SUPER)?
    I don't remember the last time I used SUPER.

    Then again, I never use the debugger, I'm of the "you can have
    (printf|warn) when you pry it from my cold, dead fingers" debugging
    school :)

    _______________________________________________
    List: Catalyst@lists.rawmode.org
    Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
    Searchable archive: http://www.mail-archive.com/
    catalyst@lists.rawmode.org/
    Dev site: http://dev.catalyst.perl.org/
    ---
    michael reece :: software engineer :: mreece@vinq.com


    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20061121/fbc74337/attachment.htm
  • Matt S Trout at Nov 21, 2006 at 11:21 pm

    Michael Reece wrote:
    retracing my steps, i see that NEXT works for all of the methods i
    listed except 'forward'.

    but if i s/NEXT/SUPER/, then it works as expected.
    Yep, that's because NEXT isn't re-entrant, and Catalyst's dispatch process
    involves nested forwards. This is why we suggested C3 which doesn't suffer
    from this problem.
    Then again, I never use the debugger, I'm of the "you can have
    (printf|warn) when you pry it from my cold, dead fingers" debugging
    school :)
    that it my usual method and works great for in-house code, but copying
    CPAN modules into my personal lib directories so i can fill them with
    warn statements has its own annoyances, so sometimes i resort to the
    debugger using the guidance of Catalyst::Manual::Tutorial::Debugging.
    I don't tend to find

    mkdir lib/Some/Module; cp `perldoc -l Some::Module::Name` lib/Some/Module/

    too much of a problem.

    Then again, I always run with -everything- installed in ~/perl for development
    at which point it's just

    chmod 644 `perldoc -l Some::Module::Name`
    vi `perldoc -l Some::Module::Name`

    which I've always found quicker than the debugger :)

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupcatalyst @
categoriescatalyst, perl
postedNov 20, '06 at 6:13p
activeNov 21, '06 at 11:21p
posts7
users4
websitecatalystframework.org
irc#catalyst

People

Translate

site design / logo © 2021 Grokbase