[p4perl] Problems inheriting from P4

Eleftherios.Kororos at symbian.com Eleftherios.Kororos at symbian.com
Wed Feb 2 08:49:51 PST 2005


Hi Tony,

thanks for your reply. 

I can see were the problem is now. 

What I was trying to do was to provide a utility class as part of a 
generic framework, that would simplify the access to perforce (using P4) 
by implementing the functionality as required by the framework. However, 
most of the specialisation would be in the initialisation of P4 and the 
rest of the methods would be the P4 methods (without overriding them). 

In this case I guess it doesn't matter too much that we can't derive from 
P4, since the derived class would only provide a very thin wrapper around 
P4 API, therefore the client of P4 will have to make these calls to P4 API 
when necessary. 

Thanks for your prompt reply anyway, and it would be useful to know when 
(and if) the API gets implements as a hashref. 

Thanks, 

Terry Kororos




Tony Smith <tony at smee.org> 
Sent by: p4perl-bounces at perforce.com
02/02/2005 16:08

To
p4perl at perforce.com
cc

Subject
Re: [p4perl] Problems inheriting from P4






Hi Terry,

> I am trying to implement my own derived class from the P4 class. Here is
> the code...
>
> package Perforce;
> use strict;
> use P4;
>
> our @ISA = qw(P4);
>
> sub new
> {
>     my $class = shift;
>     my $self = bless {}, $class;

That just creates an anonymous hash and blesses it into the class. It 
hasn't 
run any kind of constructor or initialized the Perforce API at all.

>     $self->{username} = shift;
>     $self->{password} = shift;
>     $self->{server} = shift;
>     $self->{clientspec} = shift;
>     return $self;
> }
>
> sub init
> {
>     my $self = shift;
>     $self->SetPort($self->{server});
>     $self->SetUser($self->{username});
>     $self->SetPassword($self->{password});
>     $self->SetClient($self->{clientspec});
>     $self->Init() or die("Failed to connect to Perforce\n");
> }
>
> 1;

Unfortunately it's currently (v3.x) difficult to derive from the P4 class. 
A 
P4 object is not a hash, it's a blessed reference to an integer, an I32 in 

Perl terms (oddly, an I32 can be 64-bits long), containing a pointer to a 
C++ 
object. 

I'll look into making it a blessed hashref and stashing the pointer as a 
member of the hash, but in the meantime perhaps it would help if you told 
us 
what you are trying to achieve - there might be another way?

Tony
_______________________________________________
p4perl mailing list
p4perl at perforce.com
http://maillist.perforce.com/mailman/listinfo/p4perl




-----------------------------------------
Symbian Software Ltd is a company registered in England and Wales with
registered number 4190020 and registered office at 2-6 Boundary Row,
Southwark, London, SE1 8HP, UK. This message is intended only for use by
the named addressee and may contain privileged and/or confidential
information. If you are not the named addressee you should not disseminate,
copy or take any action in reliance on it. If you have received this
message in error please notify postmaster at symbian.com and delete the
message and any attachments accompanying it immediately. Neither Symbian
nor any of its subsidiaries accepts liability for any corruption,
interception, amendment, tampering or viruses occurring to this message in
transit or for any message sent by its employees which is not in compliance
with Symbian corporate policy.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://maillist.perforce.com/pipermail/p4perl/attachments/20050202/c0b43cf2/attachment-0001.html>


More information about the p4perl mailing list