Hiya Justin et al,

I used to use TT2 about 5 years ago, but switched to mason about 3 years ago. One of the better choices I've made IMHO. For catalyst, its setup is straightforward:

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



On 8/12/06, Jonathan Rockway <[EMAIL PROTECTED]> wrote:
Install Catalyst::Helper::View::Mason from CPAN, and then try this:

$ catalyst.pl MyApp
$ cd MyApp/
$ script/myapp_create view Mason Mason
$ perl Makefile.PL
$ make test

Uh.... actually, it appears that Catalyst::[Helper::]View::Mason is
broken.  The view it creates causes this error:

Couldn't instantiate component "MyApp::View::Mason", "The 'comp_root'
parameter ("/home/jon/tmp/MyApp/root") to HTML::Mason::Interp->new() was
a 'hashref object', which is not one of the allowed types: scalar arrayref"

I've never used Mason, so I don't know how to fix this.  However,
"/home/jon/tmp/MyApp/root" is a definitely not a "hashref object", so
the error message is pretty misleading.

Also, the documentation is wrong; Mason is ignoring my
__PACAKGE__->config->{comp_root} = "whatever", as well as the usual
config->{'MyApp::View::Mason'} = "whatever" and similar variants.

Looks like a bug.

Regards,
Jonathan Rockway


J Cook wrote:
> Hi All,
>
> Could anyone give me an example of a Catalyst setup with a Mason View?
> If you could show me the View/Mason.pm and directory structure that
> would help me mucho.
>
> TIA,
>
> Justin
>
> _______________________________________________
> List: [email protected]
> Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
> Searchable archive: http://www.mail-archive.com/[email protected]/
> Dev site: http://dev.catalyst.perl.org/
>




_______________________________________________
List: [email protected]
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/[email protected]/
Dev site: http://dev.catalyst.perl.org/




_______________________________________________
List: [email protected]
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/[email protected]/
Dev site: http://dev.catalyst.perl.org/

Reply via email to