You have some strange code reversal here. I would think it'd be a better design to make what you call 'parent' a subclass of 'test', and specify methods to overload to let 'parent' inherit the overloading, or specialize it if need be. For example:

{ package test; use overload '+' => 'op_add'; sub op_add { ... } } { package parent; use test; use base qw(test); }
Instances of 'parent' inherit the overload of '+' here.

Overloading is a pretty delicate and specific thing to just toss into your class based on what your attribute classes are doing. If you insist on going this direction you describe you might be able to accomplish by setting up an accessor for this 'test' attribute of 'parent'. When it's set check to see if the object specified has the overloading you're looking for, then set it up at run-time. You'll probably need a closure to do it properly, and even then it may not work.

That's the most advice I'm willing to give. Falling back on overloading, or setting it up at run-time, are both going to make for some very confusing classes to use. I seriously suggest you rethink your design.


In reply to Re: Overload and nomethd by Somni
in thread Overload and nomethd by ewaters

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.