1Class::C3::ComponentiseUds:e:rApCpolnytHroiobkust(e3d)PCelralssD:o:cCu3m:e:nCtoamtpioonnentised::ApplyHooks(3)
2
3
4
6 Class::C3::Componentised::ApplyHooks - Run methods before or after
7 components are injected
8
10 package MyComponent;
11
12 our %statistics;
13
14 use Class::C3::Componentised::ApplyHooks
15 -before_apply => sub {
16 my ($class, $component) = @_;
17
18 push @{$statistics{$class}}, '-before_apply';
19 },
20 -after_apply => sub {
21 my ($class, $component) = @_;
22
23 push @{$statistics{$class}}, '-after_apply';
24 }, qw(BEFORE_APPLY AFTER_APPLY);
25
26 BEFORE_APPLY { push @{$statistics{$class}}, 'BEFORE_APPLY' };
27 AFTER_APPLY { push @{$statistics{$class}}, 'AFTER_APPLY' };
28 AFTER_APPLY { use Devel::Dwarn; Dwarn %statistics };
29
30 1;
31
33 This package allows a given component to run methods on the class that
34 is being injected into before or after the component is injected. Note
35 from the "SYNOPSIS" that all "Load Actions" may be run more than once.
36
38 Both import actions simply run a list of coderefs that will be passed
39 the class that is being acted upon and the component that is being
40 added to the class.
41
43 -before_apply
44 Adds a before apply action for the current component without importing
45 any subroutines into your namespace.
46
47 -after_apply
48 Adds an after apply action for the current component without importing
49 any subroutines into your namespace.
50
52 BEFORE_APPLY
53 BEFORE_APPLY { warn "about to apply $_[1] to class $_[0]" };
54
55 Adds a before apply action for the current component.
56
57 AFTER_APPLY
58 AFTER_APPLY { warn "just applied $_[1] to class $_[0]" };
59
60 Adds an after apply action for the current component.
61
62
63
64perl v5.32.0 2020-0C7l-a2s8s::C3::Componentised::ApplyHooks(3)