Author image Stevan Little
and 1 contributors


Buffer::Transactional - A transactional buffer for writing data


  use IO::File;
  use Try::Tiny;
  use Buffer::Transactional;

  my $b = Buffer::Transactional->new( out => IO::File->new('my_novel.txt', 'w') );
  try {
      $b->print('It was the best of times, it was the worst of times ...');
      # ...
      die "Whoops!";
      # ...
  } catch {
      warn "Transaction aborted because : $_";


Allow me to take you on a journey, into the distant past ...

So a year or so ago I got really into the O'Caml language and in exploring the available libraries I stumbled onto OCamlnet. Ocamlnet is basically an all things internet related module for O'Caml. Of particular interest to me was their CGI module and one nice feature jumped out at me, which was the fact they used a transactional buffer to print the output of the CGI. Now, in a Modern Perl world few people probably call print inside a CGI script anymore, but instead use templating systems and the like. However I still thought that a nice transactional buffer would be useful for other things such as in the internals of such a templating system or the bowels of a web framework.

Fast forward to 2009 ... and here you have it! We support several different kind of buffer types as well as nested transactions. As this is the first release, no doubt there is much room for improvement so feel free to suggest away.

Use only as directed, be sure to check with your doctor to make sure your healthy enough for transactional activity. If your transaction lasts for more then 4 hours, consult a physician immediately.



This is an object which responds to the method print, most often it will be some kind of IO::File, IO::String or IO::Scalar varient. This attribute is required.


This is a class name for the buffer subclass you wish to use, it currently defaults to Buffer::Transactional::Buffer::String.



Declares the start of a transaction.


Commits the current transaction.


Rollsback the current transaction.

Print to the current buffer.

txn_do ( \&body )

This is a convience wrapper around the begin_work and commit methods. It takes a CODE ref and will execute it within the context of a transaction. It does not attempt to handle exceptions, rollbacks or anything of the like, it simply wraps the transaction.


OCamlnet -


All complex software has bugs lurking in it, and this module is no exception. If you find a bug please either email me, or add the bug to cpan-RT.


Stevan Little <>


Copyright 2009, 2010 Infinity Interactive, Inc.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.