From d344b51eebdc6a1baf7268548f83b7d3cac899a7 Mon Sep 17 00:00:00 2001 From: Jaimos Skriletz Date: Thu, 8 Jan 2026 07:17:53 -0700 Subject: [PATCH] Add PG::Critic policy for the deprecated weightedGrader.pl macros. --- .../PG/ProhibitDeprecatedWeightedGrader.pm | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 lib/Perl/Critic/Policy/PG/ProhibitDeprecatedWeightedGrader.pm diff --git a/lib/Perl/Critic/Policy/PG/ProhibitDeprecatedWeightedGrader.pm b/lib/Perl/Critic/Policy/PG/ProhibitDeprecatedWeightedGrader.pm new file mode 100644 index 0000000000..77a0755ef2 --- /dev/null +++ b/lib/Perl/Critic/Policy/PG/ProhibitDeprecatedWeightedGrader.pm @@ -0,0 +1,55 @@ +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 + L, and +this macros is no longer needed. + +=head1 DESCRIPTION + +The default L +includes all the functionality of the L, 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