Get PerlIO::scalar to write to COWs
authorFather Chrysostomos <sprout@cpan.org>
Sun, 5 Jun 2011 02:01:59 +0000 (19:01 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Sun, 5 Jun 2011 02:01:59 +0000 (19:01 -0700)
ext/PerlIO-scalar/scalar.pm
ext/PerlIO-scalar/scalar.xs
ext/PerlIO-scalar/t/scalar.t

index 45f2119..a5fab72 100644 (file)
@@ -1,5 +1,5 @@
 package PerlIO::scalar;
-our $VERSION = '0.11';
+our $VERSION = '0.12';
 require XSLoader;
 XSLoader::load();
 1;
index b6cc5c1..de98738 100644 (file)
@@ -24,7 +24,8 @@ PerlIOScalar_pushed(pTHX_ PerlIO * f, const char *mode, SV * arg,
      */
     if (arg && SvOK(arg)) {
        if (SvROK(arg)) {
-           if (SvREADONLY(SvRV(arg)) && mode && *mode != 'r') {
+           if (SvREADONLY(SvRV(arg)) && !SvIsCOW(SvRV(arg))
+            && mode && *mode != 'r') {
                if (ckWARN(WARN_LAYER))
                    Perl_warner(aTHX_ packWARN(WARN_LAYER), "%s", PL_no_modify);
                SETERRNO(EINVAL, SS_IVCHAN);
index 1aee4b0..ed1ae69 100644 (file)
@@ -16,7 +16,7 @@ use Fcntl qw(SEEK_SET SEEK_CUR SEEK_END); # Not 0, 1, 2 everywhere.
 
 $| = 1;
 
-use Test::More tests => 70;
+use Test::More tests => 71;
 
 my $fh;
 my $var = "aaa\n";
@@ -284,3 +284,11 @@ EOF
     is read($strIn, my $buffer, 5), 0,
      'seek beyond end end of string followed by read';
 }
+
+# Writing to COW scalars
+{
+    my $bovid = __PACKAGE__;
+    open my $handel, ">", \$bovid;
+    print $handel "the COW with the crumpled horn";
+    is $bovid, "the COW with the crumpled horn", 'writing to COW scalars';
+}