[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [Fun With Perl] Package Retrofit




> And isn't there a more standard way to accomplish this using the autoloader?

I doubt it.  You'd have to put it into Mozilla::LDAP::Entry::AUTOLOAD,
and tampering with another package's AUTOLOAD seems to me like a much
worse idea than tampering with its other methods.

Another approach is to subclass Mozilla::LDAP::Entry, like this:

	package Tricky::LDAP::Entry;
	@ISA = qw(Mozilla::LDAP::Entry);

	$can_getLDIFrecords = can Mozilla::LDAP::Entry 'getLDIFrecords';
	sub new {
	  my ($package) = @_;
	  my $new = $package->SUPER::new(@_);
	  return $can_getLDIFrecords ? $new : bless $new => $package;
	}

	sub getLDIFrecords { ... }

There are two possibilities here.  If the original package provides
the getLDIFrecords function, then the constructor here just returns
the objects that are constructed by Mozilla::LDAP::Entry.  This is so
that methods that you call on those objects don't have to be
inherited.

But if there is no getLDIFrecords function, then the constructor
blesses the Mozilla::LDAP::Entry object into the new
Tricky::LDAP::Entry, which provides the getLDIFrecords method as well
as the other methods that it inherits.


==== Want to unsubscribe from this list? (Don't you love us anymore?)
==== Well, if you insist... Send mail with body "unsubscribe" to
==== fwp-request@technofile.org