Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

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

by ribasushi (Pilgrim)
on Apr 01, 2015 at 08:15 UTC ( #1122099=note: print w/replies, xml ) Need Help??


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

Strange that nobody brought up Devel::OverloadInfo. It will do exactly what you need (unless I misunderstood your question).
  • Comment on Re: Can I ask Perl if an object will stringify?

Replies are listed 'Best First'.
Re^2: Can I ask Perl if an object will stringify?
by LanX (Cardinal) on Apr 01, 2015 at 10:19 UTC
    > Strange that nobody brought up ...

    Because nobody compares to you, you son of a rabbit. ;)

    Thanks++ :)

    Cheers Rolf
    (addicted to the Perl Programming Language and ☆☆☆☆ :)

    PS: Je suis Charlie!

Re^2: Can I ask Perl if an object will stringify?
by haukex (Bishop) on May 25, 2015 at 10:36 UTC

    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
Node Status?
node history
Node Type: note [id://1122099]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (6)
As of 2020-10-31 05:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (286 votes). Check out past polls.

    Notices?