[Catalyst] Perlcast 7 - Interview with our release minion Marcus:)

Alan Humphrey alan.humphrey at comcast.net
Tue May 3 17:59:54 CEST 2005


I don't claim to be an expert, but here's what I'm doing.  Maybe it'll
help you get started.

In my Controller I have this:

sub list : Local {
   my ( $self, $c ) = @_;
   $c->stash->{data} = BirdWeb::Admin::M::BirdWebDB::Birds->list() ;
   $c->stash->{template} = 'list';
   $c->stash->{headings} = ['', 'Common Name', 'Genus','Species'];
   $c->stash->{columns}  = ['image_file',
'bird_common_name','genus_scientific_name', 'species_scientific_name'];
   $c->forward('BirdWeb::Admin::V::View');
}

The Model (BirdWeb::Admin::M::BirdWebDB::Birds->list() ) has this (I'm
using Catalyst::Model::CDBI)

sub list {
  my @list = __PACKAGE__->search_list();
  return \@list;
}

The View ('BirdWeb::Admin::V::View') is just the generated code that
subclasses Catalyst::View::Mason.  Nothing to see there (literally).


The key in the code above is to set $c->stash->{template}.  If you fail
to set it you get an odd error (which I don't remember off the top of my
head).

The template ('list') is in the 'root' directory and looks like this:

<& mason/list.mas, headings => $c->stash->{headings},
	columns => $c->stash->{columns},
	data => $c->stash->{data} &>

I'm using an autohandler for the basic structure of my app, so this is
very simple.  As you see, all I'm doing is pulling out of the stash
those things I tucked into it in the controller - headings, columns, and
data.

My list.mas component (in root/mason) is pure mason:

<table class='list'>
<tr>
% foreach my $heading ( @headings ) {
<th><% $heading %> </th>
% }
</tr>
%my $counter = 0;
%foreach my $row ( @{$data} ) {
<tr<%  $counter % 2 ? " class='even'" : ''  %>>
%  $counter++;
%  foreach my $column ( @columns ) {
<td>
%    if ($row->$column =~ m/img:(\d*):(\d*):(.*)/ ) {
         <img src="<% $3 %>" height="<% $1 %>" width="<% $2 %>">
%    } else {
         <% $row->$column %> </td>
%    }
%  }
    <td><a href='edit/<% $row->id %>'>edit</a></td>
    <td><a href='detail/<% $row->id %>'>detail</a></td>
</tr>
% }

</table>

<%args>
@headings => ()
@columns  => ()
$data => ''
</%args>


I'm still working on the app but this is working for me so far.  Hope
this helps get you started.  Let me know if you have any questions.
Suggestions are also welcome.

- Alan


-----Original Message-----
From: catalyst-bounces at lists.rawmode.org
[mailto:catalyst-bounces at lists.rawmode.org] On Behalf Of Kevin Old
Sent: Tuesday, May 03, 2005 6:40 AM
To: Jesse Sheidlower
Cc: catalyst at lists.rawmode.org
Subject: Re: [Catalyst] Perlcast 7 - Interview with our release minion
Marcus:)

On 5/3/05, Jesse Sheidlower <jester at panix.com> wrote:
> On Tue, May 03, 2005 at 10:22:58AM -0400, Kevin Old wrote:
> >
> > Anyone know where the code that outputs to Mason templates (I think
> > it's a Wiki) is that he mentions in the interview?  I've checked the
> > Subversion repository and have found MojoMojo and a few other
projects
> > in the examples directory, but can't find any projects that use a
> > Mason view.
> 
> http://search.cpan.org/~sri/Catalyst-View-Mason-0.07/
> 
> perhaps?

I'm aware of Catalyst-View-Mason, but I thought that Marcus said in
the PerlCast that he was developing a Wiki that used it.  I'd like to
see some code that uses it, as I really want to port an exisiting
Mason app (with absolutely no framework)  to using the Catalyst
framework.  All of the examples I can find see to use TT.  If any of
the developers of Catalyst-View-Mason would send me some code, I'll
try to write a small app that uses Catalyst-View-Mason and add to the
examples directory.

Thanks for any help,
Kevin


-- 
Kevin Old
kevinold at gmail.com

_______________________________________________
Catalyst mailing list
Catalyst at lists.rawmode.org
http://lists.rawmode.org/mailman/listinfo/catalyst




More information about the Catalyst mailing list