Devel::BeginLift(3pm) User Contributed Perl Documentation Devel::BeginLift(3pm)NAME
Devel::BeginLift - make selected sub calls evaluate at compile time
SYNOPSIS
use Devel::BeginLift qw(foo baz);
use vars qw($i);
BEGIN { $i = 0 }
sub foo { "foo: $_[0]
"; }
sub bar { "bar: $_[0]
"; }
for (1 .. 3) {
print foo($i++);
print bar($i++);
}
no Devel::BeginLift;
print foo($i++);
outputs -
foo: 0 bar: 1 foo: 0 bar: 2 foo: 0 bar: 3 foo: 4
DESCRIPTION
Devel::BeginLift 'lifts' arbitrary sub calls to running at compile time - sort of a souped up version of "use constant". It does this via
some slightly insane perlguts magic.
import
use Devel::BeginLift qw(list of subs);
Calls Devel::BeginLift->setup_for(__PACKAGE__ => @list_of_subs);
unimport
no Devel::BeginLift;
Calls Devel::BeginLift->teardown_for(__PACKAGE__);
setup_for
Devel::BeginLift->setup_for($package => @subnames);
Installs begin lifting magic (unless already installed) and registers "${package}::$name" for each member of @subnames to be executed when
parsed and replaced with its output rather than left for runtime.
teardown_for
Devel::BeginLift->teardown_for($package);
Deregisters all subs currently registered for $package and uninstalls begin lifting magic is number of teardown_for calls matches number of
setup_for calls.
setup_for_cv
$id = Devel::BeginLift->setup_for_cv(&code);
Same as "setup_for", but only registers begin lifting magic for one code reference. Returns an id to be used in "teardown_for_cv".
teardown_for_cv
Devel::BeginLift->teardown_for_cv($id);
Deregisters begin lifting magic referred to by $id.
AUTHOR
Matt S Trout - <mst@shadowcatsystems.co.uk>
Company: http://www.shadowcatsystems.co.uk/ Blog: http://chainsawblues.vox.com/
LICENSE
This library is free software under the same terms as perl itself
perl v5.14.2 2012-04-22 Devel::BeginLift(3pm)
Check Out this Related Man Page
Devel::Dwarn(3) User Contributed Perl Documentation Devel::Dwarn(3)NAME
Devel::Dwarn - return Dwarn @return_value
SYNOPSIS
use Devel::Dwarn;
return Dwarn some_call(...)
is equivalent to:
use Data::Dumper::Concise;
if (wantarray) {
my @return = some_call(...);
warn Dumper(@return);
return @return;
} else {
my $return = some_call(...);
warn Dumper($return);
return $return;
}
but shorter. If you need to force scalar context on the value,
use Devel::Dwarn;
return DwarnS some_call(...)
is equivalent to:
use Data::Dumper::Concise;
my $return = some_call(...);
warn Dumper($return);
return $return;
If you need to force list context on the value,
use Devel::Dwarn;
return DwarnL some_call(...)
is equivalent to:
use Data::Dumper::Concise;
my @return = some_call(...);
warn Dumper(@return);
return @return;
If you want to label your output, try DwarnN
use Devel::Dwarn;
return DwarnN $foo
is equivalent to:
use Data::Dumper::Concise;
my @return = some_call(...);
warn '$foo => ' . Dumper(@return);
return @return;
If you want to output a reference returned by a method easily, try $Dwarn
$foo->bar->{baz}->$Dwarn
is equivalent to:
my $return = $foo->bar->{baz};
warn Dumper($return);
return $return;
If you want to immediately die after outputting the data structure, every Dwarn subroutine has a paired Ddie version, so just replace the
warn with die. For example:
DdieL 'foo', { bar => 'baz' };
TIPS AND TRICKS
global usage
Instead of always just doing:
use Devel::Dwarn;
Dwarn ...
We tend to do:
perl -MDevel::Dwarn foo.pl
(and then in the perl code:)
::Dwarn ...
That way, if you leave them in and run without the "use Devel::Dwarn" the program will fail to compile and you are less likely to check it
in by accident. Furthmore it allows that much less friction to add debug messages.
method chaining
One trick which is useful when doing method chaining is the following:
my $foo = Bar->new;
$foo->bar->baz->Devel::Dwarn::DwarnS->biff;
which is the same as:
my $foo = Bar->new;
(DwarnS $foo->bar->baz)->biff;
SEE ALSO
This module is really just a shortcut for Data::Dumper::Concise::Sugar, check it out for more complete documentation.
perl v5.18.2 2013-12-31 Devel::Dwarn(3)