Slurping Installed Package Code

Ovid on 2008-01-31T11:39:38

Well, things have changed a bit and I have my "1 in 10" day a bit earlier than expected. I thought about working on my Oslo talk, but instead I am working on Bermuda. Several people have expressed interest and I need to move forward on this.

Right now I need a better way of testing generated code. For example, if I have a 'Bermuda::Serialization::Base' class (I could use a better name), I'm currently embedding that in a string which gets written to a target file. However, that should actually be in its own file which I can load and test. Then when Bermuda files are written out, it gets read in, the package name changed, and written to the target directory so that there's no dependency left on Bermuda after deployement.

So let's say I have this:

lib/Bermuda.pm
lib/Bermuda/Writer.pm
lib/Bermuda/Serializable/Base.pm

What happens is that Bermuda::Writer slurps in Bermuda::Serializable::Base, rewrites the package name and writes it out to the target directory. But how do I do that?

The %INC entry looks like this:

'Bermuda/Writer.pm' => 'lib/Bermuda/Writer.pm'

Seems to me that I can s{Writer.pm}{Serializable/Base.pm} (perhaps with some File::Spec magic and know the name of the class I need to read in. Are there problems with this approach? Is there an obvious and completely better way of handling this?

The name also bugs me. I don't like 'Serializable' in a name as that suggests (to me) a trait or an interface. Also, it's not a class to be used directly. Instead, it gets written out to the target dir. Should it be something like Bermuda::Relocatable::Serialization::Base or Bermuda::Triangle::Serialization::Base? (no, I'm not serious about that last one).

This seems like a minor issue, but part of the reason the new Test::Harness was successful is that the internals were relatively clean and we fought hard to keep them that way (they're complex, but still clean). HTML::TokeParser::Simple, on the other hand, was bug-ridden and limited because when I first released it, it was a mess. Subsequent releases weren't much better because I was lazy and it was still a mess. It's was a painful lesson.