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

[Fun With Perl] Package Retrofit



This is a good thing, I think:

    if (not can Mozilla::LDAP::Entry 'getLDIFrecords') {
        eval q{
            package Mozilla::LDAP::Entry;
            sub getLDIFrecords
            {
                [snip]
            }
        }; # eval
    }

In brief, "If that package doesn't have the method I need, add it."

Maybe this bores you, but I learned object-oriented design in a language with
rigid barriers between modules.  (No, not C++.  C++ is laissez-faire compared
to Ada, a *real* fascist language.)  So I struggled to arrive at the idea of
inserting a method into another package.  It still scares me, but I don't know
another way to get the good effects:

   * Newer versions of the other package have the desired method, which I
     call.  That's the optimal organization, for all the reasons that fascist
     languages require it.  But
   * Older versions of that package work fine too, despite lacking the
     necessary method.  So people can use my code without upgrading that
     package, which is valuable at least as long as the current version of
     that package is buggy (which it is).
   * Future versions of that package may inherit the method (it's an instance
     method).

BTW, this code is published, in LDIF.pm in the development branch of PerLDAP
<http://www.mozilla.org/directory/perldap.html>


==== 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