AnyData

 view release on metacpan or  search on metacpan

lib/AnyData/Storage/File.pm  view on Meta::CPAN

	if (!$fh->seek(0, 0)) {
	    die " Error while seeking back: $!";
	}
    }
    if ($open_mode =~ /[ru]/) {
	die "Cannot read file '$file': doesn't exist!" unless -f $file;
	if (!($fh = IO::File->new($file, $mode{$open_mode}))) {
	    die " Cannot open '$file': $!";
	}
    }
    binmode($fh);
    $fh->autoflush(1);
    if ( HAS_FLOCK ) {
	if ( $open_mode eq 'r') {
	    if (!flock($fh, LOCK_SH)) {
		die "Cannot obtain shared lock on '$file': $!";
	    }
	} else {
	    if (!flock($fh, LOCK_EX)) {
		die " Cannot obtain exclusive lock on '$file': $!";
	    }

lib/AnyData/Storage/File.pod  view on Meta::CPAN


=pod

=head1 NAME

 AnyData::Storage::File -- manipulate files with rich warnings

=head1 DESCRIPTION

 Opens, reads from, writes to, creates and destroys files with numerous
 options for error handling, flocking, binmode, etc.

 The simplest form is the equivalent of

       my $f    = AnyData::Storage::File->new(dirs=>\@dirs,flock=>1);
       my $str1 = $f->adSlurp($file);

       
       for( @dirs ) {
           open(IN,$file) or die $!;
       }

lib/AnyData/Storage/File.pod  view on Meta::CPAN

           local *IN;
           local $/ = undef;
       }

 But, depending on how you set the default behaviour

=head1 SYNOPSIS

 use AnyData;
 my $f = AnyData::Storage::File->new;
 $f->set('binmode',1|0);
 $f->set('PrintError',1|0);
 $f->set('RaiseError',1|0);
 $f->set('Trace',1|0);
 $f->set('f_dir',$dir|$dir_array)

<  input, fail if doesn't exist
>  output, truncate if exists, create if doesn't
>> append, create if doesn't exist
+< read/write, fail if doesn't exist

lib/AnyData/Storage/File.pod  view on Meta::CPAN


 my $f = AnyData::Storage::File->new;

 or

 my $f = AnyData::Storage::File->new( %flags );

 %flags is a hash which can contain any or all of:

     f_dir      => $directory,   # defaults to './' (
     binmode    => $binmode,     # defaults to 0 (doesn't binmode files)
     printError => $warnings,    # defaults to 1 (print warning on errors)


=head1 open_local_file( $fname, $mode );

 Mode is one of

 a = append     open for reading & writing, create if doesn't exist
 r = read       open for reading, fail if doesn't exist
 u = open       open for reading & writing, fail if doesn't exist



( run in 1.214 second using v1.01-cache-2.11-cpan-3cd7ad12f66 )