-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
=pod
A while ago, L uploaded
C to the CPAN. He seemed pretty excited about it,
but I honestly never really understood what it did (incomprehensible
example in the docs). In case you're in the same boat, here's a quick
example.
Let's write a module called C:
lang:Perl
package foo;
sub bar { print "Hello from foo::bar\n" }
1;
Then a script, C to run it:
#!/usr/bin/env perl
use foo;
foo::bar;
When you run C, you get:
lang:undef
Hello from foo::bar
Hopefully this is what you expected. Let's expand C like
this:
lang:Perl
#!/usr/bin/env perl
use foo;
BEGIN { print "before foo::bar\n" }
foo::bar;
BEGIN { print "after foo::bar\n" }
This time, the output is:
lang:undef
before foo::bar
after foo::bar
Hello from foo::bar
If this confuses you, please learn Perl before continuing. Now let's
throw C into the mix. Here's C again:
lang:Perl
package foo;
use Devel::BeginLift qw(bar);
sub bar { print "Hello from foo::bar\n" }
1;
And the output:
before foo::bar
Hello from foo::bar
after foo::bar
So what happened? C made C (mentioned in its
import list) run at C time instead of runtime. That's it.
Pretty neat.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
iD8DBQFHYdoe2rw+dVvzZm0RAn1BAKCjdWDeWot4XPLCz/ZtxyjmklVY9QCdGU34
34MxrpVBCvhKvfm4pr+jEnk=
=n7aN
-----END PGP SIGNATURE-----