1use strict; 2use FileHandle::Unget; 3use File::Spec::Functions qw(:ALL); 4use Test::More tests => 7; 5use File::Temp; 6 7my $tmp = File::Temp->new(); 8 9{ 10 print $tmp "first line\n"; 11 print $tmp "second line\n"; 12 print $tmp "third line\n"; 13 close $tmp; 14} 15 16# Test normal semantics for input record separators 17{ 18 my $fh1 = new FileHandle::Unget($tmp->filename); 19 20 local $/ = "\n"; 21 my $line1 = <$fh1>; 22 23 # 1 24 is($line1, "first line\n", 'First line'); 25 26 local $/ = undef; 27 my $line2 = <$fh1>; 28 29 # 2 30 is($line2, "second line\nthird line\n", 'No eol separator'); 31 32 $fh1->close; 33} 34 35# Test per-filehandle input record separator for 1 filehandle 36{ 37 my $fh1 = new FileHandle::Unget($tmp->filename); 38 39 local $/ = "\n"; 40 my $line1 = <$fh1>; 41 42 # 3 43 is($line1, "first line\n", 'First line'); 44 45 $fh1->input_record_separator("\n"); 46 47 local $/ = undef; 48 my $line2 = <$fh1>; 49 50 # 4 51 is($line2, "second line\n", 'Second line'); 52 53 $fh1->ungets($line2); 54 $fh1->clear_input_record_separator(); 55 my $line3 = <$fh1>; 56 57 #5 58 is($line3, "second line\nthird line\n", 'Newline end of file'); 59 60 $fh1->close; 61} 62 63 64# Test per-filehandle input record separator for 2 filehandles 65{ 66 my $fh1 = new FileHandle::Unget($tmp->filename); 67 my $fh2 = new FileHandle::Unget($tmp->filename); 68 69 local $/ = ' '; 70 71 $fh1->input_record_separator("\n"); 72 $fh2->input_record_separator(undef); 73 74 my $line1 = <$fh1>; 75 my $line2 = <$fh2>; 76 77 # 6 78 is($line1, "first line\n", 'First line'); 79 # 7 80 is($line2, "first line\nsecond line\nthird line\n", 'Undef end of line'); 81 82 $fh1->close; 83 $fh2->close; 84} 85 86