From 11a8110922bfaecb19dcce36d5833e556e4342ca Mon Sep 17 00:00:00 2001 From: Christian Loos Date: Mon, 23 Nov 2015 08:40:00 +0100 Subject: [PATCH] fix dependency check for Text::Template fixes #133 and #136 --- mysqltuner.pl | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/mysqltuner.pl b/mysqltuner.pl index cb4c33c..dcf14e8 100755 --- a/mysqltuner.pl +++ b/mysqltuner.pl @@ -645,19 +645,6 @@ sub mysql_setup { } } -sub try_load { - my $mod = shift; - - eval("use $mod"); - - if ($@) { - #print "\$@ = $@\n"; - return(0); - } else { - return(1); - } -} - # MySQL Request Array sub select_array { my $req = shift; @@ -2804,17 +2791,20 @@ sub dump_result { debugprint "HTML REPORT: $opt{'reportfile'}"; if ($opt{'reportfile'} ne 0 ) { - if (try_load('Text::Template')) { + eval "{ use Text::Template }"; + if ($@) { badprint "Text::Template Module is needed."; exit 1; } - use Text::Template; - my $vars= {'data' => Dumper( \%result ) }; - my $template = Text::Template->new(TYPE => 'STRING', PREPEND => q{;}, SOURCE => $templateModel) - or die "Couldn't construct template: $Text::Template::ERROR"; + my $template; + { + no warnings 'once'; + $template = Text::Template->new(TYPE => 'STRING', PREPEND => q{;}, SOURCE => $templateModel) + or die "Couldn't construct template: $Text::Template::ERROR"; + } open my $fh, q(>), $opt{'reportfile'} or die "Unable to open $opt{'reportfile'} in write mode. please check permissions for this file or directory"; $template->fill_in(HASH =>$vars, OUTPUT=>$fh );