From 7ab3e35b073fe488315c6f9603151d2302a0261b Mon Sep 17 00:00:00 2001 From: cos Date: Sun, 17 Jul 2016 20:09:33 +0200 Subject: Make code a tiny little bit more clean. --- cgi-bin/mat.cgi | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) (limited to 'cgi-bin') diff --git a/cgi-bin/mat.cgi b/cgi-bin/mat.cgi index d61db32..52239d5 100755 --- a/cgi-bin/mat.cgi +++ b/cgi-bin/mat.cgi @@ -50,17 +50,18 @@ sub cmd_view($) my $db = DBI->connect($Config{'database'}, "", "", {HandleError => \&misconfigured, AutoCommit => 1}); - my $recipe_row = $db->selectrow_arrayref("SELECT name, storage, uri, ". - "amount, energy FROM recipes AS r JOIN inventory AS i ". - "ON i.recipe_id=r.id WHERE i.id=".$id.";"); - - print $id, "
", $$recipe_row[0], "
", $$recipe_row[1], "
"; - print ($$recipe_row[3] ? $$recipe_row[3]." g
" : ""), "
"; - print ($$recipe_row[4] ? $$recipe_row[4]." kJ
" : ""), "
"; - if(substr($$recipe_row[2], 0, 4) eq "http") { - print ''.$$recipe_row[2].'', "
"; + my $portion = $db->selectrow_hashref("SELECT name, storage, uri, amount, ". + "energy FROM recipes AS r JOIN inventory AS i ON i.recipe_id=r.id ". + "WHERE i.id=".$id.";"); + + print $id, "
", $portion->{name}, "
\n"; + print $portion->{storage}, "
\n"; + print $portion->{amount} ? $portion->{amount}." g
" : "", "
\n"; + print $portion->{energy} ? $portion->{energy}." kJ
" : "", "
\n"; + if(substr($portion->{uri}, 0, 4) eq "http") { + print ''.$portion->{uri}.'', "
\n"; } else { - print $$recipe_row[2], "
"; + print $portion->{uri}, "
\n"; } if ($session->param('authenticated') eq "yes") { print "\n"; @@ -68,7 +69,7 @@ sub cmd_view($) print " ". "$store \n"; } - print ""; + print "\n"; } } @@ -90,8 +91,8 @@ misconfigured unless ($Config{'database'}); misconfigured unless $session; invalid_input unless ($id and $action); -invalid_input unless (($id =~ m/^[0-9]+$/) and ($action =~ m/^view|relocate$/) and - ($storage =~ /^[a-z0-9]*$/)); +invalid_input unless (($id =~ m/^[0-9]+$/) + and ($action =~ m/^view|relocate$/) and ($storage =~ /^[a-z0-9]*$/)); send_cookie; for ($action) { -- cgit v1.2.3