It sounds like you need to rethink your approach as this isn't simple stuff I'm afraid. There isn't, too my knowledge, a way of avoiding compiling code in a file, short of die()ing in the BEGIN block or some other such hackery. So if you're not too bothered about a bit of symbol table munging, and you want the subs in the current package to disappear on the case of failure then something like this might do
BEGIN {
eval { require Maybe::Module };
$::SPLAT = 1 if $@;
}
## *right* at the end of the file
if($::SPLAT) {
require Symbol and Symbol->import('delete_package');
delete_package(__PACKAGE__);
}
1;
Now in the event of the failure to require the given module the current package will be deleted in it's entirety. If the current package is main or someone else's package, then stick a package Other::Package::__temp at the top and export the subroutines upon success e.g
package Other::Package::__temp;
BEGIN {
eval { require Maybe::Module };
$::SPLAT = 1 if $@;
}
## *right* at the end of the file
if($::SPLAT) {
require Symbol and Symbol->import('delete_package');
delete_package(__PACKAGE__);
} else {
@{caller()."::"}{keys %{__PACKAGE__."::"}}
= values %{__PACKAGE__."::"};
}
1;
That will export the globs in the current package to the caller's package, which should do the trick.
HTH
_________ broquaint |