Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: isa() on any scalar

by gam3 (Curate)
on Jun 11, 2005 at 02:37 UTC ( [id://465739]=note: print w/replies, xml ) Need Help??


in reply to isa() on any scalar

You can use Scalar::Util::blessed to test the reference
use Scalar::Util qw (blessed); if (blessed($value) and $value->isa('Node')) { # }
-- gam3
A picture is worth a thousand words, but takes 200K.

Replies are listed 'Best First'.
Re^2: isa() on any scalar
by rvosa (Curate) on Jun 11, 2005 at 20:41 UTC
    Two things: i) are you building an OO module for phylogenetics? (If yes, let's join forces); ii) here's how I did it:
    sub parent { my $self = $_[0]; if ( $_[1] ) { my $parent = $_[1]; if ( $parent->can('parent') ) { $self->[PARENT] = $parent; } else { my $ref = ref $self; carp "parents can only be $ref objects"; return; } } return $self->[PARENT]; }
    This follows the "if it walks like a duck" paradigm. Not saying that this is the best way to do it, but it works for me.

      Phylogeny: (n.)
      1. The evolutionary development and history of a species or higher taxonomic grouping of organisms. Also called phylogenesis.
      2. The evolutionary development of an organ or other part of an organism: the phylogeny of the amphibian intestinal tract.
      3. The historical development of a tribe or racial group.

      Okay, just looked it up... nope, that's not what I'm doing at all. Sorry! Thanks for the piece of code though!

          -Bryan

Re^2: isa() on any scalar
by mrborisguy (Hermit) on Jun 13, 2005 at 03:18 UTC

    After looking around, trying to figure out what I want to do, I decided to use the 'walk like a duck' approach and use can. However, the same problem occured! So I use this solution together with can. Thanks for this one!

    use Scalar::Util qw(blessed); if ( blessed( $value ) and $value->can( 'parent' ) ) { # }

        -Bryan

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2024-04-20 00:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found