diff -ru File-Slurp-9999.12-orig/lib/File/Slurp.pm File-Slurp-9999.12/lib/File/Slurp.pm
--- File-Slurp-9999.12-orig/lib/File/Slurp.pm 2006-02-17 07:13:51.000000000 +0100
+++ File-Slurp-9999.12/lib/File/Slurp.pm 2007-06-12 10:51:25.953969291 +0200
@@ -6,6 +6,7 @@
use POSIX qw( :fcntl_h ) ;
use Fcntl qw( :DEFAULT ) ;
use Symbol ;
+BEGIN { eval 'use UNIVERSAL::isa' }
my $is_win32 = $^O =~ /win32/i ;
@@ -85,7 +86,7 @@
# check if we are reading from a handle (glob ref or IO:: object)
- if ( ref $file_name ) {
+ if ( ref $file_name && (UNIVERSAL::isa($file_name, 'GLOB') || UNIVERSAL::isa($file_name, 'IO')) ) {
# slurping a handle so use it and don't open anything.
# set the block size so we know it is a handle and read that amount
@@ -195,15 +196,34 @@
# this split doesn't work since it tries to use variable length lookbehind
# the m// line works.
# return [ split( m|(?<=$sep)|, ${$buf_ref} ) ] if $args{'array_ref'} ;
- return [ length(${$buf_ref}) ? ${$buf_ref} =~ /(.*?$sep|.+)/sg : () ]
- if $args{'array_ref'} ;
+# return [ length(${$buf_ref}) ? ${$buf_ref} =~ /(.*?$sep|.+)/sg : () ]
+# if $args{'array_ref'} ;
# caller wants a list of lines (normal list context)
# same problem with this split as before.
# return split( m|(?<=$sep)|, ${$buf_ref} ) if wantarray ;
- return length(${$buf_ref}) ? ${$buf_ref} =~ /(.*?$sep|.+)/sg : ()
- if wantarray ;
+# return length(${$buf_ref}) ? ${$buf_ref} =~ /(.*?$sep|.+)/sg : ()
+# if wantarray ;
+ if (wantarray || $args{'array_ref'}) {
+ # split the text on the end-of-line separator
+ my @lines = split /($sep)/, ${$buf_ref};
+
+ # reconstruct the full lines by merging items by pairs
+ for my $k (0..int($#lines/2)) {
+ my $i = $k * 2;
+ $lines[$k] = (defined $lines[$i] ? $lines[$i] : '')
+ . (defined $lines[$i+1] ? $lines[$i+1] : '');
+ }
+
+ # remove the rest of the items
+ splice(@lines, int($#lines/2)+1);
+ pop @lines unless $lines[-1];
+
+ # return as array of arrayref
+ return $args{'array_ref'} ? \@lines : @lines
+ }
+
# caller wants a scalar ref to the slurped text