AnyData2

 view release on metacpan or  search on metacpan

lib/AnyData2/Storage/FileSystem.pm  view on Meta::CPAN

package AnyData2::Storage::FileSystem;

use 5.008001;
use strict;
use warnings FATAL => 'all';

use base qw(AnyData2::Storage);

use Carp qw/croak/;
use IO::Dir ();

=head1 NAME

AnyData2::Storage::FileSystem - AnyData2 filesystem storage ...

=cut

our $VERSION = '0.002';

=head1 METHODS

=head2 new

constructs a storage reading entries from filesystem

=cut

sub new
{
    my ( $class, %options ) = @_;
    my $self = $class->SUPER::new();
    $self->{dirh} = IO::Dir->new( $options{dirname} ) or die "Can't open $options{dirname}";
    @$self{qw(dirname)} = @options{qw(dirname)};
    $self;
}

=head2 read

  my $entry = $stor->read

Use binmode for characters as synonymous for bytes.

=cut

sub read
{
    my $self  = shift;
    my $entry = $self->{dirh}->read;
    $entry;
}

=head2 seek

  $stor->seek(0,SEEK_SET)

Sets the current position to the beginning of the directory (this,
naturally, affects read only).

=cut

sub seek
{
    my ( $self, $pos, $whence ) = @_;
    $pos == 0 and $whence == 0 and return $self->{dirh}->rewind;
    croak "Unsupported combination of POS and WHENCE";
}

=head2 meta

Experimental

Returns a meta storage - if any. Imaging it as an object dealing with
underlying filesystem for a file storage.

=cut

sub meta
{
    my $self = shift;
    $self->{meta} or $self->{meta} = AnyData2::Storage::FileSystem->new( dirname => dirname( $self->{dirname} ) );
    $self->{meta};
}

=head1 LICENSE AND COPYRIGHT

Copyright 2015,2016 Jens Rehsack.

This program is free software; you can redistribute it and/or modify it
under the terms of either: the GNU General Public License as published
by the Free Software Foundation; or the Artistic License.

See http://dev.perl.org/licenses/ for more information.

If your Modified Version has been derived from a Modified Version made
by someone other than you, you are nevertheless required to ensure that
your Modified Version complies with the requirements of this license.

This license does not grant you the right to use any trademark, service
mark, tradename, or logo of the Copyright Holder.

This license includes the non-exclusive, worldwide, free-of-charge



( run in 0.461 second using v1.01-cache-2.11-cpan-39bf76dae61 )