Skip to content

Commit

Permalink
Switch to using perl signatures in all of the lib files. Note that all
Browse files Browse the repository at this point in the history
sub's should have a signature, even those that take no parameters.  This
ensures that methods are called with the correct parameters.

Remove double hashed comments except those for perl critic which is the
only place where double hashed comments should be used.

Full sentence comments should also always be capatilized and properly
punctuated.
  • Loading branch information
drgrice1 committed Dec 9, 2021
1 parent a23594e commit abad52e
Show file tree
Hide file tree
Showing 29 changed files with 370 additions and 539 deletions.
4 changes: 4 additions & 0 deletions .perlcriticrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
severity = 4

[-Subroutines::ProhibitSubroutinePrototypes]

# Allow no warnings usage with a category restriction (for signatures)
[TestingAndDebugging::ProhibitNoWarnings]
allow_with_category_restriction = 1
27 changes: 0 additions & 27 deletions lib/DB/General.pm
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,6 @@ use warnings;
The class DB::Schema::ResultSet::General pull the common functionality for
the other classes in the schema resultsets include
=over
=item Course
=item User
=item ProblemSet
=item UserSet
=item Problem
=back
=cut

use Carp;
use Data::Dump qw/dd dump/;
use List::Util qw/first/;

use Clone qw/clone/;
use DB::Utils qw/getCourseInfo getUserInfo/;
use DB::Exception;
use Exception::Class ('DB::Exception::CourseNotFound', 'DB::Exception::CourseExists');

use DB::TestUtils qw/removeIDs/;
use WeBWorK3::Utils::Settings qw/getDefaultCourseSettings mergeCourseSettings
getDefaultCourseValues validateCourseSettings/;

1;
2 changes: 1 addition & 1 deletion lib/DB/Schema.pm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package DB::Schema;

## This is the base package for the Schema for the WeBWorK.
# This is the base package for the Schema for the WeBWorK.

use warnings;
use strict;
Expand Down
3 changes: 2 additions & 1 deletion lib/DB/Schema/Result/CourseUser.pm
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ __PACKAGE__->add_columns(
size => 16,
is_nullable => 1,
},
params => { # store params as a JSON object
# Store params as a JSON object.
params => {
data_type => 'text',
size => 256,
is_nullable => 0,
Expand Down
7 changes: 5 additions & 2 deletions lib/DB/Schema/Result/PoolProblem.pm
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package DB::Schema::Result::PoolProblem;
use base qw/DBIx::Class::Core/;

use strict;
use warnings;
use feature 'signatures';
no warnings 'experimental::signatures';

=head1 DESCRIPTION
Expand Down Expand Up @@ -69,14 +72,14 @@ __PACKAGE__->add_columns(
}
);

sub valid_params {
sub valid_params () {
return {
library_id => q{\d+},
problem_path => q{((\w)+\/?)+}
};
}

sub required_params {
sub required_params () {
return { '_ONE_OF_' => [ 'library_id', 'problem_path' ] };
}

Expand Down
13 changes: 8 additions & 5 deletions lib/DB/Schema/Result/Problem.pm
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use DB::WithParams;

use strict;
use warnings;
use feature 'signatures';
no warnings qw(experimental::signatures);

use base qw(DBIx::Class::Core DB::WithParams);

Expand Down Expand Up @@ -60,7 +62,7 @@ Note: a problem should have only one of a library_id, problem_path or problem_po
=cut

sub valid_params {
sub valid_params () {
return {
weight => q{^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$}, # positive integers or decimals
library_id => q{\d+},
Expand All @@ -69,11 +71,11 @@ sub valid_params {
};
}

sub required_params {
sub required_params () {
return { '_ALL_' => [ 'weight', { '_ONE_OF_' => [ 'library_id', 'file_path', 'problem_pool_id' ] } ] };
}

### this is the table that stores problems for a given Problem Set
# This is the table that stores problems for a given Problem Set.

__PACKAGE__->table('problem');

Expand Down Expand Up @@ -102,7 +104,8 @@ __PACKAGE__->add_columns(
is_nullable => 0,
default_value => 1
},
problem_params => { # store params as a JSON object
# Store params as a JSON object.
problem_params => {
data_type => 'text',
size => 256,
is_nullable => 0,
Expand All @@ -114,7 +117,7 @@ __PACKAGE__->add_columns(

__PACKAGE__->set_primary_key('problem_id');

# maybe we don't need this.
# Maybe we don't need this.
__PACKAGE__->add_unique_constraint([qw/problem_id set_id problem_version problem_number/]);

__PACKAGE__->belongs_to(problem_set => 'DB::Schema::Result::ProblemSet', 'set_id');
Expand Down
12 changes: 6 additions & 6 deletions lib/DB/Schema/Result/ProblemSet.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use base qw/DBIx::Class::Core/;

use strict;
use warnings;
use feature 'signatures';
no warnings qw(experimental::signatures);

=head1 DESCRIPTION
Expand Down Expand Up @@ -100,7 +102,7 @@ __PACKAGE__->add_columns(
default_value => 1,
is_nullable => 0
},
# store dates as a JSON object
# Store dates as a JSON object.
set_dates => {
data_type => 'text',
size => 256,
Expand All @@ -109,7 +111,7 @@ __PACKAGE__->add_columns(
serializer_class => 'JSON',
serializer_options => { utf8 => 1 }
},
# store params as a JSON object
# Store params as a JSON object.
set_params => {
data_type => 'text',
size => 256,
Expand All @@ -120,9 +122,7 @@ __PACKAGE__->add_columns(
}
);

#
# This defines the non-abstract classes of ProblemSets.
#

__PACKAGE__->typecast_map(
type => {
Expand All @@ -146,8 +146,8 @@ returns the type (HW, Quiz, JITAR, REVIEW) of the problem set
=cut

sub set_type {
sub set_type ($set) {
my %set_type_rev = reverse %{$DB::Schema::ResultSet::ProblemSet::SET_TYPES};
return $set_type_rev{ shift->type };
return $set_type_rev{ $set->type };
}
1;
11 changes: 7 additions & 4 deletions lib/DB/Schema/Result/ProblemSet/HWSet.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package DB::Schema::Result::ProblemSet::HWSet;

use strict;
use warnings;
use feature 'signatures';
no warnings qw(experimental::signatures);

use base qw(DB::Schema::Result::ProblemSet DB::WithParams DB::WithDates);

=head1 DESCRIPTION
Expand All @@ -20,7 +23,7 @@ subroutine that returns the array for the valid dates: C<['open', 'reduced_scori
=cut

sub valid_dates {
sub valid_dates () {
return [ 'open', 'reduced_scoring', 'due', 'answer' ];
}

Expand All @@ -30,7 +33,7 @@ subroutine that returns the array for the required dates: C<['open', 'due' ,'ans
=cut

sub required_dates {
sub required_dates () {
return [ 'open', 'due', 'answer' ];
}

Expand Down Expand Up @@ -74,7 +77,7 @@ This is a description of the homework set.
=cut

sub valid_params {
sub valid_params () {
return {
enable_reduced_scoring => q{[01]},
hide_hint => q{[01]},
Expand All @@ -90,7 +93,7 @@ No parameters are required for the homework set.
=cut

sub required_params {
sub required_params () {
return {};
}

Expand Down
11 changes: 7 additions & 4 deletions lib/DB/Schema/Result/ProblemSet/Quiz.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package DB::Schema::Result::ProblemSet::Quiz;

use strict;
use warnings;
use feature 'signatures';
no warnings qw(experimental::signatures);

use base qw(DB::Schema::Result::ProblemSet DB::WithParams DB::WithDates);

=head1 DESCRIPTION
Expand All @@ -20,7 +23,7 @@ subroutine that returns the array for the valid dates: C<['open', 'due' ,'answer
=cut

sub valid_dates {
sub valid_dates () {
return [ 'open', 'due', 'answer' ];
}

Expand All @@ -30,7 +33,7 @@ subroutine that returns the array for the required dates: C<['open', 'due' ,'ans
=cut

sub required_dates {
sub required_dates () {
return [ 'open', 'due', 'answer' ];
}

Expand All @@ -56,7 +59,7 @@ if the quiz is timed, how long should it be open.
=cut

sub valid_params {
sub valid_params () {
return {
timed => q{^[01]$},
quiz_duration => q{\d+},
Expand All @@ -69,7 +72,7 @@ No parameters are required for the homework set.
=cut

sub required_params {
sub required_params () {
return {};
}

Expand Down
11 changes: 7 additions & 4 deletions lib/DB/Schema/Result/ProblemSet/ReviewSet.pm
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package DB::Schema::Result::ProblemSet::ReviewSet;
use base qw(DB::Schema::Result::ProblemSet DB::WithDates DB::WithParams);

use strict;
use warnings;
use feature 'signatures';
no warnings qw(experimental::signatures);

=head1 DESCRIPTION
Expand All @@ -19,7 +22,7 @@ subroutine that returns the array for the valid dates: C<['open', 'closed']>
=cut

sub valid_dates {
sub valid_dates () {
return [ 'open', 'closed' ];
}

Expand All @@ -29,7 +32,7 @@ subroutine that returns the array for the required dates: C<['open', 'closed']>
=cut

sub required_dates {
sub required_dates () {
return [ 'open', 'closed' ];
}

Expand All @@ -39,7 +42,7 @@ subroutine that returns the hashref for the valid parameters: (currently empty)
=cut

sub valid_params {
sub valid_params () {
return {};
}

Expand All @@ -49,7 +52,7 @@ subroutine that returns the hashref for the required parameters: (currently emp
=cut

sub required_params {
sub required_params () {
return {};
}

Expand Down
11 changes: 4 additions & 7 deletions lib/DB/Schema/Result/UserProblem.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@ use base qw/DBIx::Class::Core/;
use strict;
use warnings;

### this is the table that stores problems for a given Problem Set

## Note: we probably also need to store the problem info if it changes.

# perhaps the params will store both the problem info and the seed.

# don't allow the same problem/seed.
# This is the table that stores problems for a given Problem Set.
# Note: we probably also need to store the problem info if it changes.
# Perhaps the params will store both the problem info and the seed.
# Don't allow the same problem/seed.

__PACKAGE__->table('user_problem');

Expand Down
Loading

0 comments on commit abad52e

Please sign in to comment.