> I can feel that you are a little bit confused. >

This exact sort of thing is a breeze in ruby.

I say that with good humor!

Unfortunately it's difficult to summarize precisely why I need to do what I'm trying to do here - the best I can do is explain _what_ I need...: It's important for me to be able to inject a custom method ( "dbq" ) into an object of an external class ( "DBI" ) which has been instantiated as an attribute ( "_dbh" ) of a custom base class ( "Foo" ). How do I do so?

That is what I would like to do - if possible.

>$db->dbq("whateverquery");

That's fine for client code that directly instantiates an object of the class in question ( "Foo.pm", "DB.pm", whatever ).

One may rightly ask: "So why not just pass the '$foo'/'$db' object itself to those legacy modules?"

Because the "$db"/"$foo" class is much, much more than a simple, specialized/dedicated piece of functionality, such as your example. Passing a large object with a bunch of unrelated methods/attributes to another object that simply wants access to one specific method is serious, ugly overkill which I'm hoping to avoid - the very sort of thing why it's all being refactored/rewritten in the first place. In other words, I'm trying to trick the old code into just using the new stuff without a care or any suspicion that something has changed.

I'm working with a semi-largish codebase, alot of which relies on receiving an object w/ a particular method, "dbq" in this instance. We're talking some 140+ perl scripts and shoddy modules that all rely on using/recieving this old '$dbh->dbq' thing.

I've done some major refactoring and have written some decent oop libraries to replace the existing mess with something more sane; however we simply don't have the time to re-write/re-factor every one of those 140+ scripts/modules at the moment.

Thanks for your time, it's difficult to communicate/discuss the nature of the problem without way too much verbosity and code!


In reply to Re^2: object method question by Zarathustra
in thread object method question by Zarathustra

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.