Hi.
I’m updating (and trying to clean) a legacy perl app that deals with document management. It seems that it has been repeatedly patched through the years, with various developers tacking on functionality. It’s now large, sprawling piece of code with lots of secondary programs tapping into its libraries.
It uses URI::URL throughout. This would be fine, despite being deprecated, except that the system utilizes numerous secondary hashes to store “extra” information about the URI. A common example…
my $uri = new URI::URL “http://foo.bar”;
$self->{URL}->{$uri}->{authenticated} = 1;
$self->{URL}->{$uri}->{available} = 1;
…
return $uri;
The rest of the code calls back into the creating object to “lookup” the extra URI information and the creating object isn’t even in scope in some areas.
My original plan was to create a new class which inherited from the URI class via an @ISA relationship. This would let me bundle the extra data with the URI, while ensuring backward compatibility throughout the applications. As many of you probably already know, I ran into a few snags…here are the big ones:
- URI and URL::URI objects rely on being usable as ‘rvalues’. The URI is a scalar and the URL::URI is an array with a single element.
- URI morphs itself into new classes during construction, such as URI::http. If you make an @ISA subclass, your object will morph when the URI constructor is called. This might be managed via multiple/dynamic inheritance, but is messy.
I suspect I’m going to end up creating a new class that ‘contains’ a URI and create pass-through methods that transfer calls from my new class to the contained class. The problems with this are…
- The pass-through methods are unlikely to be updated regularly… is there an automagical way to maintain these safely?
- Many programs out there already rely on being able to use a URI::URL object as a scalar… ie. 'print if $uri =~ /pdf\s+$/;’ Is there any way to control the value returned when an object is used in a scalar context?
Thanks in advance for any suggestions. If I can’t maintain the rvalue functionality, it’ll be a lot of work just to find all the programs with dependencies on these libraries, much less updating and testing them.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.