The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

VcsTools::FileAgent - Perl class to handle a file

SYNOPSIS

 my $agent = "VcsTools::FileAgent" ;

 my $fa = new $agent(name => 'test.txt',
                     workDir => $ENV{'PWD'}.'/'.$dtest);


 $fa->writeFile(content => "dummy content\n") ;

 $fa->readFile() ;

 $fa->stat() ;

DESCRIPTION

This class is used as a file agent to perform some operation such as pipe, stat, read, write. This class will take care of going in and out of the directory where the file is and will perform basic error handling.

This class will use VcsTools::Process to launch child processes.

Note that one FileAgent class must be created for one file.

Constructor

new(...)

Creates a new class.

Parameters are :

  • name: file name (mandatory)

  • workDir: local directory where the file is.

  • trace: If set to 1, debug information are printed.

Will create a FileAgent for file 'a_name' in directory 'workDir'.

Methods

edit()

Will run a non-blocking gnuclient session to edit the file.

merge(...)

Will connect to xemacs (with gnudoit) and will run a non-blocking ediff session. See the ediff documentation.

Parameters are :

  • ancestor: the file name which contains the ancestor of the 2 files to merge

  • below: the file name which contains one of the revision to merge.

  • other: the file name which contains the other revision to merge.

Returns 1 when the ediff is launched. Returns undef in case of problems. Note that merge will return once ediff is luanched, not when the ediff session is done.

writeFile(...)

Will write a string (or an array joined with "\n") into the file.

parameters are :

  • content: string | ref_to_string_array

  • name: optional file name that will be written to (defaults to the name passed to the constructor).

readFile()

Will read the content of the file. Returns a ref to an array containing the file lines

getRevision()

Will read the content of the file and return the revision number. Return 0 of the $Revision: 1.4 $ keyword is present in the file but not set by the VCS system.

stat()

Will perform a stat (see perlfunc(3)) on the file and return the stat array.

exist()

Will return '1' or '0' if the file exists or not. ('-e' test).

chmod(...)

Will perform a chmod (see perlfunc(3)) on the file.

Parameters are :

  • mode: 0xxx mode

remove()

Will unlink (see perlfunc(3)) the file .

parameters are :

  • name: optional file name that will be written to (defaults to the name passed to the constructor).

Error handling

In case of problems, all function will return undef.

In this case of problem, you can call the error() method to get a string describing the problem of the last command.

AUTHOR

Dominique Dumont, Dominique_Dumont@grenoble.hp.com

Copyright (c) 1998-1999 Dominique Dumont. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

SEE ALSO

perl(1), VcsTools::Process(3)