The question needs changing. Both versions of is_deeply will give the same answer on these tests. I was going to say:
What you need is package MyOtherString; use overload '""' => sub { shift->[0] }, fallback => 1; sub new { my ($class, $val) = @_; bless [ $val ], $class; } But actually both versions will still give the identical answers except this time they will both say the opposite of what they said for the original tests, F On Tuesday 09 September 2003 10:52, Tony Bowden wrote: > There's been a protracted discussion on the code-review mailing list > about the behaviour of is_deeply in Test::More, which really belongs > here or p5p. > > For the most part it was sparked by a disagreement about what should > happen when comparing overloaded objects (but also then impacts on tied > objects), but has become a more philosophical question about the nature > of deepness :) > > I won't bore everyone with the details, but I would like to carry out > a pop quiz. > > Consider the following two classes: > > package MyString; > use overload > '""' => sub { shift->{value} }, > fallback => 1; > > sub new { > my ($class, $val) = @_; > bless { value => $val }, $class; > } > > and > > package MyOtherString; > > use base 'MyString'; > > Now consider two objects of those classes: > > my $str1 = MyString->new("Cat"); > my $str2 = MyOtherString->new("Cat"); > > We now have two objects which overload to the string "Cat". > > So, should the following tests pass or fail? > > 1) ok $str1 eq $str2; > 2) is $str1, $str2; > 3) is_deeply [$str1], [$str2]; > 4) is_deeply $str1, $str2; > > > Tony > >