#!/usr/bin/perl -- # Automatically enables "strict", "warnings", "utf8" and Perl 5.10 features use Mojolicious::Lite; sub my_sorted_fudge { ## has no pageination :P my( $sortorder, $sortindex ) = @_; $sortorder ||= ''; #~ $sortindex ||= 0; $sortindex = int $sortindex ; my %order = ( 'ascend' => sub { $$a[ $sortindex ] cmp $$b[ $sortindex ] }, 'descend' => sub { $$b[ $sortindex ] cmp $$a[ $sortindex ] }, '' => undef, # default sort order, none ); my $byorder = $order{ $sortorder }; my @th = ( "Ro", "Sham", "Bo" ); my @array = ( ["i", "f", "i"], ["q", "s", "n"], ["u", "g", "m"], ["j", "r", "n"], ["w", "r", "j"], ["q", "q", "n"], ["x", "p", "p"], ["o", "h", "b"], ["g", "x", "a"], ); $byorder and @array = sort $byorder @array; ## don't sort by default return \@array, \@th ; } sub mojo_index { my $self = shift; my $sortorder = $self->param('sortorder') || ''; my $sortindex = $self->param('sortindex') || 0; my( $rah, $rahth ) = my_sorted_fudge( $sortorder, $sortindex ); return $self->render( ray => $rah, rayth => $rahth, sortindex => $sortindex, sortorder => $sortorder, title => 'the sortening', ); } ## .ep templates are auto_escape <%= by default / XML escaped result get '/' => \&mojo_index => 'index';;; app->start; #### __DATA__ @@ index.html.ep % layout 'green'; %= content content => begin % for my $thix ( 0 .. $#$rayth ){ % } % for my $rai ( @$ray ) { % for my $cel ( @$rai ){ % } % }
<%# uparrow =%> <%= $$rayth[$thix] =%> <%# downarrow =%>
<%= $cel =%>
% if( $sortorder and defined $sortindex ){
* sortorder( <%= $sortorder %>) by sortindex( <%= $sortindex %> aka <%= $$rayth[ $sortindex ] %> )
% } % end @@ layouts/green.html.ep <%== title %> <%= content %>