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

Reply via email to