Title: RE: RFC: Set::Partition

> -----Original Message-----
> From: David Landgren [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, May 24, 2006 10:53 AM
> To: Ken Williams
> Cc: Xavier Noria; Module Authors
> Subject: Re: RFC: Set::Partition
>
>
> Ken Williams wrote:
>
> [...]
>
> > BTW, Xavier & David both: The proposed interface for
> enumerating the set
> > partitions uses array refs, but sets in perl are more naturally
> > represented using hashes.  I'd suggest re-implementing in terms of
> > hashes, or perhaps giving it a complete-enough OO interface
> that hides
> > the actual implementation structure.
>
> My first thought was "well, just pass in the hash keys as the list".
>
> Then I thought that that pushes a whole lot of make work code
> back onto
> the client to reconstruct the subset hashes. So yes, you have a valid
> point. It would be fairly trivial for me to stash the hash,
> and give the
> clients what they want.
>
> This would also explain why I named the module Set::Partition and not
> List::Partition :)
>
> All I would need to do is if (ref($in) eq 'HASH'), and take it from
> there ... but my eyes have glazed over during the recent isa
> threads, so
> I'm not sure what the current best practice is to detect a
> blessed hash.

The generally agreed best practice is to

  use Scalar::Util qw(reftype blessed);

  if ((reftype($obj)||"") eq 'HASH' and defined blessed $obj) {
  }

Unfortunatly Scalar::Util::reftype() doesn't have a very well thought out API so the ||"" stuff (or worse) is necessary.

Cheers,
Yves

Reply via email to