News from the kitchen

2002 October 29
by darkness

I’m in the kitchen with my laptop. I love wireless.

Was working on a Perl Wiki last night and instead got distracted by making interface.pm work. It was doing something like this:

package A;

use B;  # B is playing the role of interface here.

package B;

sub import
{
  # It expected this to force Perl to finish loading A so it could
  # read the methods defined in A.
  eval "use A";

  ... do stuff with methods in A ...
}  # import

The problem here is that… it didn’t work. In the above case, I think package A does get loaded twice, but never until B finishes loading. Instead I had to basically translate the package name from Foo::Bar to Foo/Bar.pm, look in %INC for the file, then do $INC{$fileName}. I’m a bit worried because in this case (and the original implementation of interface for that matter), A will get loaded twice. I hope there’s nothing like $myInstanceVariable++ in its initialization.

I also made an abstract.pm so I could define interfaces like this:

package SomeInterface;

use abstract;

abstract someMethod;

Pretty useless, perhaps, but it makes me feel better. Plus it automatically stubs out the method with a call to croak. I’ll have to post my interface.pm and abstract.pm some time.

I’m on to writing the Wiki again tonight. I’m actually sitting down and working out the object model. I think XP says not to do this, but this isn’t an XP project (entirely). I’m trying to figure out how to make it totally extensible. I’m undoubtedly going to look back on this entire project later and say “why the hell did I do this?” Back off to coding, though.

No Comments

Leave A Comment

Note: You can use basic XHTML in your comments. Your email address will never be published.

Subscribe to this comment feed via RSS