Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Is reference blessed?

by brycen (Monk)
on Mar 26, 2010 at 02:23 UTC ( #831017=note: print w/replies, xml ) Need Help??


in reply to Is reference blessed?

Answering the 2nd half of the question, nine years late:
# We want the true type of blessed objects like XML::DOM::Document my $true_type; if(ref($value)) { $true_type = scalar($value); $true_type =~ s/.*=(\w*).*/$1/; } print ref($value)," is really an $true_type\n";
XML::DOM::Document is really an ARRAY
That's ugly. It takes the scalar value of the reference, which just happens to show both the blessed type and the native type. But it works.

Replies are listed 'Best First'.
Re^2: Is reference blessed?
by ikegami (Patriarch) on Mar 26, 2010 at 04:26 UTC

    No, that doesn't work.

    { package Foo; use overload '""' => sub { 'Bar' }; sub new { bless({}, shift) } } { my $value = Foo->new; # We want the true type of blessed objects like XML::DOM::Document my $true_type; if(ref($value)) { $true_type = scalar($value); $true_type =~ s/.*=(\w*).*/$1/; } print ref($value)," is really an $true_type\n"; }
    Foo is really an Bar

    But it's really a hash.

    Scalar::Util's blessed, reftype and refaddr provide the desired $class, $type and $addr respectively.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (6)
As of 2022-12-05 09:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?