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

Re: Is reference blessed?

by brycen (Monk)
on Mar 26, 2010 at 02:23 UTC ( [id://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?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (2)
As of 2024-04-26 05:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found