Fellow monks,

I've written perl bindings for etk, (cpan). I'm currently writing the test suit and came across some inconsistencies:

Etk's objects mostly all extend the Etk::Widget object and the perl objects are simply blessed hash references that have an IV that points to the C object.

Most of the C functions that take objects take Etk_Widget and those that return them will also return an Etk_Widget, which the programmer has to cast to the appropriate type. Here's an example:

Etk_Bin * bin; Etk_Button * button; // assume the above initialized. etk_bin_child_set(bin, ETK_WIDGET(button); // and the get the button. button = ETK_BUTTON(etk_bin_child_get(bin));

Now in the perl version:

$bin->ChildSet($button); $button = $bin->ChildGet();

The problem is, passing $button to ChildSet works because of the inheritance, and $button is a widget, so it's cast correctly in the XS code, but ChildGet will return an Etk_Widget, and through the typemap the returned object will have Etk::Widget as a class, and therefore the programmer has to bless the object to the appropriate type, but that's not very perly.

I'm wondering on how best to keep track of what the objects were to return them. Here are the few options I can think of:

Any pointers or comments are greatly appreciated.

--
Leviathan.

In reply to Keeping track of classes by Leviathan

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.