If you want to spare the user the trouble of reblessing, do it yourself: make the class the return value should be blessed into an optional second argument to ChildGet().

sub ChildGet { my ( $self, $class ) = @_; $class = "Etk::Widget" unless defined $class; my $child = $self->{_CHILD} ? $self->{_CHILD} : child_get($self); return bless $child, $class; }

That's functionally equivalent to the C requirement that the user perform the casting. Since the information about what kind of Widget you've got can't be determined from the return value of the C function, if you want to make this DWIMmy Perl and not require that second argument, you're either going to have to add metadata to your C object or go with the global hash. You make the call. :)

You can also do this in XS, if you want.

void ChildGet(bin, ...) Etk_Bin * bin; PREINIT: char * class = "Etk::Widget"; Etk_Button * button; PPCODE: if (items > 1) class = SvPV_nolen( ST(1) ); button = TK_BUTTON(etk_bin_child_get(bin)); ST(0) = sv_newmortal(); sv_setref_pv(ST(0), class, (void*)button); XSRETURN(1);

I'm not sure that's quite right, because after spelunking your typemap and your .xs file, I still don't grok how you're getting hash objects -- but you get the general idea.

The fact that I'm a half-decent XS hacker and I can't figure out how to do this says something about its maintainability. :)

--
Marvin Humphrey
Rectangular Research ― http://www.rectangular.com

In reply to Re: Keeping track of classes by creamygoodness
in thread 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.