diff --git a/.gitignore b/.gitignore index 6dc687e..4ee143d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ log explain.production.json .vagrant +*.beforeTidy diff --git a/lib/Explain.pm b/lib/Explain.pm index 7fcb0c9..04ffd7d 100755 --- a/lib/Explain.pm +++ b/lib/Explain.pm @@ -19,9 +19,11 @@ sub startup { # array format my $use_secret = $config->{ secret } || 'Xwyfe-_d:yGDr+p][Vs7Kk+e3mmP=c_|s7hvExF=b|4r4^gO|'; if ( $self->can( 'secrets' ) ) { + # We're on Mojolicious 4.63 or newer $self->secrets( [ $use_secret ] ); - } else { + } + else { # We're on old Mojolicious $self->secret( $use_secret ); } diff --git a/lib/Explain/Controller.pm b/lib/Explain/Controller.pm index db6cde2..916e669 100755 --- a/lib/Explain/Controller.pm +++ b/lib/Explain/Controller.pm @@ -153,7 +153,7 @@ sub login { if ( my $user = $self->database->user_login( $username, $password ) ) { $self->flash( 'message' => 'User logged in.' ); - $self->session( 'user' => $username ); + $self->session( 'user' => $username ); $self->session( 'admin' => $user->{ 'admin' } ); $self->redirect_to( 'new-explain' ); } @@ -172,9 +172,9 @@ sub new_optimization { return $self->redirect_to( 'new-explain', status => 404 ) unless $original_plan; - $self->stash->{ 'optimization' } = 1; + $self->stash->{ 'optimization' } = 1; $self->stash->{ 'original_plan_id' } = $original_plan_id; - $self->stash->{ 'original_title' } = $original_title; + $self->stash->{ 'original_title' } = $original_title; return $self->render( 'controller/index' ); } @@ -332,7 +332,7 @@ sub show { # Fetch path of optimizations $self->stash->{ optimization_path } = $self->database->get_optimization_path( $id ); - $self->stash->{ suboptimizations } = $self->database->get_optimizations_for( $id ); + $self->stash->{ suboptimizations } = $self->database->get_optimizations_for( $id ); # render will be called automatically return; @@ -403,15 +403,17 @@ sub info { next if $module =~ m{^\.?/}; $module =~ s/\.pm$//; $module =~ s#/#::#g; - push @versions, { - 'module' => $module, + push @versions, + { + 'module' => $module, 'version' => $module->VERSION, - }; + }; } $self->stash( 'modules' => \@versions ); - $self->stash( 'perl' => { + $self->stash( + 'perl' => { 'version' => $PERL_VERSION, - 'binary' => $Config{'perlpath'} . $Config{'_exe'}, + 'binary' => $Config{ 'perlpath' } . $Config{ '_exe' }, } ); @@ -419,10 +421,11 @@ sub info { sub status { my $self = shift; - if ($self->database->ping()) { - $self->render('text' => 'OK', status => 200); - } else { - $self->render('text' => 'DB FAILED', status => 500); + if ( $self->database->ping() ) { + $self->render( 'text' => 'OK', status => 200 ); + } + else { + $self->render( 'text' => 'DB FAILED', status => 500 ); } } diff --git a/lib/Explain/Plugin/Database.pm b/lib/Explain/Plugin/Database.pm index 43b757f..136067e 100755 --- a/lib/Explain/Plugin/Database.pm +++ b/lib/Explain/Plugin/Database.pm @@ -87,7 +87,7 @@ sub user_login { my $crypted = crypt( $password, $row[ 0 ] ); return if $crypted ne $row[ 0 ]; - return { 'admin' => $row[1] }; + return { 'admin' => $row[ 1 ] }; } sub user_change_password { @@ -262,10 +262,9 @@ sub get_plan { sub get_optimization_path { my $self = shift; - my ($plan_id) = @_; + my ( $plan_id ) = @_; - my $rows = $self->dbh->selectall_arrayref( - ' + my $rows = $self->dbh->selectall_arrayref( ' WITH RECURSIVE path AS ( SELECT id, title, optimization_for, 0 as level FROM plans WHERE id = ? and not is_deleted union all @@ -290,9 +289,9 @@ sub get_optimization_path { } sub get_optimizations_for { - my $self = shift; - my ($plan_id) = @_; - my $rows = $self->dbh->selectall_arrayref( + my $self = shift; + my ( $plan_id ) = @_; + my $rows = $self->dbh->selectall_arrayref( 'select id, title from plans where optimization_for = ? and not is_deleted', { Slice => {} }, $plan_id diff --git a/lib/Explain/Plugin/MailSender.pm b/lib/Explain/Plugin/MailSender.pm index f229cd6..5b46af9 100755 --- a/lib/Explain/Plugin/MailSender.pm +++ b/lib/Explain/Plugin/MailSender.pm @@ -21,17 +21,17 @@ sub register { eval { my $email = Email::Simple->create( header => [ - To => $self->config->{'to'}, - From => $self->config->{'from'}, - Subject => $self->config->{'subject'}, + To => $self->config->{ 'to' }, + From => $self->config->{ 'from' }, + Subject => $self->config->{ 'subject' }, ], - body => $mail->{'msg'}, + body => $mail->{ 'msg' }, ); # log debug message $controller->app->log->debug( sprintf "Sending mail:\n%s", $controller->dumper( $email ) ); - sendmail($email); + sendmail( $email ); }; if ( $EVAL_ERROR ) {