1Tangerine::Hook(3) User Contributed Perl Documentation Tangerine::Hook(3)
2
3
4
6 Tangerine::Hook - A simple hook class
7
9 package MyHook;
10 use parent 'Tangerine::Hook';
11 use Tangerine::HookData;
12 use Tangerine::Occurence;
13
14 sub run {
15 my ($self, $s) = @_;
16 if ($s->[0] eq 'use' && $self->type eq 'compile' &&
17 $s->[1] && $s->[1] eq 'MyModule') {
18 return Tangerine::HookData->new(
19 modules => { MyModule => Tangerine::Occurence->new },
20 )
21 }
22 return
23 }
24
26 Hooks are the workhorses of Tangerine, examining the actual code and
27 returning Tangerine::HookData where applicable.
28
29 Every hook has a type, which can be one of 'package', 'compile' or
30 'runtime', set by the caller and determining what she is interested in.
31
32 Every hook should implement the "run" method which is passed an array
33 reference containing the significant children (see PPI::Statement) of
34 the currently parsed Perl statement.
35
36 The caller expects a Tangerine::HookData instance defining what
37 "modules" of the requested "type" we found, what "hooks" the caller
38 should register or what "children" shall be examined next. Either or
39 all these may be returned at once.
40
42 "type"
43 Returns or sets the hook type. May be one of "package", "compile"
44 or "runtime".
45
46 "run"
47 This is called by Tangerine with an array reference containing the
48 significant children of the currently parsed Perl statement.
49 Returns a Tangerine::HookData instance.
50
51 Every hook needs to implement this method.
52
54 "Tangerine", "PPI::Statement", "Tangerine::HookData"
55
57 Petr Šabata <contyk@redhat.com>
58
60 Copyright (c) 2014-2016 Petr Šabata
61
62 See LICENSE for licensing details.
63
64
65
66perl v5.30.1 2020-01-30 Tangerine::Hook(3)