In perl.git, the branch blead has been updated <http://perl5.git.perl.org/perl.git/commitdiff/abf6c2ea2366391df6e7478b6e9cd5ca21c69249?hp=9a7d94ef19fc170c3cac472a31f467828efc1cd4>
- Log ----------------------------------------------------------------- commit abf6c2ea2366391df6e7478b6e9cd5ca21c69249 Merge: 9a7d94e... 532217f... Author: Rafael Garcia-Suarez <[email protected]> Date: Tue Jun 2 08:47:54 2009 +0200 Merge branch 'smartmatch' into blead ----------------------------------------------------------------------- Summary of changes: pod/perl5110delta.pod | 17 ++++++++++++----- pod/perlsyn.pod | 5 ++--- t/op/smartmatch.t | 12 ++++++++++-- 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/pod/perl5110delta.pod b/pod/perl5110delta.pod index 54292e0..ea62b67 100644 --- a/pod/perl5110delta.pod +++ b/pod/perl5110delta.pod @@ -42,8 +42,9 @@ of the switch statements where smart matching is implicitly used. The smart match operator C<~~> is no longer commutative. The behaviour of a smart match now depends primarily on the type of its right hand -argument. While the general backwards compatibility is maintained, -several changes must be noted: +argument. Moreover, its semantics has been adjusted for greater +consistency or usefulness in several cases. While the general backwards +compatibility is maintained, several changes must be noted: =over 4 @@ -62,6 +63,12 @@ the subroutine. =item * +Due to the commutativity breakage, code references are no longer +treated specially when appearing on the left of the C<~~> operator, +but like any vulgar scalar. + +=item * + C<undef ~~ %hash> is always false (since C<undef> can't be a key in a hash). No implicit conversion to C<""> is done (as was the case in perl 5.10.0). @@ -88,9 +95,9 @@ appear on the left, the overload routine will be called only when the rightmost argument is a simple scalar. This way distributivity of smart match across arrays is not broken, as well as the other behaviours with complex types (coderefs, hashes, regexes). Thus, writers of overloading routines -for smart match need to worry only with comparing against a scalar, and -possibly with stringification overloading; the other cases will be -automatically handled consistently. +for smart match mostly need to worry only with comparing against a scalar, +and possibly with stringification overloading; the other common cases +will be automatically handled consistently. C<~~> will now refuse to work on objects that do not overload it (in order to avoid relying on the object's underlying structure). diff --git a/pod/perlsyn.pod b/pod/perlsyn.pod index b4eff36..2ba30d8 100644 --- a/pod/perlsyn.pod +++ b/pod/perlsyn.pod @@ -688,13 +688,13 @@ that applies determines the match behaviour (which is thus mostly determined by the type of the right operand). Note that the smart match implicitly dereferences any non-blessed hash or array ref, so the "Hash" and "Array" entries apply in those cases. (For blessed references, the -"Any" entry apply.) +"Object" entries apply.) $a $b Type of Match Implied Matching Code ====== ===== ===================== ============= Any undef undefined !defined $a - Any Object invokes ~~ overloading on $object, or dies + Any Object invokes ~~ overloading on $object, or dies Hash CodeRef sub truth for each key[1] !grep { !$b->($_) } keys %$a Array CodeRef sub truth for each elt[1] !grep { !$b->($_) } @$a @@ -722,7 +722,6 @@ and "Array" entries apply in those cases. (For blessed references, the Num numish[4] numeric equality $a == $b Any Any string equality $a eq $b - 1 - empty hashes or arrays will match. 2 - that is, each element smart-matches the element of same index in the other array. [3] diff --git a/t/op/smartmatch.t b/t/op/smartmatch.t index 8c48768..9df7357 100644 --- a/t/op/smartmatch.t +++ b/t/op/smartmatch.t @@ -62,7 +62,7 @@ my %keyandmore = map { $_ => 0 } @keyandmore; my %fooormore = map { $_ => 0 } @fooormore; # Load and run the tests -plan "no_plan"; +plan tests => 294; while (<DATA>) { next if /^#/ || !/\S/; @@ -168,6 +168,10 @@ __DATA__ ! \&fatal $ov_obj 'cigam' $ov_obj ! 'cigam on' $ov_obj +! ['cigam'] $ov_obj +! ['stringified'] $ov_obj +! { cigam => 1 } $ov_obj +! { stringified => 1 } $ov_obj ! $obj $ov_obj ! undef $ov_obj @@ -191,7 +195,8 @@ __DATA__ # object (overloaded or not) ~~ Any $obj qr/NoOverload/ $ov_obj qr/^stringified$/ - "$ov_obj" "stringified" += "$ov_obj" "stringified" +!= $ov_obj "stringified" $ov_obj 'magic' ! $ov_obj 'not magic' @@ -248,6 +253,9 @@ __DATA__ +{} \&fatal @empty \&fatal %empty \&fatal +# sub is not special on the left + sub {0} qr/^CODE/ + sub {0} sub { ref shift eq "CODE" } # HASH ref against: # - another hash ref -- Perl5 Master Repository
