Re: Why the lexical scoping????
Cliff Wheatley (cwheat@concordia.net)
Sat, 03 May 1997 00:34:59 -0500
At 03:19 PM 5/2/97 -0600, you wrote:
>
> First off, if there's a way to subscribe to this mailing list, please, someone
>let me know by sending me e-mail direct to haines@uswest.com. This of course
>implies that if the list has munged the return address, please make sure you CC
>me a copy of your response to the same address.
>
> Okay, here goes. I have been using the libwww stuff recently (version 5.08)
>and have started to get to where I need to make some extensions to it. I want
>to do this is some standard way so that others can use my code without having
>to use a modified version (modified by me) version of libwww. Here's the
>problem stated generally and specifically.
>
>In general:
>
> There are hooks in the LWP class files that look like they were put there to
>help extend functionality of the class. However they are lexically scoped to
>the file (and only the file) by a 'my' statement. An example of this can be
>clearly found in LWP::Protocol for the hash ImplementedBy. Look at the line:
>
>my %ImplementedBy = (); # scheme => classname
>
>
>The only place that this hash is used is in the subroutine 'implementor'. There
>it is read to see if a particular key for that hash has a value. It looks like
>this would allow someone to override the default class that implements a
>scheme or add a scheme. However since nothing exists, we always fallback on:
>
>$ic = "LWP::Protocol::$scheme"; # default location
>
>
>I find no other instances of the hash '%ImplementedBy' in the file. And since
>it is lexically scoped by 'my' to just the file, no code outside the file can
>change/add to the hash. So in general my question is "why?". Why is it scoped
>to just the file? I can find no way to modify it besides modifying the file
>itself and thus creating a non-standard distribution. Is there a valid design
>reason that this and other hashes in other files are lexically scope using
>'my'? Or is it just an oversight? Is there any other way to extend the
>functionallity of this and other classes that was part of the libwww design
>that I am missing?
>
>
>
>Specific case:
>
>What I am actually after is in LWP::Protocol::http. The lexically scoped hash
>'%allowedMethods' seems to represent a check to make sure that the method is
>valid. However, I am coding for a Netscape Enterprise Web server which has some
>non-standard HTTP methods it implements, such as "INDEX", "MKDIR", etc. How can
>I add these methods to the HTTP protocol without modifying the file or creating
>my own custom copy of the file (and the files which use it)?
>
>
>
>Any other suggestions are welcome as are pointers to more documentation,
>examples, etc. about the libwww code.
>
>Thanks in advance,
>Mark Haines
>haines@uswest.com
>
>
>
Your address came out fine on the receiving end. Try sending a message to
libwww-perl-request@ics.UCI.EDU with a subject or text body (can't remember
which, do both -- it won't hurt) with JOIN youremailaddress.
The %ImplementedBy behaivor that you noted is not a bug, it's a feature <g>.
One of the salient points of object-oriented design is encapsulation. By
hiding features of the implementation you force a developer to use the
"public" API rather than depend on something that might change in future
versions.
To implement an extension to the package use another feature of OOP --
inheritance. Check the Perl docs for an explanation of Perl OO and
inheritance. There is also a page, perlbot.htm in my build (303), that
gives some helpful hints.
-Cliff
Dumb answers are free, answers that require thought are at
http://www.concordia.net