NAME

CGI::Bus::file - file object

SYNOPSIS

 use CGI::Bus;
 $s =CGI::Bus->new();
 $s->file(-name=>'t.txt', -mode=>'rwc')->store('aa','bb');

DESCRIPTION

This module is a file object encapsulating IO::File object. See CGI::Bus::Base for inherited slots and methods.

SLOTS

-iofile

IO::File object

-lock

Current file lock, 0 or undef is used when unlocked

-mode

File access mode, default is 'r'

-name

File name

-perm

File permissions when to be created, default is 0666

METHODS

AUTOLOAD

'O_XXX' Fcntl call or 'LOCK_XX' Fcntl call or IO::File method call

close -> self object

Close file opened

dump ( data ) -> self object
dump -> data dump loaded
dumpload -> data dump loaded
dumpstore ( data ) -> self object

Store and load data structure to or from file using store, load, CGI::Bus::dumpout, CGI::Bus::dumpin. seeks to the beginning of the file before read or write.

iofile ( ?file open args ) -> IO:File object

Returns internal IO::File object. Create it if not exists or if arguments present to open file. See open for arguments.

load ( ?-asb, ?sub ) -> data loaded

Reads file into memory as array or list ('-a'), text scalar ('-s'), binary scalar ('-b'). Default, '-a' or '-b', is determined with wantarray. Locks file with 'LOCK_SH' if there is no shared or exclusive lock, lock remains after operation. seeks to the beginning of the file before read.

If sub is defined, it is evaluated for each row read into local $_, and with '-a' option results of each evaluation are returned as a list, true is returned otherwise.

lock ( lock mode ) -> self object
lock -> current lock mode

Locks or unlocks file, or returns current lock. Lock mode may be Fcntl 'LOCK_SH', 'LOCK_EX', 'LOCK_UN', or strings 'sh', 'ex', 'un' or '0'. 0 means unlocked file.

open ( filename, ?mode, ?perm ) -> self object

Open file. Default mode is 'r', mode may be Fcntl constants like 'O_RDONLY', 'fopen' mode signs 'r', 'w', 'a', 'r+', 'a+', mode strings 'rw' for O_RDWR and 'rwc' for O_RDWR|O_CREAT. Default permission is 0666.

seek ( position, ?whence ) -> self object

Filehandle positioning. Default positioning method is 0 - 'SEEK_SET'.

store ( ?-b, data to store ) -> self object

Writes given data into file. Locks file with 'LOCK_EX' if there is no exclusive lock, lock remains after operation. Does not seeks, call seek before store call. Option '-b' chooses binary mode and binary write. Without '-b', each element of data list is printed with trailing "\n" added.

VERSION

22/12/2001 - 23/12/2001

Implemented and Documented.

AUTHOR

Andrew V Makarow <makarow at mail.com>

2 POD Errors

The following errors were encountered while parsing the POD:

Around line 149:

You forgot a '=back' before '=head2'

Around line 154:

=back without =over