# Copyright (c) 1997-2004, Perforce Software, Inc. All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL PERFORCE SOFTWARE, INC. BE LIABLE FOR ANY # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package P4::Client; use strict; require Exporter; require DynaLoader; use AutoLoader; use vars qw( $VERSION @ISA @EXPORT @EXPORT_OK $AUTOLOAD ); @ISA = qw(Exporter DynaLoader); @EXPORT_OK = qw( ); @EXPORT = qw( ); $VERSION = '2.4319'; bootstrap P4::Client $VERSION; # Get/Set Debug level. 0 = off, > 0 = on. Without an argument it returns # the current debug level. sub DebugLevel { my $self = shift; $self->{ "Debug" } = shift if ( @_ ); $self->{ "Debug" }; } sub DoPerlDiffs { my $self = shift; $self->{ "PerlDiffs" } = 1; } sub DoP4Diffs { my $self = shift; $self->{ "PerlDiffs" } = 0; } # Change the current working directory. Returns undef on failure. sub SetCwd { my $self = shift; my $cwd = shift; # First we chdir to the dir if it exists. If successful, then we # update the PWD environment variable (if defined) and call the # API equivalent function, now named _SetCwd() return undef unless chdir( $cwd ); $ENV{ "PWD" } = $cwd if ( defined( $ENV{ "PWD" } ) ); $self->_SetCwd( $cwd ); return $cwd; } # Makes the Perforce commands usable as methods on the object for # cleaner syntax. If it's not a valid method, you'll find out when # Perforce recommends you read the help. sub AUTOLOAD { my $self = shift; my $ui = shift; my $cmd; ($cmd = $AUTOLOAD ) =~ s/.*:://; $cmd = lc $cmd; return $self->Run( $ui, $cmd, @_ ); } 1; __END__ =head1 NAME P4::Client - Perl extension for the Perforce API =head1 SYNOPSIS use P4::Client; use P4::UI; my $client = new P4::Client; my $ui = new P4::UI; $client->SetClient( $clientname ); $client->SetPort ( $p4port ); $client->SetPassword( $p4password ); $client->Init() or die( "Failed to connect to Perforce Server" ); $client->Run( $ui, "info" ); $client->Run( $ui, "edit", "file.txt" ); # OR, using Autoloaded methods instead of Client::Run(). $client->Users( $ui ); $client->Resolve( $ui, "-ay" ); $client->Submit( $ui ); $client->Final(); =head1 DESCRIPTION This module provides a Perl interface to the Perforce API allowing you to write Perl scripts which communicate directly with a Perforce server. P4::Client is the main interface through which all commands are issued. The Perforce API is callback based though, and all interaction with the user interface takes place through callbacks to methods of the P4::UI object passed to the Run() method. To customise the behaviour of the Perforce client, you should derive your own class from P4::UI and override the relevant methods therein. =head1 METHODS The following paragraphs define the methods of a P4::Client object. Note that due to the magic of the Autoloader, the Perforce commands ( submit, client, filelog etc. ) are also available as methods ( case insensitive ) as well as through the Run() method. =over 4 =item C<Client::new()> Construct a new Client object. =item C<Client::Dropped()> Returns true if the TCP/IP connection between client and server has been dropped. =item C<Client::Final()> Terminate the connection and clean up. Should be called before exiting to cleanly disconnect. =item C<Client::GetClient()> Returns the current Perforce client name. This may have previously been set by SetClient(), or may be taken from the environment or P4CONFIG file if any. If all that fails, it will be your hostname. =item C<Client::GetCwd()> Returns the current working directory as your Perforce client sees it. =item C<Client::GetHost()> Returns the client hostname. Defaults to your hostname, but can be overridden with SetHost() =item C<Client::GetPassword()> Returns your Perforce password - in plain text if that's how it's stored and currently on all except Windows platforms, that's the way it's done. Taken from a previous call to SetPassword() or extracted from the environment ( $ENV{P4PASSWD} ), or a P4CONFIG file. Note that the password is not transmitted in clear text. =item C<Client::GetPort()> Returns the current address for your Perforce server. Taken from a previous call to SetPort(), or from $ENV{P4PORT} or a P4CONFIG file. =item C<Client::Init()> Initializes the Perforce client and connects to the server. Returns false on failure and true on success. =item C<Client::Run( $ui, $cmd, [$arg...] )> Run a Perforce command. The first argument must be a reference to a P4::UI object or a reference to an object derived from P4::UI. The methods of that object will be used to interact with the user. The subsequent arguments are the command you wish to run, and the arguments you want to pass to it. At this time, only strings and numbers are valid argument types although through the magic of Perl you can pass arrays or hashes but not references. =item C<Client::SetClient( $client )> Sets the name of your Perforce client. If you don't call this method, then the clientname will default according to the normal Perforce conventions. i.e. =over 4 =item 1. Value from file specified by P4CONFIG =item 2. Value from C<$ENV{P4CLIENT}> =item 3. Hostname =back =item C<Client::SetCwd( $path )> Sets the current working directory for the client. This should be called after the Init() and before calling Run(). Note that this method does actually change your working directory (using chdir), and will also update the PWD environment variable (if defined) to reflect the change. =item C<Client::SetPassword( $password )> Set the password for the Perforce user, overriding all defaults. =item C<Client::SetPort( [$host:]$port )> Set the port on which your Perforce server is listening. Defaults to: =over 4 =item 1. Value from file specified by P4CONFIG =item 2. Value from C<$ENV{P4PORT}> =item 3. perforce:1666 =back =item C<Client::SetProtocol( $protflag, $value )> Set protocol options for this session. The most common protocol option is the "tag" option which requests tagged output format for commands which would otherwise get formatted output. In API terms, this means the output comes through the P4::UI::OutputStat() interface, instead of P4::UI::OutputInfo(). For example: =over 4 C<< $client->SetProtocol(tag','') >> =back =item C<Client::SetUser( $username )> Set your Perforce username. Defaults to: =over 4 =item 1. Value from file specified by P4CONFIG =item 2. Value from C<$ENV{P4USER}> =item 3. OS username =back =item C<Client::DebugLevel( [level] )> Get/Set the debug level for the given client. Passing a value of zero disables debugging, whilst a value of 1 enables it. Default is off. For example: =over 4 C<< $client->DebugLevel( 1 ) >> C<< $client->DebugLevel( 0 ) >> C<< print( "Debug level = ", $client->DebugLevel(), "\n" ) >> =back =item C<Client::DoPerlDiffs()> Specify that you will handle the comparing of files within Perl space yourself by overriding the Diff() method in your derived class. This method is preserved for backwards compatibility with previous releases of P4::Client. For example: =over 4 C<< $client->DoPerlDiffs() >> C<< $client->Diff( $ui, "file.c" ) >> =back =item C<Client::DoP4Diffs()> Specify that you want P4::Client to send the output of "p4 diff" commands through the UI::OutputText() method as for other commands. This is the default behaviour. For example: =over 4 C<< $client->DoP4Diffs() >> C<< $client->Diff( $ui, "file.c" ) >> =back =back =head1 API Versions This extension has been built and tested on the Perforce 2000.2 API, but should work with any recent version, certainly any release later than and including 99.2. =head1 LICENCE Copyright (c) 1997-2004, Perforce Software, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL PERFORCE SOFTWARE, INC. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. =head1 AUTHOR Tony Smith, Perforce Software ( tony@perforce.com ) =head1 SEE ALSO perl(1), P4::UI(3), Perforce API documentation. =cut
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#26 | 4319 | Tony Smith |
Update Cygwin hints file to handle gcc3 builds using the 2003.2 API. Thanks to Jeremy Bopp. |
||
#25 | 4259 | Tony Smith |
Porting change. Improved solaris hints file for Solaris 8/9 (and hopefully later releases too). No functional change |
||
#24 | 4158 | Tony Smith |
Copyright notice updates. No functional change. |
||
#23 | 3552 | Tony Smith |
Release previous bugfix from a platform that can build a decent tarball... |
||
#22 | 3550 | Tony Smith |
Add OutputBinary() support to P4Perl. This allows "p4 print" to work with clients that do not use "local" line endings amongst other things. |
||
#21 | 3540 | Tony Smith |
Add hints file for Cygwin contributed by Nathan Royer - thanks Nathan! |
||
#20 | 2596 | Tony Smith |
Bug fix: Allow form parsing to accept forms that are initialised (deliberately) with invalid data. |
||
#19 | 2411 | Tony Smith |
Port bug fix from P4Ruby to P4Perl. Certain variable names get reused in tagged mode and this causes the hash members to lose their earlier contents when the later value comes along. Specifically this is otherLock and otherOpen in the output of "p4 fstat". This slightly unpleasant fix simply renames the later variable name by appending an "s" to it. So otherLock becomes otherLocks and otherOpen becomes otherOpens. Now otherOpen is an array containing the user/client of the other users who have the file open and otherLock is a single-element array containing the user/client of the user who has the file locked. otherOpens contains the number of other users who have the file opened. otherLocks contains an empty string. Since the latter two are quite redundant they may be explicitly removed in a future release. |
||
#18 | 2373 | Tony Smith |
Bug fix: Forms parsing was not correctly handling fields with embedded digits like the P4DTI-* fields in a job. This fix should make the detection of the base variable name and its index more reliable |
||
#17 | 2279 | Tony Smith |
Bump major version up to 2.2279 to make CPAN see this as a new release. CPAN.pm thinks 1.982 is newer than 1.1084 so hopefully this will stop CPAN users getting old release of P4-Client. No functional change |
||
#16 | 2223 | Tony Smith |
Relegated previous support for "p4 diff" to the bottom drawer and use the Diff class provided in the P4 API to send the diff listings through the OutputText() interface. This has two main advantages over the old implementation: (a) same output as "p4 diff" as it uses the same classes and (b) doesn't require extra perl modules. The old implementation is still available - you just have to call P4::Client::DoPerlDiffs() to specify your preference. |
||
#15 | 2084 | Tony Smith |
Removed ugly hack preserving the specdef in perl hashes. There's no need for it as the server kindly provides it when you run the "p4 XXX -i". A little tidying of the test harness. It's not great, but there's at least something in there to check the form parsing now. |
||
#14 | 2010 | Tony Smith |
Bug fix. Fix crash when bizarre input is supplied as allegedly valid form fields. |
||
#13 | 1980 | Tony Smith |
Porting changes. Make P4/Perl build with ActivePerl > 623. They've messed up the PerlIO headers now so you can't use fprintf in an XSUB anymore. Also they're now including math.h and on Windows that must be included with C++ linkage so we now include it before we include the other perl headers that have to be included with C linkage. |
||
#12 | 1976 | Tony Smith |
Add support for ClientUser::Diff() to P4/Perl. Uses the Algorithm::Diff module to perform the diffs. Thanks to Wilson Snyder. |
||
#11 | 1894 | Tony Smith |
Bug fix. Correcty typo in SetCwd() - been doing too much Ruby (It's not a habit, I can control it) so I used [] instead of {} for indexing a hash. |
||
#10 | 1711 | Tony Smith |
Missed changes to Client.xs. Updated build accordingly |
||
#9 | 1710 | Tony Smith |
Bug fix/workaround. P4::Client::SetCwd() now does genuinely change your working directory, and also updates the PWD environment variable so that P4CONFIG files from the target directory can be correctly loaded. |
||
#8 | 1692 | Tony Smith |
Explicitly add extra preprocessor definitions for linux builds. It seems that some builds, most notably ActiveState ones don't use _BSD_SOURCE or _SVID_SOURCE so these settings are not propagated to additional modules. Thanks to Jeremy Russell. |
||
#7 | 1615 | Tony Smith |
Add debugging support to the ClientUserPerl class. It's not complete, but it's targeted at the code which deals with tagged output parsing which is the most complex code by far. |
||
#6 | 1546 | Tony Smith |
Fix to debugging code. Two debug statements were not protected by conditions so they always executed. Very annoying. Updating current build to 1546. |
||
#5 | 1542 | Tony Smith |
Removed another ClientApi reference in the debug code, and also made the debug code useable without the need to recompile. Now you just call $client->DebugLevel( 1 ); to enable debugging at run time. |
||
#4 | 1515 | Tony Smith |
Bug fix. Make sure all perl header files are included with C linkage preventing problems with redefinition of Perl_malloc() et al. |
||
#3 | 1084 | Tony Smith |
Bug fix: Fetching data using Tagged() or ParseForms() mode could give "attempt to free unreferenced scalar" errors on completion. When flattening the structured hashes into a Perforce form, the reference counts on the contents of the hash were not being incremented leading to their premature destruction. |
||
#2 | 1050 | Tony Smith |
Fix for parsing of complex tagged output with nested data items such as the output from "p4 filelog" for a file with integration records. P4-Client can now handle any level of nested data in the response from the Perforce server, but complex structures of this type may not be supplied for conversion into a Perforce form. That's OK as no Perforce forms have nested data items. Updated current build to 1.1050 |
||
#1 | 1011 | Tony Smith |
Moved Perl API stuff one level down to make way for upcoming Ruby interface. |
||
//guest/tony_smith/perforce/API/P4-Client/Client.pm | |||||
#8 | 977 | Tony Smith |
Fix broken form parsing. Two problems: first off, the specdef was not being saved in the hash for later use so forms could not be reconstructed from the hash data structure. Secondly, multi-line elements parsed into array members of the hash were not being flattened prior to reconstructing the form so they would be empty. |
||
#7 | 976 | Tony Smith |
Fix for multi-line field handling bug. The array handling code was dependent on all results for a given tag being supplied before moving on to the next tag, but this is not true for all Perforce commands. i.e. p4 client -o -> tags not fragmented p4 describe -s -> oops. Now the implementation is not fussy about the order in which elements arrive other than that tagN comes before tagN+1. Any number of other elements may come in between them. |
||
#6 | 966 | Tony Smith | Updated 1.966 build | ||
#5 | 964 | Tony Smith | Release P4::Client 1.964 | ||
#4 | 931 | Tony Smith | Latest (931) builds of P4::Client and P4 | ||
#3 | 923 | Tony Smith |
Update version numbering scheme for P4::Client so that the minor release is the changelist number. This is to save me having to branch the source code at release time. |
||
#2 | 577 | Tony Smith | Preparations for release of P4::Client version 0.52 | ||
#1 | 549 | Tony Smith |
Renamed the working directory to P4-Client as I've discovered that MakeMaker is quite happy with that and doesn't require a version number in the directory name. |
||
//guest/tony_smith/perforce/API/P4-Client-0.51/Client.pm | |||||
#2 | 528 | Tony Smith |
Updated version numbers etc. and tarball for 0.51. |
||
#1 | 527 | Tony Smith | Release P4::Client version 0.51 with Win32 support | ||
//guest/tony_smith/perforce/API/P4-Client-0.50/Client.pm | |||||
#2 | 511 | Tony Smith | Completed the process of renaming P4::ClientApi to P4::Client | ||
#1 | 510 | Tony Smith | Renamed the ClientApi modules | ||
//guest/tony_smith/perforce/API/P4-Client-0.50/ClientApi.pm | |||||
#1 | 509 | Tony Smith |
Renamed P4::ClientApi to P4::Client as it's more friendly and that's what it's called on CPAN. Subsequent changes include the actual renaming inside the code, this just creates the branch |
||
//guest/tony_smith/perforce/API/P4-ClientApi-0.05/ClientApi.pm | |||||
#2 | 507 | Tony Smith |
Removed explicit use of sub AUTOLOAD as it messes with your namespace. Put there in the first place by h2xs from perl 5.5. Not worthy of a new release ID. |
||
#1 | 501 | Tony Smith |
First publicly released version of the Perl interface to the Perforce API. |