Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Re: Re: Re: Re: Class::Interface -- isa() Considered Harmful

by MarkM (Curate)
on Jan 17, 2003 at 23:38 UTC ( [id://227864]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: Re: Re: Class::Interface -- isa() Considered Harmful
in thread Class::Interface -- isa() Considered Harmful

In your example, $h is not a tied hash. $h is a blessed reference to an object that is used to store data for the tied hash. The tied hash is %new_hash.

For a better example than the one you are presenting:

use Scalar::Util qw(reftype); tie(%hash, "ScalarHash"); function_that_expects_a_hash_reference(\%hash); sub function_that_expects_a_hash_reference { my($hash_ref) = @_; reftype($hash_ref) eq 'HASH' or die "CALLED WITHOUT A HASH REFERENCE!\n"; ... $hash_ref->{...} ... } package ScalarHash; sub TIEHASH { bless \(my $foo), $_[0] }

As I pointed out in the node that you were responding to, you are confusing Perl object interfaces (the ability to use a scalar as if it were a hash reference), and Perl blessed reference methods (the ability to use a particular method with an object).

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: Re: Class::Interface -- isa() Considered Harmful
by chromatic (Archbishop) on Jan 18, 2003 at 01:11 UTC

    Thanks; that particular behavior of tying had always confused me. You're right -- Scalar::Util::reftype() does what I want in this example.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (2)
As of 2024-04-20 06:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found