File: vmethods-fix-for-perl5.18

package info (click to toggle)
libtemplate-perl 2.24-1.2
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd, stretch
  • size: 8,676 kB
  • ctags: 1,427
  • sloc: perl: 14,535; makefile: 15; sh: 5
file content (84 lines) | stat: -rw-r--r-- 3,160 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
Description: apply fix from the upstream git to be compatible with Perl 5.18
 Rewrite split handling to use qr// which is consistent before and after
 the Perl 5.18.0 changes.
 
 In perldelta 5.18.0 it reads:
 
 split's first argument is more consistently interpreted
 
 After some changes earlier in v5.17, split's behavior has been
 simplified: if the PATTERN argument evaluates to a string containing
 one space, it is treated the way that a literal string containing
 one space once was.

 Also apply a fix to be backward compatible.

 from https://github.com/abw/Template2/commit/0caac1347e2e3f2fc290f0a4ffc0281b5df68abb
 and  https://github.com/abw/Template2/commit/5d732184712342cdb3750f52b03f8dcc3740b53d
 .
 libtemplate-perl (2.24-1.1) unstable; urgency=low
 .

Author: CSILLAG Tamas <cstamas@cstamas.hu>
Author: Andy Wardley <abw@wardley.org>
Origin: upstream, https://github.com/abw/Template2/commit/0caac1347e2e3f2fc290f0a4ffc0281b5df68abb https://github.com/abw/Template2/commit/5d732184712342cdb3750f52b03f8dcc3740b53d
Bug: https://rt.cpan.org/Public/Bug/Display.html?id=84778
Bug-Debian: http://bugs.debian.org/708025
Forwarded: https://rt.cpan.org/Public/Bug/Display.html?id=84778
Last-Update: 2013-08-17

--- libtemplate-perl-2.24.orig/lib/Template/VMethods.pm
+++ libtemplate-perl-2.24/lib/Template/VMethods.pm
@@ -254,21 +254,40 @@ sub text_split {
     my ($str, $split, $limit) = @_;
     $str = '' unless defined $str;
 
-    # we have to be very careful about spelling out each possible
-    # combination of arguments because split() is very sensitive
-    # to them, for example C<split(' ', ...)> behaves differently
-    # to C<$space=' '; split($space, ...)>
+    # For versions of Perl prior to 5.18 we have to be very careful about
+    # spelling out each possible combination of arguments because split()
+    # is very sensitive to them, for example C<split(' ', ...)> behaves
+    # differently to C<$space=' '; split($space, ...)>.  Test 33 of 
+    # vmethods/text.t depends on this behaviour.
 
-    if (defined $limit) {
-        return [ defined $split
-                 ? split($split, $str, $limit)
-                 : split(' ', $str, $limit) ];
+    if ($] < 5.018) {
+        if (defined $limit) {
+            return [ defined $split
+                     ? split($split, $str, $limit)
+                     : split(' ', $str, $limit) ];
+        }
+        else {
+            return [ defined $split
+                     ? split($split, $str)
+                     : split(' ', $str) ];
+        }
     }
-    else {
-        return [ defined $split
-                 ? split($split, $str)
-                 : split(' ', $str) ];
+
+    # split's behavior changed in Perl 5.18.0 making this:
+    # C<$space=' '; split($space, ...)>
+    # behave the same as this:
+    # C<split(' ', ...)>
+    # qr// behaves the same, so use that for user-defined split.
+
+    my $split_re;
+    if (defined $split) {
+        eval {
+            $split_re = qr/$split/;
+        };
     }
+    $split_re = ' ' unless defined $split_re;
+    $limit ||= 0;
+    return [split($split_re, $str, $limit)];
 }
 
 sub text_chunk {