1Perl::Critic::DynamicPoUlsiecry(C3o)ntributed Perl DocumPeenrtla:t:iCornitic::DynamicPolicy(3)
2
3
4
6 Perl::Critic::DynamicPolicy - Base class for dynamic Policies
7
9 Perl::Critic::DynamicPolicy is intended to be used as a base class for
10 Perl::Critic::Policy modules that wish to compile and/or execute the
11 code that is being analyzed.
12
13 Policies that inherit from Perl::Critic::DynamicPolicy will "fork" the
14 process each time the "violates" method is called. The child process
15 is then free to compile the code and do other mischievous things
16 without corrupting the symbol table of the parent process. When the
17 analysis is complete, the child serializes any Perl::Critic::Violation
18 objects that were created and sends them back to the parent across a
19 pipe.
20
21 Any Policy that inherits from Perl::Critic::DynamicPolicy will also be
22 marked as "unsafe" and is usually ignored by both Perl::Critic and
23 perlcritic. To use a Policy that inherits from
24 Perl::Critic::DynamicPolicy, you must set the "-allow-unsafe" switch in
25 the Perl::Critic constructor or on the perlcritic command line.
26
27 In every other way, a Perl::Critic::DynamicPolicy behaves just like an
28 ordinary Perl::Critic::Policy. For Policy authors, the main difference
29 is that you must override the "violates_dynamic" method instead of the
30 "violates" method. See Perl::Critic::DEVELOPER for a discussion of the
31 other aspects of creating new Policies.
32
34 This list of methods is not exhaustive. It only covers the methods
35 that are uniquely relevant to Perl::Critic::DynamicPolicy subclasses.
36 See Perl::Critic::Policy and Perl::Critic::DEVELOPER for documentation
37 about the other methods shared by all Policies.
38
39 " violates( $doc, $elem ) "
40 In a typical Perl::Critic::Policy subclass, you would override the
41 "violates" method to do whatever code analysis you want. But with
42 Perl::Critic::DynamicPolicy, this method has already been
43 overridden to perform the necessary pipe and fork operations that I
44 described above. So instead, you need to override the
45 "violates_dyanmic" method.
46
47 " violates_dynamic( $doc, $elem ) "
48 Given a PPI::Element and a PPI::Document, returns one or more
49 Perl::Critic::Violation objects if the $elem or <$doc> violates
50 this Policy. If there are no violations, then it returns an empty
51 list. This method will be called in a child process, so you can
52 compile $doc without interfering with the parent process.
53
54 "violates_dynamic" is an abstract method and it will abort if you
55 attempt to invoke it directly. It is the heart of your
56 Perl::Critic::DynamicPolicy modules, and your subclass must
57 override this method.
58
59 " is_safe() "
60 Returns false. Any Policy derived from this module is presumed to
61 be unsafe. Perl::Critic and perlcritic users can only load
62 Policies derived from this module if they use the "-allow-unsafe"
63 switch.
64
66 Jeffrey Ryan Thalhammer <thaljef@cpan.org>
67
69 Copyright (c) 2007 Jeffrey Ryan Thalhammer. All rights reserved.
70
71 This program is free software; you can redistribute it and/or modify it
72 under the same terms as Perl itself. The full text of this license can
73 be found in the LICENSE file included with this module.
74
75
76
77perl v5.30.0 2019-07-26 Perl::Critic::DynamicPolicy(3)