Permalink
Browse files

Document CHECK_PRINT and include an example.

  • Loading branch information...
1 parent 360ecba commit 302a10e33b60978906fa8f5a7c455c35d2156dff @josephw committed Mar 29, 2010
Showing with 41 additions and 0 deletions.
  1. +6 −0 XML/Writer.pm
  2. +35 −0 XML/examples/check-print.pl
View
@@ -1322,6 +1322,12 @@ A character encoding; currently this must be one of 'utf-8' or 'us-ascii'.
If present, it will be used for the underlying character encoding and as the
default in the XML declaration.
+=item CHECK_PRINT
+
+A true or false value; if this parameter is present and its value is
+true, all prints to the underlying output will be checked for success. Errors
+will cause a croak.
+
=back
=item end()
@@ -0,0 +1,35 @@
+#!/usr/bin/perl -w
+
+# Demonstrate CHECK_PRINT to catch output failures
+
+use strict;
+
+use XML::Writer;
+
+my $output;
+
+print "Open a file handle where all writes will fail.\n";
+
+# A file handle where all writes will fail immediately
+open($output, '>:unix', '/dev/full') or die "Unable to open output file: $!";
+
+my $writer;
+
+print "Writing without CHECK_PRINT will appear to succeed...\n";
+
+$writer = new XML::Writer(OUTPUT => $output);
+$writer->emptyTag('document');
+$writer->end();
+
+print "...no errors.\n";
+
+
+print "With CHECK_PRINT the write failure causes a croak...\n";
+
+$writer = new XML::Writer(OUTPUT => $output, CHECK_PRINT => 1);
+$writer->emptyTag('document');
+$writer->end();
+
+print "...this shouldn't happen!\n";
+
+close($output) or die "Failed to close output file: $!";

0 comments on commit 302a10e

Please sign in to comment.