This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
File tests were already treated as boolean in when()
[perl5.git] / pod / perl5110delta.pod
CommitLineData
7120b314
NC
1=head1 NAME
2
3perldelta - what is new for perl v5.11.0
4
5=head1 DESCRIPTION
6
7This document describes differences between the 5.10.0 and the 5.11.0
9948897e 8development releases.
7120b314
NC
9
10=head1 Incompatible Changes
11
8b8da387
RGS
12=head2 Switch statement changes
13
14The handling of complex expressions by the C<given>/C<when> switch
1710b4c0 15statement has been enhanced. There are two new cases where C<when> now
8b8da387
RGS
16inteprets its argument as a boolean, instead of an expression to be used
17in a smart match:
18
19=over 4
20
8b8da387
RGS
21=item flip-flop operators
22
23The C<..> and C<...> flip-flop operators are evaluated in boolean context,
24following their usual semantics; see L<perlop/"Range Operators">.
25
26=item defined-or operator
27
28A compound expression involving the defined-or operator, as in
29C<when (expr1 // expr2)>, will be treated as boolean if the first
30expression is boolean. (This just extends the existing rule that applies
31to the regular or operator, as in C<when (expr1 || expr2)>.)
32
33=back
34
35The next paragraph details more changes brought to the semantics to
36the smart match operator, that naturally also modify the behaviour
37of the switch statements where smart matching is implicitly used.
38
39=head2 Smart match changes
40
41=head3 Changes to type-based dispatch
42
43The smart match operator C<~~> is no longer commutative. The behaviour of
44a smart match now depends primarily on the type of its right hand
45argument. While the general backwards compatibility is maintained,
46several changes must be noted:
47
48=over 4
49
50=item *
51
52Code references with an empty prototype are no longer treated specially.
53They are passed an argument like the other code references (even if they
54choose to ignore it).
55
56=item *
57
58C<%hash ~~ sub {}> and C<@array ~~ sub {}> now test that the subroutine
59returns a true value for each key of the hash (resp. element of the
60array), instead of passing the whole hash or array as a reference to
61the subroutine.
62
63=item *
64
65C<undef ~~ %hash> is always false (since C<undef> can't be a key in a
66hash). No implicit conversion to C<""> is done (as was the case in perl
675.10.0).
68
69=item *
70
71C<$scalar ~~ @array> now always distributes the smart match across the
72elements of the array. It's true if one element in @array verifies
73C<$scalar ~~ $element>. This is a generalization of the old behaviour
74that tested whether the array contained the scalar.
75
76=back
77
78The full dispatch table for the smart match operator is given in
79L<perlsyn/"Smart matching in detail">.
80
81=head3 Smart match and overloading
82
83According to the rule of dispatch based on the rightmost argument type,
84when an object overloading C<~~> appears on the right side of the
85operator, the overload routine will always be called (with a 3rd argument
86set to a true value, see L<overload>.) However, when the object will
87appear on the left, the overload routine will be called only when the
88rightmost argument is a scalar. This way distributivity of smart match
89across arrays is not broken, as well as the other behaviours with complex
90types (coderefs, hashes, regexes). Thus, writers of overloading routines
91for smart match need to worry only with comparing against a scalar, and
92possibly with stringification overloading; the other cases will be
93automatically handled consistently.
94
95C<~~> will now refuse to work on objects that do not overload it (in order
96to avoid relying on the object's underlying structure).
97
7120b314
NC
98=head1 Core Enhancements
99
1839a850
RGS
100=head1 The C<overloading> pragma
101
102This pragma allows you to lexically disable or enable overloading
103for some or all operations. (Yuval Kogman)
104
7120b314
NC
105=head1 Modules and Pragmata
106
1839a850
RGS
107=head2 Pragmata Changes
108
109=over 4
110
111=item C<overloading>
112
113See L</"The C<overloading> pragma"> above.
114
115=back
116
7120b314
NC
117=head1 Utility Changes
118
119=head1 Documentation
120
121=head1 Performance Enhancements
122
123=head1 Installation and Configuration Improvements
124
125=head1 Selected Bug Fixes
126
54ad55c5
RGS
127=over 4
128
129=item C<-I> on shebang line now adds directories in front of @INC
130
131as documented, and as does C<-I> when specified on the command-line.
132(Renée Bäcker)
133
134=back
135
7120b314
NC
136=head1 New or Changed Diagnostics
137
138=head1 Changed Internals
139
140=head1 Known Problems
141
142=head2 Platform Specific Problems
143
144=head1 Reporting Bugs
145
146If you find what you think is a bug, you might check the articles
147recently posted to the comp.lang.perl.misc newsgroup and the perl
148bug database at http://bugs.perl.org/ . There may also be
149information at http://www.perl.org/ , the Perl Home Page.
150
151If you believe you have an unreported bug, please run the B<perlbug>
152program included with your release. Be sure to trim your bug down
153to a tiny but sufficient test case. Your bug report, along with the
154output of C<perl -V>, will be sent off to perlbug@perl.org to be
155analysed by the Perl porting team.
156
157=head1 SEE ALSO
158
159The F<Changes> file for exhaustive details on what changed.
160
161The F<INSTALL> file for how to build Perl.
162
163The F<README> file for general stuff.
164
165The F<Artistic> and F<Copying> files for copyright information.
166
167=cut