Doesn't work properly with inheritance.
Subject: | coerce-breaks-inheritance.t |
use Test::More;
use Params::Coerce qw(coerce);
use URI;
{
package My::Link;
use Carp;
sub new {
my $class = shift;
my %args = @_;
defined $args{href} or croak("Need href");
defined $args{title} or $args{title} = $args{href};
bless \%args, $class;
}
sub __from_URI {
my $uri = shift;
__PACKAGE__->new( href => "$uri" );
}
}
my $uri = URI->new('http://www.example.com/');
my $link = coerce('My::Link', $uri);
isa_ok($uri, 'URI', '$uri');
isa_ok($link, 'My::Link', '$link');
done_testing;