1 package Class::C3::Componentised::ApplyHooks;
9 sub BEFORE_APPLY (&) { push @{$Before{scalar caller}}, $_[0] };
10 sub AFTER_APPLY (&) { push @{$After {scalar caller}}, $_[0] };
15 my ($from, @args) = @_;
29 if ($arg eq '-before_apply') {
32 push @{$Before{$to}}, $args[$i + 1]
33 } elsif ($arg eq '-after_apply') {
36 push @{$After{$to}}, $args[$i + 1];
37 } elsif ($arg =~ /^BEFORE_APPLY|AFTER_APPLY$/) {
43 @import = qw(BEFORE_APPLY AFTER_APPLY)
46 *{"$to\::$_"} = \&{"$from\::$_"} for @import
54 Class::C3::Componentised::ApplyHooks
62 use Class::C3::Componentised::ApplyHooks
63 -before_apply => sub {
64 my ($class, $component) = @_;
66 push @{$statistics{$class}}, '-before_apply';
69 my ($class, $component) = @_;
71 push @{$statistics{$class}}, '-after_apply';
72 }, qw(BEFORE_APPLY AFTER_APPLY);
74 BEFORE_APPLY { push @{$statistics{$class}}, 'BEFORE_APPLY' };
75 AFTER_APPLY { push @{$statistics{$class}}, 'AFTER_APPLY' };
76 AFTER_APPLY { use Devel::Dwarn; Dwarn %statistics };
82 This package allows a given component to run methods on the class that is being
83 injected into before or after the component is injected. Note from the
84 L</SYNOPSIS> that all C<Load Actions> may be run more than once.
88 Both import actions simply run a list of coderefs that will be passed the class
89 that is being acted upon and the component that is being added to the class.
95 Adds a before apply action for the current component without importing
96 any subroutines into your namespace.
100 Adds an after apply action for the current component without importing
101 any subroutines into your namespace.
103 =head1 EXPORTED SUBROUTINES
107 BEFORE_APPLY { warn "about to apply $_[1] to class $_[0]" };
109 Adds a before apply action for the current component.
113 AFTER_APPLY { warn "just applied $_[1] to class $_[0]" };
115 Adds an after apply action for the current component.