
CGI::Bus::file - file object

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

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

IO::File object
Current file lock, 0 or undef is used when unlocked
File access mode, default is 'r'
File name
File permissions when to be created, default is 0666

'O_XXX' Fcntl call or 'LOCK_XX' Fcntl call or IO::File method call
Close file opened
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.
Returns internal IO::File object. Create it if not exists or if arguments present to open file. See open for arguments.
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.
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 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.
Filehandle positioning. Default positioning method is 0 - 'SEEK_SET'.
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.

Implemented and Documented.

Andrew V Makarow <makarow at mail.com>