Puma
P e r l   U n i v e r s a l   M a r k u p   D o c u m e n t a t i o n
SourceForge.net Logo

Puma::Util::Buffer
Captures STDOUT into a Perl scalar variable for any evaluated chunk of code.
   use Puma::Util::Buffer;

   my $foo = new Puma::Util::Buffer;
   $foo->startCapture;
   print 'This example uses startCapture and endCapture';
   my $footext = $foo->endCapture();
   print "footext =\n\t$footext\n\n";

   my $bar = new Puma::Util::Buffer;
   my $bartext = $bar->capture(
      sub {
         print "This example uses the 'capture' method";
      }
   );
   print "bartext =\n\t$bartext\n\n";
The above example shows the two ways that output can be captured. The first uses the startCapture() and endCapture() methods to capture the output of all the code executed between the two methods. The second portion of the example uses the capture() method to capture the output of a subroutine reference passed to it.