Hi ribasushi,

Thanks for the suggestion! I tried it out, and the module returns a bit more information than overload::Method(), but unless I missed something it unfortunately doesn't seem to directly answer the question whether an object will stringify via magic autogeneration or not, but I could probably figure it out based on all the information it returns. Here's an example of what the overload_info() function returns for two of my test classes from the original post:

# this class stringifies even though "" is not directly overloaded { "0+" => { class => "ICanStringify", code => sub { ... }, code_name => "ICanStringify::__ANON__", }, "fallback" => { class => "ICanStringify", value => undef }, } # this class does not stringify { "0+" => { class => "OnlyANumber", code => sub { ... }, code_name => "OnlyANumber::__ANON__", }, "fallback" => { class => "OnlyANumber", value => 0 }, }

Right now my current solution (posted below) of "just try it out" seems to work, so I'm a bit hesitant to change it except in a way that would simplify it. I'll look into it a bit more whether I can do so with the above info.

Thanks and Regards,
-- Hauke D


In reply to Re^2: Can I ask Perl if an object will stringify? by haukex
in thread Can I ask Perl if an object will stringify? by haukex

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.