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:
and Foo.pm:package Bar use interface Foo; warn "blaah"; 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).package Foo; sub bar {} 1
Thanks!
In reply to eval "use $module" doesn't by nothingmuch
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |