Skip Menu |

This queue is for tickets about the Params-Coerce CPAN distribution.

Report information
The Basics
Id: 121552
Status: new
Priority: 0/
Queue: Params-Coerce

People
Owner: Nobody in particular
Requestors: perl [...] toby.ink
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in:
  • 0.08
  • 0.09
  • 0.11
  • 0.12
  • 0.13
  • 0.14
Fixed in: (no value)



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;
This happens because $uri is blessed into the URI::http package, which inherits from URI. This could be fixed by using the mro module to loop through the packages $uri inherits from, and finding the first appropriate __from_X function in My::Link.