Gluu fer the Wëëbb Part 2

Well in my first post of this series I just managed to get a listing up and running utilizing the Toto plugin well lets move on a little.

Well it seems I have my list and the underlying urls I have 'http://localhost:3000/character/view/Glarp_Gnlnarn' which is correct but of course it is not a 100% 'REST' as I think that by convention 'character' should be the plural 'characters' but then again in the POD they say this is a BREAD interface not a REST and the author defines it as

'- in a BREAD application, browse and add are operations on zero or many objects, while edit, add, and delete are operations on one object'

Ok I can buy that so back to doing some code.

Well back to doing a little coding.

So this time out I again start with my route and sub


get '/character/view/:name' => sub {
my $self = shift;
use MooseX::YAML;
my $name = $self->param('name');
my $character = MooseX::YAML::LoadFile('D:\\blogs\\mymoose\\'.$name.".yml");
$self->stash(character =>$character);
} => "/character/view";

Oh course now I get to use that nifty MooseX from this post and that saves me a good deal of time. All I am doing here is using some mojo route shorthand with the ':name' as the wildcard and I get it from the prams and use my nifty MooseX to instantiate my Character and then I stuff it in the stash for use on the template

Now this time out I didn't forget to create a template and here it is


@@ character/view.html.ep

You Characters
<table>
<tr>
<td>Name:</td><td><%=$character->name()%></td>>
</tr>
<tr>
<td>Strength:</td><td><%=$character->strength()%>
% if ($character->can('exceptional')) {
(<%=$character->exceptional %>)
%}
</td>
</tr>
<tr>
<td>Intelligence:</td><td><%=$character->intelligence()%></td>
</tr>
<tr>
<td>Wisdom:</td><td><%=$character->wisdom()%></td>
</tr>
<tr>
<td>Dexterity:</td><td><%=$character->dexterity()%></td>
</tr>
<tr>
<td>Constitution:</td><td><%=$character->constitution()%></td>
</tr>
<tr>
<td>Charisma:</td><td><%=$character->charisma()%></td>
</tr>
</table>

simple enough I just list all the attributes with my $character that is already in the stash I even check to see if my character has exceptional strength

and I give it a go and get this

toto_5.jpg

Opps missing that menu bar again.

Perhaps this will fix it


get '/character/view/:name' => { nav_item => 'character\view' } => sub {

and it dose as now I get this

toto_6.jpg

On to better things tomorrow

Leave a comment

About byterock

user-pic Long time Perl guy, a few CPAN mods allot of work on DBD::Oracle and a few YAPC presentations