On Fri, 18 Mar 2011 10:19:31 +0000, William Bellamy Bellamy 
<[email protected]> wrote:
> subtype 'IxHash' 
>     => as 'HashRef' 
>     => where { 
>         ref $_ eq 'HASH' 
> };
> 
> coerce 'IxHash'
> => from 'HashRef'
> => via { 
>     tie (%$_,'Tie::IxHash') unless tied $_; return $_; 
>     
> };

Your subtype does nothing.  It needs to be more restrictive than HashRef if you
want coercions from HashRef to ever fire, and it isn't.

An example:

  subtype 'IxHash', as 'HashRef', 
    where { tied $_ and (tied $_)->isa('Tie::IxHash') };

  coerce 'IxHash', from 'HashRef',
    via { my %h = %$_; tie %h, 'Tie::IxHash'; return \%h };

(You probably don't want to tie the passed-in hash reference.)

hdp.

Reply via email to