Skip to content

Commit 6cc9e86

Browse files
committed
Add PG::Critic policy for the deprecated weightedGrader.pl macros.
1 parent a43c888 commit 6cc9e86

1 file changed

Lines changed: 50 additions & 0 deletions

File tree

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package Perl::Critic::Policy::PG::ProhibitDeprecatedWeightedGrader;
2+
use Mojo::Base 'Perl::Critic::Policy', -signatures;
3+
4+
use Perl::Critic::Utils qw(:severities :classification :ppi);
5+
6+
use constant DESCRIPTION => 'The deprecated %s function is called';
7+
use constant EXPLANATION => 'The deprecated %s function should be replaced with a modern alternative.';
8+
use constant SCORE => 5;
9+
use constant SAMPLE_PROBLEMS => [ [ 'Weighted Grader' => 'ProblemTechniques/WeightedGrader' ] ];
10+
use constant WEIGHTED_GRADER_METHODS => {
11+
install_weighted_grader => 1,
12+
WEIGHTED_ANS => 1,
13+
NAMED_WEIGHTED_ANS => 1,
14+
weight_ans => 1,
15+
CREDIT_ANS => 1,
16+
};
17+
18+
sub supported_parameters ($) {return}
19+
sub default_severity ($) { return $SEVERITY_HIGHEST }
20+
sub default_themes ($) { return qw(pg) }
21+
sub applies_to ($) { return qw(PPI::Token::Word) }
22+
23+
sub violates ($self, $element, $) {
24+
return unless WEIGHTED_GRADER_METHODS->{$element} && is_function_call($element);
25+
return $self->violation(sprintf(DESCRIPTION, $element),
26+
{ score => SCORE, explanation => sprintf(EXPLANATION, $element), sampleProblems => SAMPLE_PROBLEMS },
27+
$element);
28+
}
29+
30+
1;
31+
32+
__END__
33+
34+
=head1 NAME
35+
36+
Perl::Critic::Policy::PG::ProhibitDeprecatedWeightedGrader - The L<weightedGrader.pl> functionality
37+
is now included in the default grader, and this macro is no longer needed.
38+
39+
=head1 DESCRIPTION
40+
41+
The L<weightedGrader.pl> is now the default grader, and use of this macro should be removed.
42+
Remove calling the function C<install_weighted_grader>. Instead of calling C<WEIGHTED_ANS> or
43+
C<NAMED_WEIGHTED_ANS>, pass C<< weight => n >> to the C<cmp> method. In PGML use the following:
44+
45+
[_]{$answer}{ cmp_options => { weight => n } }
46+
47+
Instead of calling C<CREDIT_ANS> pass C<< credit => $answer1 >> or C<< credit => [$answer1, $answer2, ...] >>
48+
to the C<cmp> method.
49+
50+
=cut

0 commit comments

Comments
 (0)