Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^2: Can I ask Perl if an object will stringify?

by haukex (Archbishop)
on May 25, 2015 at 10:36 UTC ( [id://1127673]=note: print w/replies, xml ) Need Help??


in reply to Re: Can I ask Perl if an object will stringify?
in thread Can I ask Perl if an object will stringify?

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1127673]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (5)
As of 2024-04-18 11:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found