No, I am very much not looking for Scalar::Util::reftype, thought it could indeed replace UNIVERSAL::isa. It still dictates implementation, which is what I'm trying to avoid.
I'm not expecting to rummage around in the internals of an object passed as $args. I'm expecting to deal with something that behaves as a hash. If it's a hash, fine. If it's a tied hash, it ought to work fine too.
Unfortunately, it doesn't:
#!/usr/bin/perl -w use strict; use Scalar::Util 'reftype'; use Tie::Hash; foreach my $package (qw( Scalar Array Code )) { my $h = tie my %new_hash, $package . 'Hash'; print "Tied $h as a hash based on $package\n"; print 'It is ' . (UNIVERSAL::isa( $h, 'HASH' ) ? '' : 'not ') . "a + HASH\n"; print 'Its reftype is ' . reftype( $h ) . "\n"; } package ScalarHash; sub TIEHASH { bless \(my $foo), $_[0] } package ArrayHash; sub TIEHASH { bless [], $_[0] } package CodeHash; sub TIEHASH { bless sub {}, $_[0] }
In reply to Re: Re: Re: Re: Class::Interface -- isa() Considered Harmful
by chromatic
in thread Class::Interface -- isa() Considered Harmful
by chromatic
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |