Overload is handled by "magic", and there are a number of perlapi functions which handle it properly, for instance sv_catsv. If you are manipulating strings by accessing the SvPVX directly, then the overloading won't kick in, but if you use sv_catsv, it will work.

Here's an extremely verbose version of "hello_world.plx" which illustrates the point:

package World; use strict; use warnings; use overload '""' => sub { "world" }; sub new { bless {}, __PACKAGE__ } package main; use strict; use warnings; use Inline C => <<'END_C'; void magical_concat(SV *a, SV *b) { sv_catsv(a, b); } END_C my $greeting = "Hello, "; my $world = World->new; magical_concat($greeting, $world); $greeting .= ".\n"; print $greeting;

perlapi functions that handle magic properly say so in the docs. I'd check out the source code for sv_catsv if you're looking for samples.

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

In reply to Re: XS and overload by creamygoodness
in thread XS and overload by BrowserUk

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.