Login
Offering a new Perl::Critic::Annotation class for review.
authorJeffrey Ryan Thalhammer <jeff@imaginative-software.com>
Tue, 28 Oct 2008 21:32:51 +0000 (21:32 +0000)
committerJeffrey Ryan Thalhammer <jeff@imaginative-software.com>
Tue, 28 Oct 2008 21:32:51 +0000 (21:32 +0000)
commit48d3832c89a6bcd4009df7f31a08a21cd8de68a6
tree09652f8ae9d9c8a03df2dc0650cd8a0a1643f86f
parent3be4796c38a41c7768b0e53eac863c35ac2d3969
Offering a new Perl::Critic::Annotation class for review.
The idea here is to define an object that represents the
"## no critic" markers that appear in the file.  Policies
can then interact with these objects via P::C::Document.

For example, ProhibitUnrestrictedNoCritic would look something
like this:

sub violates {
    my ( $self, $doc, undef ) = @_;

    # If for some reason $doc is not a P::C::Document, then all bets are off
    return if not $doc->isa('Perl::Critic::Document');

    my @violations = ();
    for my $annotation ($doc->annotations()) {
        if ($annotation->disables_all_policies()) {
            my $token = $annotation->token();
            push @violations, $self->violation($DESC, $EXPL, $token);
        }
    }

    return @violations;
}

I've completed most of the work to integrate this with the existing
code.  But I won't commit it until everyone has reviewed this idea.

Comments wanted!
lib/Perl/Critic/Annotation.pm [new file with mode: 0644]