From 453d35da5cc6c5a4f52fe4afff342a8c75fe2aab Mon Sep 17 00:00:00 2001
From: Alexandre Morignot <erdnaxeli@cervoi.se>
Date: Sat, 2 Apr 2016 23:46:36 +0200
Subject: [PATCH] utils::db::get now returns an hash ref instead of an array
 ref

---
 PlayBot/commands/get.pm | 18 +++++-------------
 PlayBot/utils/db/get.pm | 12 +++++++++++-
 2 files changed, 16 insertions(+), 14 deletions(-)

diff --git a/PlayBot/commands/get.pm b/PlayBot/commands/get.pm
index 1cf5702..cbd9e00 100644
--- a/PlayBot/commands/get.pm
+++ b/PlayBot/commands/get.pm
@@ -75,7 +75,7 @@ sub exec {
         from playbot_tags
         where id = ?
     ");
-    $sth->execute($content->[0]);
+    $sth->execute($content->{id});
 
     my @tags;
     while (my $data = $sth->fetch) {
@@ -84,17 +84,9 @@ sub exec {
         push @tags, $tag;
     }
 
-    my %content_h;
-    $content_h{'id'} = $content->[0];
-    $content_h{'author'} = $content->[1];
-    $content_h{'title'} = $content->[2];
-    $content_h{'url'} = $content->[3];
-    $content_h{'duration'} = $content->[4];
-    $content_h{'external_id'} = $content->[5];
-    $content_h{'site'} = $content->[6];
-    $content_h{'tags'} = \@tags;
+    $content->{'tags'} = \@tags;
 
-    my $irc_msg = PlayBot::utils::print::print(\%content_h);
+    my $irc_msg = PlayBot::utils::print::print($content);
 
     # if in query
     if ($chan !~ /^#/) {
@@ -114,12 +106,12 @@ sub exec {
         VALUES (?,?,?)');
     $log->error("Couldn't prepare querie; aborting") unless (defined $sth);
 
-    $sth->execute($content->[0], $chan, "PlayBot")
+    $sth->execute($content->{id}, $chan, "PlayBot")
         or $log->error("Couldn't finish transaction: " . $dbh->errstr);
 
     $dbh->commit();
 
-    return $content->[0];
+    return $content->{id};
 }
 
 
diff --git a/PlayBot/utils/db/get.pm b/PlayBot/utils/db/get.pm
index 305135a..7f91f6c 100644
--- a/PlayBot/utils/db/get.pm
+++ b/PlayBot/utils/db/get.pm
@@ -54,7 +54,17 @@ sub get {
     # if id was precised, we (and so the user) know there is no more results
     $self->_clean($chan) if ($query->id >= 0);
 
-    return $result;
+    return undef unless $result;
+
+    my %content;
+    $content{'id'} = $result->[0];
+    $content{'author'} = $result->[1];
+    $content{'title'} = $result->[2];
+    $content{'url'} = $result->[3];
+    $content{'duration'} = $result->[4];
+    $content{'external_id'} = $result->[5];
+    $content{'site'} = $result->[6];
+    return \%content;
 }
 
 sub get_rows {
-- 
GitLab