Tree::Persist::File - the base class for File plugins for Tree persistence


Tree-Persist documentation Contained in the Tree-Persist distribution.

Index


Code Index:

NAME

Top

Tree::Persist::File - the base class for File plugins for Tree persistence

DESCRIPTION

Top

This class is a base class for the Tree::Persist::File::* hierarchy, which provides File plugins for Tree persistence.

PARAMETERS

Top

In addition to any parameters required by its parent Tree::Persist::Base, the following parameters are required by connect():

* type (required)

For any File::* plugin to be used, the type must be 'File' (case-sensitive).

* filename (required)

This is the filename that will be used as the datastore.

TODO

Top

CODE COVERAGE

Top

Please see the relevant section of Tree::Persist.

SUPPORT

Top

Please see the relevant section of Tree::Persist.

AUTHORS

Top

Rob Kinyon <rob.kinyon@iinteractive.com>

Stevan Little <stevan.little@iinteractive.com>

Thanks to Infinity Interactive for generously donating our time.

COPYRIGHT AND LICENSE

Top


Tree-Persist documentation Contained in the Tree-Persist distribution.

package Tree::Persist::File;

use strict;
use warnings;

use base qw( Tree::Persist::Base );

use Scalar::Util qw( blessed );

our $VERSION = '1.00';

sub _init {
    my $class = shift;
    my ($opts) = @_;

    my $self = $class->SUPER::_init( $opts );

    $self->{_filename} = $opts->{filename};

    return $self;
}

sub _create {
    my $self = shift;

    open my $fh, '>', $self->{_filename}
        or die "Cannot open '$self->{_filename}' for writing: $!\n";

    print $fh $self->_build_string( $self->{_tree} );

    close $fh;

    return $self;
}

*_commit = \&_create;

1;
__END__