BEGIN { require Module; Module->import( LIST ); }
####
use Module ();
##
##
BEGIN { require Module }
##
##
#!/usr/bin/perl
use strict;
use warnings;
BEGIN {
print ">>> About to execute 'use LoadMe;' <<<\n";
}
use LoadMe;
BEGIN {
print ">>> LoadMe was loaded <<<\n";
}
print "***** See? No code in LoadMe is executed! *****\n";
##
##
package LoadMe;
use strict;
use warnings;
INIT {
print "LoadMe: INIT is evaluated\n";
system "echo Would I run rm -rf / ?";
}
CHECK {
print "LoadMe: CHECK is evaluated\n";
system "echo Check check, is this thing on?";
}
UNITCHECK {
print "LoadMe: UNITCHECK is evaluated\n";
system "echo Luckily, format C: does not work on linux";
}
BEGIN {
print "LoadMe: BEGIN is evaluated\n";
system "echo what could go wrong?";
}
END {
print "LoadMe: END is evaluated\n";
system "echo Good bye cruel world";
}
sub foo
{
print "LoadMe: foo\n";
}
sub import
{
my $class=shift;
print "LoadMe: import called as ${class}->import(",join(',',@_),")\n";
system "echo Oh well, no smart comment here";
}
print "LoadMe: Module initialisation\n";
system "echo Perl is fully working and can run arbitary code, including external programs";
1; # or any other non-false value
##
##
/tmp/use-demo>perl demo.pl
>>> About to execute 'use LoadMe;' <<<
LoadMe: BEGIN is evaluated
what could go wrong?
LoadMe: UNITCHECK is evaluated
Luckily, format C: does not work on linux
LoadMe: Module initialisation
Perl is fully working and can run arbitary code, including external programs
LoadMe: import called as LoadMe->import()
Oh well, no smart comment here
>>> LoadMe was loaded <<<
LoadMe: CHECK is evaluated
Check check, is this thing on?
LoadMe: INIT is evaluated
Would I run rm -rf / ?
***** See? No code in LoadMe is executed! *****
LoadMe: END is evaluated
Good bye cruel world
/tmp/use-demo>
##
##
/tmp/use-demo>perl -cw demo.pl
>>> About to execute 'use LoadMe;' <<<
LoadMe: BEGIN is evaluated
what could go wrong?
LoadMe: UNITCHECK is evaluated
Luckily, format C: does not work on linux
LoadMe: Module initialisation
Perl is fully working and can run arbitary code, including external programs
LoadMe: import called as LoadMe->import()
Oh well, no smart comment here
>>> LoadMe was loaded <<<
LoadMe: CHECK is evaluated
Check check, is this thing on?
demo.pl syntax OK
/tmp/use-demo>perl -cw LoadMe.pm
LoadMe: BEGIN is evaluated
what could go wrong?
LoadMe: UNITCHECK is evaluated
Luckily, format C: does not work on linux
LoadMe: CHECK is evaluated
Check check, is this thing on?
LoadMe.pm syntax OK
/tmp/use-demo>