From d2c2ee95623de944b4a0780d5d99694f9c1316da Mon Sep 17 00:00:00 2001 From: Marius Gavrilescu Date: Thu, 18 Jun 2015 20:10:26 +0300 Subject: [PATCH] Add a leading underscore to private function names --- lib/Gruntmaster/Data.pm | 42 ++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/lib/Gruntmaster/Data.pm b/lib/Gruntmaster/Data.pm index 9613584..8c2fb17 100644 --- a/lib/Gruntmaster/Data.pm +++ b/lib/Gruntmaster/Data.pm @@ -50,7 +50,7 @@ sub dbinit { sub purge; -sub query { +sub _query { my ($stat, @extra) = @_; $db->query($statements{$stat}, @extra) } @@ -58,7 +58,7 @@ sub query { my (%name_cache, %name_cache_time); use constant NAME_CACHE_MAX_AGE => 5; -sub object_name { +sub _object_name { my ($table, $id) = @_; $name_cache_time{$table} //= 0; if (time - $name_cache_time{$table} > NAME_CACHE_MAX_AGE) { @@ -71,28 +71,28 @@ sub object_name { } -sub add_names ($) { ## no critic (ProhibitSubroutinePrototypes) +sub _add_names ($) { ## no critic (ProhibitSubroutinePrototypes) my ($el) = @_; return unless defined $el; if (ref $el eq 'ARRAY') { - &add_names ($_) for @$el ## no critic (ProhibitAmpersandSigils) + &_add_names ($_) for @$el ## no critic (ProhibitAmpersandSigils) } else { for my $object (qw/contest owner problem/) { my $table = $object eq 'owner' ? 'users' : "${object}s"; - $el->{"${object}_name"} = object_name $table, $el->{$object} if defined $el->{$object} + $el->{"${object}_name"} = _object_name $table, $el->{$object} if defined $el->{$object} } } $el } -sub user_list { scalar query('user_list_sth')->hashes } +sub user_list { scalar _query('user_list_sth')->hashes } sub user_entry { my ($id) = @_; - my $ret = query('user_entry_sth', $id)->hash; - $ret->{problems} = add_names query('problem_status_sth', $id)->hashes; - $ret->{contests} = add_names query('contest_status_sth', $id)->hashes; + my $ret = _query('user_entry_sth', $id)->hash; + $ret->{problems} = _add_names _query('problem_status_sth', $id)->hashes; + $ret->{contests} = _add_names _query('contest_status_sth', $id)->hashes; $ret; } @@ -107,14 +107,14 @@ sub problem_list { $where{owner} = $args{owner} if $args{owner}; my $table = $args{contest} ? 'problems JOIN contest_problems cp ON cp.problem = id' : 'problems'; - add_names $db->select(\$table, \@columns, \%where, 'name')->hashes + _add_names $db->select(\$table, \@columns, \%where, 'name')->hashes } sub problem_entry { my ($id, $contest) = @_; $contest = contest_entry ($contest) if $contest; - my $ret = add_names query(problem_entry_sth => $id)->hash; - my $limits = query(limits_sth => $id)->hashes; + my $ret = _add_names _query(problem_entry_sth => $id)->hash; + my $limits = _query(limits_sth => $id)->hashes; $ret->{limits} = $limits if @$limits; if ($contest) { @@ -126,11 +126,11 @@ sub problem_entry { $ret } -sub contest_list { add_names query('contest_list_sth')->hashes } +sub contest_list { _add_names _query('contest_list_sth')->hashes } -sub contest_entry { add_names query(contest_entry_sth => $_[0])->hash } +sub contest_entry { _add_names _query(contest_entry_sth => $_[0])->hash } -sub contest_has_problem { query('contest_has_problem_sth', @_[0, 1])->flat } +sub contest_has_problem { _query('contest_has_problem_sth', @_[0, 1])->flat } sub job_list { my (%args) = @_; @@ -146,7 +146,7 @@ sub job_list { my $rows = $db->select('job_entry', 'COUNT(*)', \%where)->list; my $pages = int (($rows + JOBS_PER_PAGE - 1) / JOBS_PER_PAGE); my ($stmt, @bind) = $db->abstract->select('job_entry', '*', \%where, {-desc => 'id'}); - my $jobs = add_names $db->query("$stmt LIMIT " . JOBS_PER_PAGE . ' OFFSET ' . ($args{page} - 1) * JOBS_PER_PAGE, @bind)->hashes; + my $jobs = _add_names $db->query("$stmt LIMIT " . JOBS_PER_PAGE . ' OFFSET ' . ($args{page} - 1) * JOBS_PER_PAGE, @bind)->hashes; my $pageinfo = { current_page => $args{page}, last_page => $pages, @@ -157,7 +157,7 @@ sub job_list { } sub job_entry { - my $ret = add_names query(job_entry_sth => $_[0])->hash; + my $ret = _add_names _query(job_entry_sth => $_[0])->hash; $ret->{results} = decode_json $ret->{results} if $ret->{results}; $ret } @@ -186,7 +186,7 @@ sub standings { $ct = contest_entry $ct; my (%scores, %tries, %opens); - my $opens = query(opens_sth => $ct->{id}); + my $opens = _query(opens_sth => $ct->{id}); while ($opens->into(my ($problem, $owner, $time))) { $opens{$problem, $owner} = $time; } @@ -207,7 +207,7 @@ sub standings { my $user = $_; +{ user => $user, - user_name => object_name(users => $user), + user_name => _object_name(users => $user), score => sum (values %{$scores{$user}}), scores => [map { $scores{$user}{$_->{id}} // '-'} @problems], } @@ -244,14 +244,14 @@ sub update_status { sub rerun_job { my ($id) = @_; - query rerun_job_sth => $id; + _query rerun_job_sth => $id; purge '/log/'; purge "/log/$id"; } sub take_job { my ($daemon) = @_; - my $id = query(take_job_sth => $daemon)->list; + my $id = _query(take_job_sth => $daemon)->list; return $id ? db->select(jobs => '*', {id => $id})->hash : undef; } -- 2.39.2