Stuff with the Perl Foundation. A couple of patches in the Perl core. A few CPAN modules. That about sums it up.
The problem: Bermuda needs to be relocatable. This means that a lot of the auto-generated code needs to not require that Bermuda be installed. My Bermuda::Writer package needs to supply a base serialization class, but I need to test this class. To do that, I had Bermuda::Serialize::Base both in its own file, but also embedded in my Bermuda writer as a string.
That duplication is bad, but someone needs control over their serialization base class name and it shouldn't force them to use 'Bermuda', so here's what I did:
sub _base_class_code {
my ( $class, $package ) = @_;
my $writer = $INC{'Bermuda/Writer.pm'};
my @path = splitdir($writer);
pop @path; # discard Writer.pm
my $base = catfile( @path, 'Serialize', 'Base.pm' );
open my $fh, '<', $base or die "Cannot open ($base) for reading: $!";
my $base_class_code = do { local $/; <$fh> };
close $fh or die "Cannot close ($base): $!";
$base_class_code =~ s/Bermuda::Serialize::Base/$package/gs;
return $base_class_code;
}
This makes me feel really icky, but I've removed some duplication and now this code can be relocated.
Unix blinders? (Score:1)
Are you sure you want
splitdir/catfileand notsplitpath/catpath?Re: (Score:2)
To be honest, I use those so seldom, I never really paid attention to the difference.
Making both of those changes results in a lot of uninit value warnings from catpath, even though the tests pass :/
Re: (Score:1)
Huh, what are you passing to it?
Re: (Score:2)
Er, um, really wish I had read the documentation rather than doing a quick %s/one/fortheother/. *blush*.
Re: (Score:1)
Heh. That’s what I meant by “Unix blinders” – and not pejoratively, as I used to wear them for the longest time myself. Unix is so nicely simple: no volumes, no distinct namespaces for file and directory names, just one uniform hierarchy… after a while one forgets the bizarre things that exist elsewhere.
Re: (Score:1)
Avoid the extra file? (Score:1)
How about a method that returns the serialiser code as a string (with selectable package name), which can then be
evaled by the test file for testing?Re: (Score:2)
I don't want to embed a string of code. I'm doing a huge amount of that already to do code generation and it makes a lot of my code hard to follow, despite aggressive refactoring. If I keep these packages in real packages, I get the benefits of my t/00-load.t test:
Re: (Score:1)
Put it in a SelfLoader module and add a method to pull out the source via the package’s
DATAhandle? That way you avoid all the path diddling gymnastics and it automatically works as a standalone module.