[SearchBuilder-devel] problems with capitalization.pm and OO modules
David Glasser
glasser at bestpractical.com
Tue Jun 14 15:02:37 EDT 2005
capitalization.pm is fundamentally incompatible with OO modules.
Given a class such as SearchBuilder, the lower-case methods are
aliased to the uppercase methods.
However, when you subclass SearchBuilder, you run into problems.
Let's say you want to override SomeFunction. There are a few choices:
(a) Define SubClass::SomeFunction. But then if you use -
>some_function in your code anywhere, it won't find
SubClass::SomeFunction -- it'll call SearchBuilder::some_function,
which is aliased to SearchBuilder::SomeFunction.
(b) Define SubClass::some_function. But then if you use -
>SomeFunction in your code anywhere, or in fact wherever
SearchBuilder.pm *itself* uses ->SomeFunction, it won't find
SubClass::some_function -- it'll call SearchBuilder::SomeFunction.
(c) Require every subclass of SearchBuilder to define the methods
that they override as CamelCase, and to also use capitalization to
lower_case all functions that they override. But in this case:
* capitalization is no longer the optional feature that we
advertise it as -- anybody who ever wants to make a subclass **must**
follow this rule
* it requires subclassers to use CamelCase, which kind of defeats
the point of allowing customizable casing
For example, I wouldn't be surprised if there are bugs with using
lower_case method names when addressing a
SearchBuilder::Record::Cachable.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: cap-test.tar.gz
Type: application/x-gzip
Size: 1575 bytes
Desc: not available
Url : http://lists.bestpractical.com/pipermail/searchbuilder-devel/attachments/20050614/293392dc/cap-test.tar-0001.bin
-------------- next part --------------
Attached is a tarball showing this problem; just run test.pl to see
what's going on.
Any ideas?
I've tried the relatively obvious thing which aliases the new_name to
sub { my $self = shift; $self->$CamelName(@_) }
While this at least fixes the problem of "I overrode it with
CamelCase and I called it with lower_case and it didn't work", it
doesn't fix the opposite problem. There might also be some
complicated ugly AUTOLOAD-based way to deal with this, but I'm not
sure what that would be. Or perhaps you could do something involving
actually asking SB for one API or the other when you use it? So you
might do
use MySBSubclass qw/:lower_case/;
and the import function would decapitalize MySBSubclass and all of
its superclass' methods right then?
--dave
Code Monkey, Best Practical Solutions
--
David Glasser | glasser at bestpractical.com
More information about the SearchBuilder-devel
mailing list