6 unless (find PerlIO::Layer 'perlio') {
7 print "1..0 # Skip: not perlio\n";
11 if (($Config::Config{'extensions'} !~ m!\bPerlIO/scalar\b!) ){
12 print "1..0 # Skip -- Perl configured without PerlIO::scalar module\n";
22 open($fh,"+<",\$var) or print "not ";
25 print "not " unless eof($fh);
27 seek($fh,0,0) or print "not ";
28 print "not " if eof($fh);
31 print $fh "ok 7\n" or print "not ";
35 seek($fh,0,0) or print "not ";
36 print "not " if eof($fh);
38 print "not " unless <$fh> eq "foo\n";
42 print "# Close on scalar failed: $!\n";
47 # Test that semantics are similar to normal file-based I/O
48 # Check that ">" clobbers the scalar
51 print "# Got [$var], expect []\n";
52 print "not " unless $var eq "";
54 # Check that file offset set to beginning of scalar
56 print "# Got $off, expect 0\n";
57 print "not " unless $off == 0;
59 # Check that writes go where they should and update the offset
63 print "# Got $off, expect 4\n";
64 print "not " unless $off == 4;
66 print "# Got [$var], expect [Breathing]\n";
67 print "not " unless $var eq "Breathing";
71 # Check that ">>" appends to the scalar
73 open $fh, ">>", \$var;
75 print "# Got $off, expect 10\n";
76 print "not " unless $off == 10;
78 print "# Got [$var], expect [Something ]\n";
79 print "not " unless $var eq "Something ";
81 # Check that further writes go to the very end of the scalar
83 print "# Got [$var], expect [Something else ]\n";
84 print "not " unless $var eq "Something else ";
87 print "# Got $off, expect 10\n";
88 print "not " unless $off == 10;
91 print "# Got [$var], expect [Something else is here]\n";
92 print "not " unless $var eq "Something else is here";
96 # Check that updates to the scalar from elsewhere do not
98 $var = "line one\nline two\line three\n";
104 print "# Got [$var], expect [foo]\n";
105 print "not " unless $var eq "foo";
108 # Check that dup'ing the handle works
112 open $fh, "+>", \$var;
115 print $dup "ok 22\n";
123 # Check reading from non-string scalars
126 print <$fh> eq "42" ? "ok 23\n" : "not ok 23\n";
129 # reading from magic scalars
131 { package P; sub TIESCALAR {bless{}} sub FETCH {"ok 24\n"} }
132 tie $p, P; open $fh, '<', \$p;
135 # don't warn when writing to an undefined scalar
140 local $SIG{__WARN__} = sub { $ok = 0; };
141 open my $fh, '>', \my $scalar;
144 print $ok ? "ok 25\n" : "not ok 25\n";
147 my $data = "a non-empty PV";
149 open(MEM, '<', \$data) or die "Fail: $!\n";
150 my $x = join '', <MEM>;
151 print $x eq '' ? "ok 26\n" : "not ok 26\n";
154 # [perl #35929] verify that works with $/ (i.e. test PerlIOScalar_unread)
160 open(F, '<', \$s) or die "Could not open string as a file";
164 print $ln eq $s ? "ok 27\n" : "not ok 27\n";