Hack #42. Find and Report Module Bugs
Fix problems in CPAN modules.
In an ideal world, all software is fully tested and bug free. Of course that's rarely the case.
Using Perl modules offers many advantages, including more thoroughly validated routines, tested and optimized solutions, and the fact that someone has already done part of your job for you. Sometimes, though, you may find that the shiny module that does exactly what you need actually does something different than it should have.
Here's some code that creates a proxy object FooProxy. When you create an instance of this proxy object, it should behave just like an instance of the original Foo object, but FooProxy could modify specific behavior of the Foo object, perhaps to log method calls or check access [Hack #48], without altering the Foo package itself:
package FooProxy;
sub new
{
my $class = shift;
my $foo = Foo->new( @_ );
bless \\$foo, $class;
}
sub can
{
my $self = shift;
return $$self->can( @_ );
}
1;Here's some code that instantiates a FooProxy object, and being paranoid, attempts to double-check that the created object looks just like a Foo object:
# Create a proxy object
my $proxy = FooProxy->new( );
# Make sure the proxy acts like a Foo
if ($proxy->isa('Foo'))
{
print "Proxy is a Foo!\\n";
}
else
{
die "Proxy isn't a Foo!";
}When you run this script, you might notice a problem. When you call a Foo method on the $fooproxy object, the method complains that the object isn't Foo. What's going on?
Instead of diving ...