Buffer::Transactional::Buffer::File - A file based buffer


Buffer-Transactional documentation Contained in the Buffer-Transactional distribution.

Index


Code Index:

NAME

Top

Buffer::Transactional::Buffer::File - A file based buffer

DESCRIPTION

Top

This buffer will write a file for each buffer it creates and name it with a UUID. Upon destruction it will cleanup the file.

BUGS

Top

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.

AUTHOR

Top

Stevan Little <stevan.little@iinteractive.com>

COPYRIGHT AND LICENSE

Top


Buffer-Transactional documentation Contained in the Buffer-Transactional distribution.

package Buffer::Transactional::Buffer::File;
use Moose;
use Moose::Util::TypeConstraints;

use IO::File;
use Data::UUID;

our $VERSION   = '0.02';
our $AUTHORITY = 'cpan:STEVAN';

class_type 'IO::File';

has 'uuid' => (
    is      => 'ro',
    isa     => 'Str',
    lazy    => 1,
    default => sub { Data::UUID->new->create_str },
);

has '_buffer' => (
    is      => 'ro',
    isa     => 'IO::File',
    lazy    => 1,
    default => sub { IO::File->new( (shift)->uuid, 'w' ) },
    handles => {
        'put' => 'print'
    }
);

# *sigh* Moose
with 'Buffer::Transactional::Buffer';

sub as_string {
    my $self = shift;
    $self->_buffer->flush;
    join "" => IO::File->new( $self->uuid, 'r' )->getlines;
}

sub DEMOLISH {
    my $self = shift;
    unlink $self->uuid;
}

__PACKAGE__->meta->make_immutable;

no Moose; 1;

__END__