[Catalyst] Need example of Catalyst with Mason View

August R. Wohlt catalyst at isidore.net
Sun Aug 13 13:39:46 CEST 2006


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} 
  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 
     if ( -f $f ) {
         $c->stash->{template}          $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 <jon at jrock.us> 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} > config->{'MyApp::View::Mason'} >
> 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: Catalyst at 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 at 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/
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.rawmode.org/pipermail/catalyst/attachments/20060813/dab7dacf/attachment.htm 


More information about the Catalyst mailing list