G'day Rafael / p5p,
For autodie, hints.t is fixed in my git repository. Those tests were
failing due to a restructure of File::Copy, and the new tests handle these
correctly. Of more interest, is:
Paul Fenwick wrote:
> Rafael Garcia-Suarez wrote:>> ../lib/autodie/t/hints_pod_examples.t (Wstat: 1280 Tests: 80 Failed: 5)>> Failed tests: 5, 14, 21, 37, 60>> Non-zero exit status: 5> > These look like they're the results of smart-match changes. I'm going to> have to dig deeper to see what's going on here. Investigating now.These all seem to relate to how 5.10.1 smart-match handles undef. In
particular:
undef ~~ 0; # True! (undef is coerced to 0)
undef ~~ ""; # True! (undef is coerced to "")
Consequently, this also means the following prints "I've got a zero".
my $x = undef;
given ($x) {
when (0) { say "I've got a zero!" } # printed
default { say "I've got something else" }
}
This means that for 5.10.1, any given/when block is going to need a separate
case for undef before any string/numeric tests if we want to avoid treating
it like 0/"". I don't know about everyone else, but I *never* want to treat
undef as if it's defined. If I did, I have now have the new // (defined-or)
operator to make that easy. As such, it's a *big* surprise to have
smart-match go coercing undef so readily.
When comparing scalars, to me it makes the most sense to have undef only
smart-match against itself. It certainly means I can have more succinct
given/when blocks, and less coercion warnings.
I'm also a little perplexed because:
undef ~~ 0 # True
undef ~~ [0] # False!
Here no coercion is happening when comparing against an array reference! My
understanding (after consulting the docs) is that the smart-match is
distributed over the array elements in the form `$_ ~~ $a`, resulting in the
undef on the RHS. But then I'd expect `0 ~~ [undef]` to distribute to
`undef ~~ 0`, which then coerces undef to be a number, and hence be true,
but it's not... So coercion only happens when comparing two scalars? I'm
confused.
Unfortunately, this means that the new smart-matches don't fit into my head;
at least not these bits of it. Using the principle of least surprise (to
pjf), I'd like to see:
undef ~~ undef # True
0 ~~ undef # False
undef ~~ 0 # False (currently true)
[undef] ~~ undef # True (currently false!)
undef ~~ [undef] # True
0 ~~ [undef] # False
[undef] ~~ 0 # False
I'm really sorry to be bringing up smart-match again. Really, really sorry.
I don't want to start another long thread about how it should/shouldn't
work, but I fear I'm not going to be able to sleep soundly until I finally
grok it (or it groks me).
All the best,
Paul
--
Paul Fenwick <pjf@perltraining.com.au> | http://perltraining.com.au/
Director of Training | Ph: +61 3 9354 6001
Perl Training Australia | Fax: +61 3 9354 2681