in reply to Re: Re: if only blocks were avoidable...
in thread if only blocks were avoidable...
Then, in an example program, you would do:package Foo; require bytes; # make sure the module is loaded without (un)import $bytes = 0; # flag: whether bytes should be enforced $evalled = 0; # flag: whether rest of source has been compiled sub import { unless ($evalled++) { # we haven't evalled the rest +before $bytes = ($_[1] eq "usebytes"); # should bytes be enforced? local $/; # enable slurp mode eval <DATA>; # compile rest of source (afte +r __DATA__) die $@ if $@; # die now if an error occurred } }; 1; # in order for require of Foo.pm to be + successful __DATA__ # actual source of module starts here BEGIN {bytes->import if $bytes} # activate bytes if flag set sub new { bless {},shift } # example routine
Hope this will help you in your quest.use Foo 'usebytes'; # or something else to not use bytes my $foo = Foo->new;
Liz
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Re: if only blocks were avoidable...
by yosefm (Friar) on Sep 22, 2003 at 15:30 UTC | |
by tye (Sage) on Sep 23, 2003 at 16:52 UTC | |
by yosefm (Friar) on Sep 23, 2003 at 20:36 UTC |