From 9e418af0e855ce0c5616dcdb8be2101478ad7bd1 Mon Sep 17 00:00:00 2001
From: Alexandre Morignot <erdnaxeli@cervoi.se>
Date: Sun, 29 Nov 2015 13:05:29 +0100
Subject: [PATCH] add and fix warnings

---
 PlayBot/commands/fav.pm       |  3 +++
 PlayBot/commands/get/query.pm |  3 +++
 PlayBot/commands/later.pm     |  3 +++
 PlayBot/commands/parser.pm    |  5 +++--
 PlayBot/commands/tag.pm       |  3 +++
 PlayBot/sessions/irc.pm       |  2 +-
 PlayBot/sessions/irc/later.pm |  5 ++++-
 PlayBot/sites/dailymotion.pm  |  3 +++
 PlayBot/sites/mixcloud.pm     | 18 +++++++++++-------
 PlayBot/sites/parser.pm       | 11 ++++++++---
 PlayBot/sites/soundcloud.pm   | 19 ++++++++++++-------
 PlayBot/sites/youtube.pm      |  9 ++++++---
 PlayBot/sites/zippy.pm        |  3 +++
 PlayBot/utils/db/get.pm       |  3 +++
 PlayBot/utils/db/stats.pm     |  3 +++
 PlayBot/utils/id.pm           |  2 ++
 PlayBot/utils/print.pm        |  1 +
 17 files changed, 72 insertions(+), 24 deletions(-)

diff --git a/PlayBot/commands/fav.pm b/PlayBot/commands/fav.pm
index cc8f3a6..3eee6ba 100644
--- a/PlayBot/commands/fav.pm
+++ b/PlayBot/commands/fav.pm
@@ -1,5 +1,8 @@
 package PlayBot::commands::fav;
 
+use strict;
+use warnings;
+
 our $dbh;
 our $log;
 our $irc;
diff --git a/PlayBot/commands/get/query.pm b/PlayBot/commands/get/query.pm
index c32989f..40b7871 100644
--- a/PlayBot/commands/get/query.pm
+++ b/PlayBot/commands/get/query.pm
@@ -1,5 +1,8 @@
 package PlayBot::commands::get::query;
 
+use strict;
+use warnings;
+
 use Moose;
 use overload '~~' => \&_equals;
 use Scalar::Util qw(looks_like_number);
diff --git a/PlayBot/commands/later.pm b/PlayBot/commands/later.pm
index 55c088d..26eef73 100644
--- a/PlayBot/commands/later.pm
+++ b/PlayBot/commands/later.pm
@@ -1,5 +1,8 @@
 package PlayBot::commands::later;
 
+use strict;
+use warnings;
+
 our $dbh;
 our $log;
 
diff --git a/PlayBot/commands/parser.pm b/PlayBot/commands/parser.pm
index e692b64..35c9760 100644
--- a/PlayBot/commands/parser.pm
+++ b/PlayBot/commands/parser.pm
@@ -1,6 +1,7 @@
 package PlayBot::commands::parser;
 
 use strict;
+use warnings;
 use Try::Tiny;
 
 use PlayBot::commands::fav;
@@ -89,8 +90,8 @@ sub exec {
             $irc->yield(privmsg => $chan => $insultes[rand @insultes]);
         };
     }
-    elsif ($msg =~ /^( *!get)(?: +.*)?$/) {
-        my $query = substr $msg, (length $1) + 1;
+    elsif ($msg =~ /^( *!get)( +.*)?$/) {
+        my $query = $2;
         my @args = ($chan, $query);
         my $id = PlayBot::commands::get::exec(@args);
 
diff --git a/PlayBot/commands/tag.pm b/PlayBot/commands/tag.pm
index 719ae87..0ca69b8 100644
--- a/PlayBot/commands/tag.pm
+++ b/PlayBot/commands/tag.pm
@@ -1,5 +1,8 @@
 package PlayBot::commands::tag;
 
+use strict;
+use warnings;
+
 our $dbh;
 our $log;
 
diff --git a/PlayBot/sessions/irc.pm b/PlayBot/sessions/irc.pm
index 6a3d4c1..5035739 100644
--- a/PlayBot/sessions/irc.pm
+++ b/PlayBot/sessions/irc.pm
@@ -49,7 +49,7 @@ my $debug = 0;
 
 # mode debug
 if ($#ARGV + 1) {
-	@channels = qw(#hormone);
+	@channels = ('#hormone');
 	$nick = 'kikoo';
 	$debug = 1;
 }
diff --git a/PlayBot/sessions/irc/later.pm b/PlayBot/sessions/irc/later.pm
index 993dd6b..20f9677 100644
--- a/PlayBot/sessions/irc/later.pm
+++ b/PlayBot/sessions/irc/later.pm
@@ -1,5 +1,8 @@
 package PlayBot::sessions::irc::later;
 
+use strict;
+use warnings;
+
 use PlayBot::commands::get;
 
 sub consume
@@ -7,7 +10,7 @@ sub consume
 	my ($nick, $id, $chan_src) = @_;
 
     my @args = ($nick, $id, $chan_src);
-    commands::get::exec(@args);
+    PlayBot::commands::get::exec(@args);
 }
 
 1;
diff --git a/PlayBot/sites/dailymotion.pm b/PlayBot/sites/dailymotion.pm
index c1f0c52..5a14fb8 100644
--- a/PlayBot/sites/dailymotion.pm
+++ b/PlayBot/sites/dailymotion.pm
@@ -1,5 +1,8 @@
 package PlayBot::sites::dailymotion;
 
+use strict;
+use warnings;
+
 use Inline Python => 'DATA';
 
 sub get {
diff --git a/PlayBot/sites/mixcloud.pm b/PlayBot/sites/mixcloud.pm
index 1825a68..0b9bdb3 100644
--- a/PlayBot/sites/mixcloud.pm
+++ b/PlayBot/sites/mixcloud.pm
@@ -1,5 +1,8 @@
 package PlayBot::sites::mixcloud;
 
+use strict;
+use warnings;
+
 use LWP::UserAgent;
 use JSON;
 use Encode;
@@ -7,7 +10,6 @@ use Encode;
 sub get {
 	my ($url) = @_;
     $url =~ s/www/api/;
-    my %infos;
 
 	my $ua = LWP::UserAgent->new(
         timeout     => 30,
@@ -16,13 +18,15 @@ sub get {
 	my $response = $ua->get($url);
 	die($response->status_line) unless ($response->is_success);
 
-	$content = decode_json(encode('UTF-8', $response->decoded_content));
-	$infos{'title'} = $content->{'name'};
-	$infos{'author'} = $content->{'user'}->{'name'};
-	$infos{'url'} = $content->{'url'};
-    $infos{'duration'} = $content->{'audio_length'};
+	my $content = decode_json(encode('UTF-8', $response->decoded_content));
+    my $infos = {
+	    title       => $content->{'name'},
+	    author      => $content->{'user'}->{'name'},
+	    url         => $content->{'url'},
+        duration    => $content->{'audio_length'},
+    };
 
-	return %infos;
+	return %{ $infos };
 }
 
 1;
diff --git a/PlayBot/sites/parser.pm b/PlayBot/sites/parser.pm
index 24e9383..f375982 100644
--- a/PlayBot/sites/parser.pm
+++ b/PlayBot/sites/parser.pm
@@ -76,8 +76,13 @@ sub parse {
             ');
 		    $log->error("Couldn't prepare querie; aborting") unless (defined $sth);
 
-		    $sth->execute($content{'site'}, $content{'url'},
-                $content{'author'}, $content{'title'}, $content{'duration'});
+		    $sth->execute(
+                $content{'site'},
+                $content{'url'},
+                $content{'author'},
+                $content{'title'},
+                $content{'duration'}
+            );
         };
         if ($@) {
             # seems to be already present in database 
@@ -110,7 +115,7 @@ sub parse {
 		$id = $sth->fetch->[0];
 
         # insertion du chan
-        my $sth = $dbh->prepare('
+        $sth = $dbh->prepare('
             INSERT INTO playbot_chan (content, chan, sender_irc)
             VALUES (?,?,?)');
 		$log->error("Couldn't prepare querie; aborting") unless (defined $sth);
diff --git a/PlayBot/sites/soundcloud.pm b/PlayBot/sites/soundcloud.pm
index 9945872..8d2e831 100644
--- a/PlayBot/sites/soundcloud.pm
+++ b/PlayBot/sites/soundcloud.pm
@@ -1,5 +1,8 @@
 package PlayBot::sites::soundcloud;
 
+use strict;
+use warnings;
+
 use LWP::UserAgent;
 use JSON;
 use URI::Find;
@@ -19,17 +22,19 @@ sub get {
 	my $response = $ua->get($root.'/resolve.json?url='.$url.'&client_id='.$clientId);
 	die($response->status_line) unless ($response->is_success);
 
-	$content = decode_json($response->decoded_content);
-	$infos{'title'} = $content->{'title'};
-	$infos{'author'} = $content->{'user'}->{'username'};
-    $infos{'duration'} = $content->{'duration'} / 1000;
-	$infos{'url'} = $url;
+	my $content = decode_json($response->decoded_content);
+    my $infos = {
+        title       => $content->{'title'},
+	    author      => $content->{'user'}->{'username'},
+        duration    => $content->{'duration'} / 1000,
+	    url         => $url,
+    };
 
 	if ($content->{'downloadable'}) {
-		$infos{'ddl'} = $content->{'download_url'};
+		$infos->{'ddl'} = $content->{'download_url'};
 	}
     
-	return %infos;
+	return %{ $infos };
 }
 
 1;
diff --git a/PlayBot/sites/youtube.pm b/PlayBot/sites/youtube.pm
index b6cd65f..b43744a 100644
--- a/PlayBot/sites/youtube.pm
+++ b/PlayBot/sites/youtube.pm
@@ -1,5 +1,8 @@
 package PlayBot::sites::youtube;
 
+use strict;
+use warnings;
+
 use LWP::UserAgent;
 use JSON;
 use FindBin;
@@ -37,9 +40,9 @@ sub get {
     $video->{'contentDetails'}->{'duration'} =~ /PT((?<h>\d+)H)?((?<m>\d+)M)?((?<s>\d+)S)?/;
 
     # default values
-    my ($h) = ($+{'h'}, 0);
-    my ($m) = ($+{'m'}, 0);
-    my ($s) = ($+{'s'}, 0);
+    my ($h) = $+{'h'} || 0;
+    my ($m) = $+{'m'} || 0;
+    my ($s) = $+{'s'} || 0;
 
     # there is one more second, don't know why
     $infos{'duration'} = $h*3600 + $m*60 + $s - 1;
diff --git a/PlayBot/sites/zippy.pm b/PlayBot/sites/zippy.pm
index e6ecee6..359765c 100644
--- a/PlayBot/sites/zippy.pm
+++ b/PlayBot/sites/zippy.pm
@@ -1,5 +1,8 @@
 package PlayBot::sites::zippy;
 
+use strict;
+use warnings;
+
 use LWP::UserAgent;
 use HTML::Parser;
 use HTML::Entities;
diff --git a/PlayBot/utils/db/get.pm b/PlayBot/utils/db/get.pm
index 03139d4..73b3568 100644
--- a/PlayBot/utils/db/get.pm
+++ b/PlayBot/utils/db/get.pm
@@ -1,5 +1,8 @@
 package PlayBot::utils::db::get;
 
+use strict;
+use warnings;
+
 use feature 'state';
 use Moose;
 
diff --git a/PlayBot/utils/db/stats.pm b/PlayBot/utils/db/stats.pm
index 166fbc8..2a069ee 100644
--- a/PlayBot/utils/db/stats.pm
+++ b/PlayBot/utils/db/stats.pm
@@ -1,5 +1,8 @@
 package PlayBot::utils::db::stats;
 
+use strict;
+use warnings;
+
 use Moose;
 use FindBin;
 use List::Util qw( reduce );
diff --git a/PlayBot/utils/id.pm b/PlayBot/utils/id.pm
index e9d9d59..465848e 100644
--- a/PlayBot/utils/id.pm
+++ b/PlayBot/utils/id.pm
@@ -1,6 +1,8 @@
 package PlayBot::utils::id;
 
 use strict;
+use warnings;
+
 use Scalar::Util qw(looks_like_number);
 
 # Used to get a proper id from an index.
diff --git a/PlayBot/utils/print.pm b/PlayBot/utils/print.pm
index 4c31ecb..077730a 100644
--- a/PlayBot/utils/print.pm
+++ b/PlayBot/utils/print.pm
@@ -1,6 +1,7 @@
 package PlayBot::utils::print;
 
 use strict;
+use warnings;
 
 use IRC::Utils qw(YELLOW ORANGE GREEN NORMAL LIGHT_BLUE GREY);
 
-- 
GitLab