#!/usr/bin/perl #******************************************************************************* #* example.pl - a short sample showing how to use the P4 client interface #******************************************************************************* use P4; # Initialisation my $p4 = new P4; $p4->Connect() or die( "Failed to connect to Perforce" ); # Running "p4 info" and getting the results as a single string my $info; $info = join( "\n", $p4->Info() ); # Or equivalently $info = join( "\n", $p4->Run( "info" ) ); # Running "p4 info" and getting the results in array form my @info; @info = $p4->Info(); # Submitting changes. Use "p4 change -o" to grab the change spec # and "p4 submit -i" to do the submit. # # Commented out by default to make the example non-invasive #my $change = $p4->FetchChange(); #$change =~ s/<enter description here>/Some description/; #$p4->SetInput( $change ); #$p4->Submit( "-i" ) ); # Parsing forms. Requires protocol options set prior to initialisation $p4 = new P4; # discard old object $p4->ParseForms(); $p4->Connect() or die( "Failed to connect to Perforce" ); my $spec = $p4->FetchClient(); foreach my $key ( sort keys %$spec ) { next if ( $key eq "specdef" ); if( $key eq "View" ) { print( "View:\n" ); foreach my $v ( @{$spec->{ $key }} ) { print( "\t$v\n" ); } } else { print( "$key\t => " . $spec->{ $key } . "\n" ); } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#2 | 4579 | Tony Smith |
Rewrite P4Perl to be more like P4Ruby. This change does away with the old P4/P4::Client split and pulls all the functionality of P4::Client into P4. Hence P4::Client is now deprecated. There are a few gotcha's - see the Changes file, and documentation for the details, but in general it's backwards compatible. As part of this change, I'm also releasing the previous current versions of P4 and P4::Client as released versions - for posterity. P4 now gets a v3.x version number so the old versions will stand out clearly. Hopefully it's all working - works fine for me - but people should consider this a beta build, for now at least. |
||
#1 | 1011 | Tony Smith |
Moved Perl API stuff one level down to make way for upcoming Ruby interface. |
||
//guest/tony_smith/perforce/API/P4/example.pl | |||||
#1 | 960 | Tony Smith |
Misc changes. Added an example.pl file with sample code. Also Added the PPD file to the manifest (duh!). P4::Run() now returns an array reference instead of a formatted string when used in scalar context where more than one result is returned. Also renamed the shortcut GetXXX and SetXXX methods to be FetchXXX and SaveXXX because GetClient() and SetClient() we already defined by P4::Client. |