diff --git a/lib/Perl/Critic/Policy/PG/ProhibitDeprecatedWeightedGrader.pm b/lib/Perl/Critic/Policy/PG/ProhibitDeprecatedWeightedGrader.pm new file mode 100644 index 0000000000..32a25f2c38 --- /dev/null +++ b/lib/Perl/Critic/Policy/PG/ProhibitDeprecatedWeightedGrader.pm @@ -0,0 +1,50 @@ +package Perl::Critic::Policy::PG::ProhibitDeprecatedWeightedGrader; +use Mojo::Base 'Perl::Critic::Policy', -signatures; + +use Perl::Critic::Utils qw(:severities :classification :ppi); + +use constant DESCRIPTION => 'The deprecated %s function is called'; +use constant EXPLANATION => 'The deprecated %s function should be replaced with a modern alternative.'; +use constant SCORE => 5; +use constant SAMPLE_PROBLEMS => [ [ 'Weighted Grader' => 'ProblemTechniques/WeightedGrader' ] ]; +use constant WEIGHTED_GRADER_METHODS => { + install_weighted_grader => 1, + WEIGHTED_ANS => 1, + NAMED_WEIGHTED_ANS => 1, + weight_ans => 1, + CREDIT_ANS => 1, +}; + +sub supported_parameters ($) {return} +sub default_severity ($) { return $SEVERITY_HIGHEST } +sub default_themes ($) { return qw(pg) } +sub applies_to ($) { return qw(PPI::Token::Word) } + +sub violates ($self, $element, $) { + return unless WEIGHTED_GRADER_METHODS->{$element} && is_function_call($element); + return $self->violation(sprintf(DESCRIPTION, $element), + { score => SCORE, explanation => sprintf(EXPLANATION, $element), sampleProblems => SAMPLE_PROBLEMS }, + $element); +} + +1; + +__END__ + +=head1 NAME + +Perl::Critic::Policy::PG::ProhibitDeprecatedWeightedGrader - The L functionality +is now included in the default grader, and this macro is no longer needed. + +=head1 DESCRIPTION + +The L is now the default grader, and use of this macro should be removed. +Remove calling the function C. Instead of calling C or +C, pass C<< weight => n >> to the C method. In PGML use the following: + + [_]{$answer}{ cmp_options => { weight => n } } + +Instead of calling C pass C<< credit => $answer1 >> or C<< credit => [$answer1, $answer2, ...] >> +to the C method. + +=cut