Howdy...

I'm trying to use interface, which is nicer than base if you don't trust yourself.

What it does is, in theory, is when it's import is called, it loads the calling module completely (using eval "use $foo"), making sure that it doesn't recurse into it's own import, and then when the calling module is loaded, it checks that all the methods in all the interfaces are implemented by the calling package or one of it's ancestors.

What happens in practice is that eval "use $pkg" goes into $pkg's import, and then exits from there, without finishing the compilation of the code in "${pkg}.pm".

One solution that works in general but breaks in some cases (especially BEGIN { require_ok("module"}, module->import }) is to delay interface checking from BEGIN time to CHECK time by building a queue. In the require_ok case, what happens is that OK is given to the harness, and then the test dies if the interface is incomplete. Not fun.

Is there any way to get the calling package's file to do something when it's done parsing (aside from source filters, which I think is even more flakey and overkill than delaying to CHECK)?

Is there anyway to use the recursive approach and get it to actually parse, and not return immediately?

Update: an example...

Given two files, Bar.pm:

package Bar use interface Foo; warn "blaah"; sub bar { } 1
and Foo.pm:
package Foo; sub bar {} 1
somewhere in @INC, perl -e 'require Bar'; does not print "blaah", but dies, saying that Bar doesn't implement a 'bar' like Foo requires, and furthermore perl -de 'require Bar'; traces through interface's eval "use $pkg", but warn "blaah"; is not encountered (even if it is wrapped in a BEGIN{} block).

Thanks!

-nuffin
zz zZ Z Z #!perl

In reply to eval "use $module" doesn't by nothingmuch

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.