#1
  1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2009
    Posts
    335
    Rep Power
    247

    Catalyst Routing - Clarification :confused:


    Hi,

    I've got my IIS7 Catalyst envioronment up and running and before I charge ahead with development, I was hoping for some clarification on a few things.

    $c->go / $c->forward / $c->detach / $c->visit

    I understand that forward / visit are linked, is it correct that forward only runs the method/action called and then returns back to the previous segment it was called from?

    So auto/begin/end are not executed in the controller where the method is being called?

    and so detach calls just the controller method and doesn't return or run auto/begin/end

    and go will not return but will execute the auto/begin/end.

    I've read this in the manual
    Keep in mind that the end method used is that of the caller action. So a $c->detach inside a forwarded action would run the end method from the original action requested.
    So it seems if you forward and then that call uses detach, the end in the detach command isn't executed but the one in the forward is?

    I'm confused.

    I thought detach stops all returning calls and runs the action/method without going back, so how come the end in the calling forward is executed?

    How do I call a method in a controller from either another controller or a model, which does not return back and finish any other chained calls, but does execute auto/begin/end in the newly called controller?

    is it $c->go ?

    Basically I have a controller 'Login' with a Private method and also an 'end' method.

    Code:
    sub locked :Private {   
        $c->stash->{message} = 'Sorry, system is currently undergoing maintenance, please try again later.';  
    }
    
    sub end :Private {
        
        $c->stash->{css} = 'login';         
        $c->stash(template => 'login.tp'); 
        
    }
    The first thing my app does before anything is authenticate the user. Part of that process is to check if the system flag for maintenace is set, if so, I don't care where in the chain of calls the application might be, I want it to stop, not return to anywhere, run the 'locked' method in the Login controller, including the 'end' method in the Login controller.

    is that detach, go, visit, forward or something else?

    Clarification is appreciated.
    Free MP3 Dance Music Downloads

    To err is human; To really balls things up you need Microsoft!
  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2009
    Posts
    335
    Rep Power
    247
    It's OK, I've got it all working now!

    It turns out that begin / auto methods are bad and shouldn't be used, well auto in 'Root' is OK , but that's it!

    Although their discussion is littered all over the Catalyst tutorial and CPAN docs, apparently it is bad and the 'Chained' attribute should now be used instead.

    Also there are other mechanism for ensuring something is ran such as
    Code:
    before 'index' => sub {
        
        my ( $self, $c ) = @_;    
    
        do_what_ever
    }
    another thing to note is the 'Catalyst::Session::Plugin' CPAN docs have wrong information in them ....
    Code:
     # To get sessions to "just work", all you need to do is use these plugins:
    
        use Catalyst qw/
          Session
          Session::Store::FastMmap
          Session::State::Cookie
          /;
    FastMmap should *not* be used and is broken apparently


    Instead it has been recommended that the following should be used instead.
    Code:
        Session  
        Session::Store::File
        Session::State::Cookie
    Hope it helps others
    Free MP3 Dance Music Downloads

    To err is human; To really balls things up you need Microsoft!

IMN logo majestic logo threadwatch logo seochat tools logo