[p4perl] P4Perl in 2007.3

Tony Smith tony at smee.org
Fri Jun 20 13:25:52 PDT 2008


Hi Scott,

getGroups() should not be calling $p4->FetchGroups() (note the plural). 
It should be calling $p4->RunGroups() instead. 'FetchGroups()'
is a method that I can only describe as unintentional. It's implemented 
by the AUTOLOADER, but as you've discovered, it won't give you the 
results you want. It probably runs a 'p4 groups -o', and 'p4 groups' 
does not take a -o flag. The Fetch* methods are intended to be used when 
you know the name of an object, and you want detailed information about 
it; don't use them to list the available objects.

tony $ p4 groups -o
Usage: groups [ -m max ] [ [ [ -i ] user | group ] | [ -v [ group ] ] ]
Invalid option: -o.

So, I suspect that's why you're getting no results. Using RunGroups() 
instead will change that.

Regards,

Tony

Scott Lavender wrote:
> Sorry, that was a typo. The actual subroutine did not have the '='. Here
> is the test code that I have written. It returns "None" for all groups.
> If I add a simple print of $groupHash, it prints the entire groups
> record. This tells me that the Fetch is not returning a Hash.
>
> # Get a list of all Perforce groups
> @groups = getGroups();
> print "\nThere are " . ($#groups + 1) . " groups defined.\n\n";
>
> #See if there are any members...
> foreach $groupName ( @groups )
> {
>     $groupHash = getGroup( $group );
>     if( defined $groupHash->{ 'Users' } )
>     {
>         print "Found users\n";
>     }
>     else
>     {
>         print "None\n";
>     }
> }
>
> sub getGroups {
>     return $p4->FetchGroups();
> }
>  
> sub getGroup {
>     my ( $groupName ) = @_;
>
>     return $p4->FetchGroup( $groupName );
> }
>
> -----Original Message-----
> From: G Barthelemy [mailto:gb.perforce at googlemail.com] 
> Sent: Friday, June 20, 2008 2:29 PM
> To: Scott Lavender
> Cc: p4perl at perforce.com
> Subject: Re: [p4perl] P4Perl in 2007.3
>
> FetchGroup ($groupName) should return a hashref in 2007.3.
>
> P4::FetchGroup($groupName) is not the same as P4::RunGroup("-o",
> $groupName), although both are a shorthand for P4::Run(group, "-o",
> $groupName) which now returns either an array or a reference to an
> array in scalar context (array of hashes to be more precise). However
> P4::FetchGroup only returns the first element of this array of hashes,
> in the form of a hashref, so it's adequate for commands that return
> just one item such as p4 group -o, p4 user -o, p4 change -o.
>
> Remove the equal sign to the right of your return statement, though.
>
> Anyway, if in doubt you can always use ref() (see
> http://perldoc.perl.org/functions/ref.html) to determine the type of
> reference returned by a method.
>
> Guillaume
>
> 2008/6/20 Scott Lavender <Scott.Lavender at visiprise.com>:
>   
>> I know there were changes when P4Perl was rolled into 2007.3. How did
>>     
> the
>   
>> return for Fetch change. I have a subroutine that expects it to be a
>>     
> has
>   
>> reference. Somehow it has changed to an array, or string. I'm not
>>     
> sure.
>   
>> sub getGroup {
>>     my ( $groupName ) = @_;
>>
>>     return = $p4->FetchGroup( $groupName );
>> }
>>
>> Can someone explain how I should alter my scripts to account for this?
>>     
> I
>   
>> tried using ParseSpec to convert to a hash, but started getting
>>     
> errors. Any
>   
>> help would be appreciated.
>>
>> Thanks.....
>> Scott Lavender | SCM Specialist | Visiprise | office: 770.619.4166 |
>> www.visiprise.com
>>
>>
>> It is our company policy not to accept email of any data controlled by
>>     
> the
>   
>> International Traffic in Arms Regulations (ITAR). Please direct
>>     
> inquiries to
>   
>> ITAR at visiprise.com for instructions and authorization to transmit such
>>     
> data.
>   
>> _______________________________________________
>> p4perl mailing list
>> p4perl at perforce.com
>> http://maillist.perforce.com/mailman/listinfo/p4perl
>>
>>
>>     
>
> _______________________________________________
> p4perl mailing list
> p4perl at perforce.com
> http://maillist.perforce.com/mailman/listinfo/p4perl
>
> !DSPAM:485bfc90176671344965704!
>
>   



More information about the p4perl mailing list