Brad Lhotsky wrote:
> I'm considering converting the mix of Late 90s CGI Environment and Pure
> Mason mod_perl to a Catalyst system at work.  I _really_ like Mason and
> would like to continue using it for the View section.
>
> Does anyone have some examples for best practices or pitfalls for
> developing with Mason as the View in a Catalyst environment?  Maybe my
> google searches were terrible, but I wasn't able to find a good set of
> examples on how to integrate the two without causing too much overlap in
> the Controller part of the framework?
>
>   
    The following is an answer I got last year on the Catalyst mailing 
list, it worked for me, but I haven't really done much more than play 
with it.

=cut
create lib/MyApp/View/Mason.pm and within it, put one line to define the 
temporary directory where apache will put its object files. I use an 
application-specific directory since I have a number of different 
catalyst apps and the mason defaults will clobber each other otherwise:

  package MyApp::View::Mason;

  use strict;
  use base 'Catalyst::View::Mason';

  __PACKAGE__->config->{data_dir} = "/workplace/MyApp/data";

  1;

And then in lib/MyApp/Controller/Root.pm, I put a default subby like the 
following which will serve any page out of the root/ directory as a 
mason component. That way I don't have to keep defining controllers for 
everything when I want to put most of my development application logic 
in mason components anyway (that way I don't have to keep reloading 
apache on HUGE applications that catalyst takes forever to load as a cgi):

  sub default : Private {
     my ( $self, $c ) = @_;

     # what directory our default mason components are in:
     my $f = $c->path_to('root', @{$c->req->args});

     if ( -f $f ) {
         $c->stash->{template} = $f->relative($c->path_to('root')) ."";
         $c->forward("MyApp::View::Mason");
     }
  }

I have an override in apache for root/static for all those unprotected  
things I don't want catalyst to touch, like dojo, yui, images, css, etc.

The use of lib/MyApp/Controller/Root.pm suggests a more recent version 
of Catalyst. If you dont have a root controller, it's time to upgrade.

$c is available in every mason component, and so is $m like normal. Hope 
that helps. Glad to see not everyone is drinking the TT2 kool-aid :-)

:goose
=cut

Hope this helps

Justin


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Mason-users mailing list
Mason-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mason-users

Reply via email to