I use Perl::Critic and like it, but one thing I do not agree with is that it uses perldoc hardcoded as POD renderer. That's nothing worth to contribute a patch for, it just complicates everything for very little public gain. So I went into the sources (first the perlcritic program, and in recent releases, Perl::Critic::Command) and edited it to use annopod instead, just for myself.
Now I got fed up that every new release overwrites my local changes again, so I just spent some time to do it the proper way, like I should have done in the first place, changing behaviour through polymorphism. Behold pcpod! Instead of writing perlcritic --doc $POLICY_NAME I write pcpod $POLICY_NAME.
#!/usr/bin/env perl package Perl::Critic::Command::RenderPolicyDocsAnnopod; use parent 'Perl::Critic::Command'; sub _render_policy_docs { my (%opts) = @_; my $pattern = delete $opts{-doc}; require Perl::Critic; $critic = Perl::Critic->new(%opts); _set_up_pager($critic->config()->pager()); require Perl::Critic::PolicyFactory; my @site_policies = Perl::Critic::PolicyFactory->site_policy_name +s(); my @matching_policies = grep { $_ =~ m/$pattern/ixms } @site_poli +cies; exec 'annopod', $matching_policies[0] or die "exec annopod failed: + $!\n"; } unshift @ARGV, '--doc'; Perl::Critic::Command::RenderPolicyDocsAnnopod->run();
When I said »spent some time«, that was a lie. The code above really just took two minutes or so, but the last half hour I've been knee-deep in the debugger to find out why the stupid thing doesn't work, that is it still is the unoverridden behaviour. Aaaaargh! Relevant excerpt is below. Would the kind monks please deliver explanation and advice?
> perl -d `which pcpod` CodeLayout::RequireUseUTF8 [...] DB<1> s Perl::Critic::Command::_dispatch_special_requests(.../lib/perl5/site_p +erl/5.10.0/Perl/Critic/Command.pm:139): 139: if ( $opts{-doc} ) { _render_policy_docs( %opt +s ) } #Exits DB<1> s Perl::Critic::Command::_render_policy_docs(.../lib/perl5/site_perl/5.1 +0.0/Perl/Critic/Command.pm:588): 588: my (%opts) = @_;
In reply to why does this subclassing not work? by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |