http://qs1969.pair.com?node_id=831017


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.