1 package Devel::BeginLift;
7 our $VERSION = 0.001002;
10 use base qw(DynaLoader);
11 use B::Hooks::OP::Check::EntersubForCV;
13 bootstrap Devel::BeginLift;
16 my ($class, @args) = @_;
18 $class->setup_for($target => \@args);
24 $class->teardown_for($target);
28 my ($class, $target, $args) = @_;
29 $lift{$target} ||= [];
30 push @{ $lift{$target} }, map {
31 $class->setup_for_cv($_);
35 : \&{ "${target}::${_}" }
40 my ($class, $target) = @_;
41 $class->teardown_for_cv($_) for @{ $lift{$target} };
42 delete $lift{$target};
47 Devel::BeginLift - make selected sub calls evaluate at compile time
51 use Devel::BeginLift qw(foo baz);
57 sub foo { "foo: $_[0]\n"; }
59 sub bar { "bar: $_[0]\n"; }
82 Devel::BeginLift 'lifts' arbitrary sub calls to running at compile time
83 - sort of a souped up version of "use constant". It does this via some
84 slightly insane perlguts magic.
88 use Devel::BeginLift qw(list of subs);
90 Calls Devel::BeginLift->setup_for(__PACKAGE__ => \@list_of_subs);
96 Calls Devel::BeginLift->teardown_for(__PACKAGE__);
100 Devel::BeginLift->setup_for($package => \@subnames);
102 Installs begin lifting magic (unless already installed) and registers
103 "${package}::$name" for each member of @subnames to be executed when parsed
104 and replaced with its output rather than left for runtime.
108 Devel::BeginLift->teardown_for($package);
110 Deregisters all subs currently registered for $package and uninstalls begin
111 lifting magic is number of teardown_for calls matches number of setup_for
116 $id = Devel::BeginLift->setup_for_cv(\&code);
118 Same as C<setup_for>, but only registers begin lifting magic for one code
119 reference. Returns an id to be used in C<teardown_for_cv>.
121 =head2 teardown_for_cv
123 Devel::BeginLift->teardown_for_cv($id);
125 Deregisters begin lifting magic referred to by C<$id>.
129 Matt S Trout - <mst@shadowcatsystems.co.uk>
131 Company: http://www.shadowcatsystems.co.uk/
132 Blog: http://chainsawblues.vox.com/
136 This library is free software under the same terms as perl itself