Introduction to Mason 17

Another Component Example: latest_projects.mas

<table width="100%" bgcolor="#CCCCCC"
       cellspacing="0" cellpadding="5">
 <tr>
  <td colspan="2" align="center" class="heading">
   <h2 class="headline">Latest projects</h2>
  </td>
 </tr>
</table>
<table width="100%" bgcolor="#CCCCCC"
       cellspacing="0" cellpadding="3">
% if ($count) {
%   while (my $project = $projects->next) {
 <tr>
  <td>
   <a href="<& /lib/url.mas,
               path => '/project/'
                       . $project->project_id . '.html' &>">
    <% $project->name | h %></a>
  </td>
  <td>
   <& /lib/format_date.mas,
      date => $project->creation_date, short => 1 &>
  </td>
 </tr>
%   }
 <tr>
  <td colspan="2">&nbsp;</td>
 </tr>
 <tr>
  <td colspan="2">
   <% $count %> project<% $count > 1 ? 's' : '' %>
   in the system.
  </td>
 </tr>
% } else {
 <tr>
  <td colspan="2">No projects in the system.</td>
 </tr>
% }
</table>
<%init>
my $count = $Schema->Project_t->row_count;

my $projects = $Schema->Project_t->all_rows
  ( order_by => [ $Schema->Project_t->creation_date_c, 'desc',
                  $Schema->Project_t->name_c,          'asc' ],
    limit => 5,
  );
</%init>