Jeffrey Ryan Thalhammer > Perl-Critic-Dynamic > Perl::Critic::DynamicPolicy

Download:
dynamic/Perl-Critic-Dynamic-0.04.tar.gz

Dependencies

Annotate this POD

CPAN RT

New  1
Open  1
View/Report Bugs
Module Version: 0.03   Source   Latest Release: Perl-Critic-Dynamic-0.05

NAME ^

Perl::Critic::DynamicPolicy - Base class for dynamic Policies

DESCRIPTION ^

Perl::Critic::DynamicPolicy is intended to be used as a base class for Perl::Critic::Policy modules that wish to compile and/or execute the code that is being analyzed.

Policies derived from Perl::Critic::DynamicPolicy will fork the process each time the violates method is called. The child process is then free to compile the code and do other mischievous things without corrupting the symbol table of the parent process. When the analysis is complete, the child serializes any Perl::Critic::Violation objects that were created and sends them back to the parent across a pipe.

In every other way, a Perl::Critic::DynamicPolicy behaves just like an ordinary Perl::Critic::Policy. For Policy authors, the main difference is that you must override the violates_dynamic method instead of the violates method. See Perl::Critic::DEVELOPER for a discussion of the other aspects of creating new Policies.

METHODS ^

This list of methods is not exhaustive. It only covers the methods that are uniquely relevant to Perl::Critic::DynamicPolicy subclasses. See Perl::Critic::Policy and Perl::Critic::DEVELOPER for documentation about the other methods shared by all Policies.

violates( $doc, $elem )

In a typical Perl::Critic::Policy subclass, you would override the violates method to do whatever code analysis you want. But with Perl::Critic::DynamicPolicy, this method has already been overridden to perform the necessary pipe and fork operations that I described above. So instead, you need to override the violates_dyanmic method.

violates_dynamic( $doc, $elem )

Given a PPI::Element and a PPI::Document, returns one or more Perl::Critic::Violation objects if the $elem or <$doc> violates this Policy. If there are no violations, then it returns an empty list. This method will be called in a child process, so you can compile $doc without interfering with the parent process.

violates_dynamic is an abstract method and it will abort if you attempt to invoke it directly. It is the heart of your Perl::Critic::DynamicPolicy modules, and your subclass must override this method.

AUTHOR ^

Jeffrey Ryan Thalhammer <thaljef@cpan.org>

COPYRIGHT ^

Copyright (c) 2007 Jeffrey Ryan Thalhammer. All rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The full text of this license can be found in the LICENSE file included with this module.

syntax highlighting: