I'm using a run time require to delegate object create to an appropriate subclass like this.
eval "require My::Object::$subclass";
my $obj = My::Object::$subclass->new(@params);
This works fine, but as I edit subclass.pm and introduce syntax errors, they of course can't be caught at compile time. However I would have expected them to be caught at runtime when the require executes, but they aren't.
What actually happens is that every subroutine including and after the one where the syntax error is, just goes missing and the program complains "Undefined subroutine..." when it first tries to call one of the missing subs. I can confirm the loss of the subroutines in the debugger with 'S' - the sub in the required module where the syntax error is and every sub after it is not listed in the current namespace. The Perl Programming book is silent about the syntax checking behavior of the require command.
- Is this the expected behavior?
- Does require not do any syntax checking?
- Is there a way to force syntax checking of a 'required' module?
- Is there a better way that I should be implementing runtime delegation?
Thanks for any help.
Barry
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.