[Catalyst] writing a test suite for my app

Daniel McBrearty danielmcbrearty at gmail.com
Mon May 15 00:11:36 CEST 2006


ok, here is the controller , minus docs ... (I changed teh method from
"index" to "natlang" as I remember seeing that cat treats "index" specially
... just to see if it was  to do with that. seems to be the same ...)

package Engoi::Controller::Public;

use strict;
use warnings;
use base 'Catalyst::Controller';

sub default : Private {
    my ( $self, $c ) = @_;
    $c->log->debug("Public::default : redirecting to home");
    $c->res->redirect('home');
}

sub natlang : Local {
    my ( $self, $c ) = @_;
    $c->stash->{langs} = getLangsAsArray($c);
}

sub home : Local {
    my ( $self, $c ) = @_;
    # blah
}


sub menu : Local {
    my ( $self, $c ) = @_;
    # more blah
}

# helper method
sub getLangsAsArray
{
    my ($c, $natlang) = @_; # exclude this if it is defined
    my $all_langs = $c->getLangs(); # TODO use database for this ...
    my $count = 0;
    my $table_width = 4;
    my $langs = [];
    my $row = [];
    foreach my $l (@$all_langs)
    {
        unless (defined $natlang && $l eq $natlang)
        {
            $row = [] if ($count % $table_width == 0); # start of row?
            push @$row, $l;
            $count++;
            push @$langs, $row if ($count % $table_width == ($table_width -
1));
        }
    }
    # we don't bother to pad out last element
    # as it works and the code validates OK
    return $langs;
}

1;



-- 
Daniel McBrearty
email : danielmcbrearty at gmail.com
www.engoi.com : the multi - language vocab trainer
BTW : 0873928131
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.rawmode.org/pipermail/catalyst/attachments/20060515/de2ead9b/attachment.htm 


More information about the Catalyst mailing list