in reply to Sub::Contract is_a inheritance problem

is_a doesn't check if the object is a descendant of the specified class.

sub is_a { croak "is_a() expects a package name" if (scalar @_ != 1 || !defined $_[0] || ref $_[0] ne ''); my $type = shift; return sub { return 0 if (!defined $_[0]); return (ref $_[0] eq $type) ? 1:0; }; }

So use is_a('mSomeObject_T') or make your own constraint.

use Scalar::Util qw( blessed ); sub is_or_extends { my ($type) = @_; croak "is_or_extends() expects a package name" if !defined($type) || ref($type) ne ''; return sub { return ( blessed($_[0]) ? $_[0]->isa($type) : UNIVERSAL::isa($_[0], $type) ); }; }

Replies are listed 'Best First'.
Re^2: Sub::Contract is_a inheritance problem
by grizzley (Chaplain) on Sep 09, 2008 at 10:30 UTC
    Works perfectly, thanks!