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 {
