Daisuke Murase > Data-TxnBuffer > Data::TxnBuffer



Annotate this POD

View/Report Bugs
Module Version: 0.05   Source  




    use Data::TxnBuffer;
    # create buffer
    my $buf = Data::TxnBuffer->new;
    # or create buffer from some data
    # read some data
    use Try::Tiny;
    try {
    } catch {
    try {
        $buf->txn_read(sub {
    } catch {
        # try again later
    # write some data to filehandle or buffer
    $buf->write("Hello World");
    # got written data
    my $data = $buf->data;
    # clear all data from buffer



XS implementation ^

This module use XS implementation by default, but fallback to ::PP implementation in pure perl environment or PERL_ONLY environment variable is set.

XS implementation is several times faster than PP implementation.






Return buffer read cursor point. This value increase by read methods automatically and reset to 0 by reset method.


Return buffer's whole data.


Return buffer's data length. (bytes)





Write $data into buffer.


    $buf->spin; # clear only foo
    $buf->data; # == 'bar'


And also, this method returns cleared data. For example $buf->spin in above example returns 'foo';


Reset read cursor to 0.


Clear all data from buffer.


By combination of read, spin, and reset methods, you can read some data like transaction:

    use Try::Tiny;
    try {
    } catch {



Shortcut method for above transaction read example.

    use Try::Tiny;
    try {
        $buf->txn_read(sub {
        # spin automatically called
    } catch {
        # reset automatically called
        # try later

This method automatically call spin method and returns spin'ed data if all data successfully read, or throw exception not enough data in buffer and call reset method automatically. This method is very useful for typical transaction read functions.


This module provides not only basic read($bytes) method but also useful methods to read integer values easily.





Read unsigned integers. uXX is bit length. (ex: u32 is 32bit unsigned int)





Read singed integers.





Write unsigned integers





Write signed integers








Read/Write unsigned integers in network byte order.







Daisuke Murase <typester@cpan.org>


Copyright (c) 2011 by KAYAC Inc.



syntax highlighting: