我認爲這應該爲你工作(如果我明白你想要什麼):
package Perl::Critic::Policy::CodeLayout::NoSideComments;
use strict;
use warnings;
use Readonly;
use Perl::Critic::Utils qw{ :severities :classification :ppi };
use parent 'Perl::Critic::Policy';
our $VERSION = 20090904;
Readonly::Scalar my $DESC => "side comments are not allowed";
Readonly::Scalar my $EXPL => "put the comment above the line, not next to it";
sub supported_parameters { return }
sub default_severity { return 5 }
sub default_themes { return qw(custom) }
sub applies_to { return 'PPI::Token::Comment' }
sub violates {
my ($self, $elem) = @_;
#look backwards until you find whitespace that contains a
#newline (good) or something other than whitespace (error)
my $prev = $elem->previous_sibling;
while ($prev) {
return $self->violation($DESC, $EXPL, $elem)
unless $prev->isa("PPI::Token::Whitespace");
return if $prev->content =~ /\n/;
$prev = $prev->previous_sibling;
}
#catch # after a block start, but leave the #! line alone
return $self->violation($DESC, $EXPL, $elem)
unless $elem->parent->isa("PPI::Document");
return;
}
1;
謝謝,看起來像一個好開始! – 2009-09-04 14:30:56
/golfclap完成! :) – 2009-09-04 14:33:35
做得不好,我忽略了POD,但是我跑出了tuits。 – 2009-09-04 14:39:42