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
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.