NAME

P4::Server - Perl wrapper for control of a Perforce server

VERSION

Version 0.11

SYNOPSIS

This module provides for control and configuration of a Perforce server.

use Error qw( :try );
use P4::Server;

my $server = P4::Server->new( {
        port    => $port,
) };
$server->create_temp_root();
$server->set_cleanup( 1 );
$server->start_p4d();

try {
    $server->load_journal_file( $journalfile );
}
catch P4::Server::Exception with {
    # Handle the error
};

# Do some operations against the server
# Automatically stops the server and cleans up based on the cleanup flag

METHODS

clean_up_root

If the clean up flag is set and the root is defined, automatically removes the server root.

Throws

  • P4::Server::Exception::ServerRunning - when attempting to clean up the root directory of a running server

create_temp_root

Creates a temporary directory and sets it as the server root. This directory will be cleaned up when the program exits according to the state of the cleanup attribute when this method is called.

get_cleanup

Returns whether the object is set to clean up the server root upon destruction.

get_journal

Returns the server journal name.

get_log

Returns the server log name.

get_p4d_exe

Returns the name of the currently set p4d executable.

get_p4d_timeout

Returns the number of seconds P4::Server will wait for p4d to start. See "set_p4d_timeout" for the exact definition of what this means.

get_pid

Returns the PID of the running server, if any.

get_port

Returns the Perforce port for the server.

get_root

Returns the server root.

load_journal_file

Loads the specified file as a journal into the Perforce server for this object. The server does not have to be running.

Parameters

  • journal - Journal file to load

Throws

  • P4::Server::Exception::NoJournalFile - If the supplied journal file name doesn't exist

  • P4::Server::Exception::FailedSystem - If the system() call invoking the journal load fails

load_journal_string

Loads the specified string as a journal into the Perforce server for this object. Creates a temporary file, loads the journal file from it, and removes the file. The server does not have to be running.

  • contents - String containing the journal content to load.

new

Constructor for P4::Server. Takes an optional hash argument of parameters for the server. The valid keys in the hash are:

  • p4d_exe - The name of the p4d executable to be used. Default: 'p4d'

  • port - The value of P4PORT for the server. Default: '1666'

  • root - The value of P4ROOT for the server. No default indicating current directory.

  • log - The value of P4LOG for the server. Default: 'log'

  • journal - The value of P4JOURNAL for the server. Default: 'journal'

Throws

  • P4::Server::Exception::InvalidExe - the p4d or p4 executables do not exist or are not executable files

set_cleanup

A true value tells the object to clean up the server root upon destruction.

set_journal

Gets the server journal name.

set_log

Sets the server log name.

set_p4d_exe

Sets the p4d executable to use. An undefined argument sets the value back to the default ('p4d').

Throws

  • P4::Server::Exception::InvalidExe - the p4d executable does not exist or is not an executable file

set_p4d_timeout

Sets the minimum number of seconds P4::Server will wait for p4d to start before giving up. Because of the nature of the tests being applied, the actual wait time is unpredictable and theoretically unbounded, although practically very finite.

Throws

Nothing

set_port

Sets the Perforce port for the server. If the port is set to undef, the port will be dynamically allocated when the server is started. At that point a port will be assigned. If the server is stopped and restarted, the assigned port will continue to be used unless the port is reset to undef.

set_root

Sets the server root with the side-effect of invoking clean_up_root.

Throws

  • P4::Server::Exception::ServerRunning - when attempting to change the root directory of a running server

start_p4d

Starts the server with the current settings. If the port is undefined, a port will be dynamically assigned. That port will continue to be used through stops and starts until the port is reset to undef.

Throws

  • P4::Server::Exception::FailedExec - if the execution of the Perforce server fails

  • P4::Server::Exception::FailedToStart - The server failed to start servicing requests in the specified time despite executing successfully

  • P4::Server::Exception::P4DQuit - The server stopped after initially executing successfully

  • P4::Server::Exception::ServerListening - Another server is already listening on the specified port

  • P4::Server::Exception::ServerRunning - if the server is already running when this method is called

stop_p4d

Stops the currently running server for this object.

unpack_archive_to_root_dir

Unpacks an archive of any type supported by Archive::Extract into the currently set root directory for the server.

It is expected that the archive consists of depot files and checkpoints made relative to the server root directory.

Returns

An array reference with the paths of all the files in the archive, relative to the server root.

Throws

  • P4::Server::Exception::NoArchiveFile - When the specified archive file does not exist or is not readable

  • P4::Server::Exception::ArchiveError - When Archive::Extract returns an error

  • P4::Server::Exception::UndefinedRoot - When the root directory has not yet been defined.

  • P4::Server::Exception::RootDoesNotExist - When the root directory does not exist

BUILD

Constructor invoked by Class::Std

DEMOLISH

Destructor invoked by Class::Std. Invokes stop_p4d and clean_up_root.

AUTHOR

Stephen Vance, <steve at vance.com>

BUGS

Please report any bugs or feature requests to bug-p4-server at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=P4-Server. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

perldoc P4::Server

You can also look for information at:

ACKNOWLEDGEMENTS

Thank you to The MathWorks, Inc. for sponsoring this work and to the BaT Team for their valuable input, review, and contributions.

COPYRIGHT & LICENSE

Copyright 2007-8 Stephen Vance, all rights reserved.

This program is released under the following license: Artistic