Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
To coin a phrase, a snippet is worth a thousand words...
package Foo; use overload qw("" stringify fallback 1 + zero); sub stringify { "overload.pm just ruined your day!" } sub zero { 0 } package main; my $foo1=bless {},'Foo'; my $foo2=bless {},'Foo'; sub same { "'$_[0]' is ".($_[0] eq $_[1] ? "the same as" : "different +to" )." '$_[1]'\n" }; print same(0+$foo1,0+$foo2); print same($foo1,$foo2); print same("$foo1","$foo2"); print same(overload::StrVal($foo1),overload::StrVal($foo2)); __END__ '0' is the same as '0' 'overload.pm just ruined your day!' is the same as 'overload.pm just r +uined your day!' 'overload.pm just ruined your day!' is the same as 'overload.pm just r +uined your day!' 'Foo=HASH(0x1acef84)' is different to 'Foo=HASH(0x1acf038)'
:-)

AFAIK, the _only_ non-xs way to reliably determine the underlying variable type and class of an overloaded object is to parse the results of overload::StrVal. Even then you get nowhere with reblessed qr// objects. (Which still act as regexes at the same time.)

Frankly the fact that perl completely lacks any reliable native perl way of doing type introspection is IMO one of its few serious failings. (And no, at least some of the problems do not go away with Scalar::Utils and List::Utils.)

--- demerphq
my friends call me, usually because I'm late....


In reply to Re: Re: Re: How can I find the calling object? by demerphq
in thread How can I find the calling object? by strider corinth

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (7)
As of 2024-04-23 12:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found