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.



( run in 0.455 second using v1.01-cache-2.11-cpan-0bb4e1dffa6 )