Reinhard Pagitsch <[EMAIL PROTECTED]> writes: >Hello, > >What I want is that in my .pm I use the sub new method to make some >initialation. >But in my XS module I have also the new for the C++ class constructor. >Now I found out that if I call in my test.pl MyPackage->new($file) the >method in the XS will be called instead of the new in the .pm file. > >How can I avoid this? Or is there a way to put back the initialaition to >the .pm module?
There is nothing special about the name 'new' to perl. So call one of them something else. Tyically methods perl level user isn't supposed to mess with are given an _ prefix. So XS init could be called _new. That avoids colliding with C++'s new which is NOT a function but an operator. That said if you have an object of you class what data structure(s) to you want to build for it? You perl new creates a blessed hash reference and doesn't do any C++ / XS things at all. Normaly a hybrid perl/C++ object would have one member of hash be a token for C++ stuff e.g.: $self{Internals} = _new($file); While your C++ new creates (and then immediately destructs unless I am missing something) a C++ object with a raw HV as one of its members is this supposed to be your perl object? > >Here are some code snippets: >modul.pm: >sub new >{ > my $class = shift; > if([EMAIL PROTECTED]) { die "parameter required!\n"; } > my $self = { > FILE=>shift, # file name > isError=>0, > isOOo=>0, > HANDLE=>undef, # HANDLE to file > Error=>undef > }; > my ($suffix) = $self->{FILE} =~ m/\.(\w\w\w)$/; > if($suffix eq "sxw" || $suffix eq "sxc" || $suffix eq "odt" || $suffix >eq "ods") > { > $self->{isOOo} = 1; > } > bless $self, $class; > return $self; >} > >the modul.xs: >... >MODULE = Win32::File::Prop PACKAGE = Win32::File::Prop > > >properties* >properties::new(File); > char * File > >The constructor: >properties::properties(char * File) >{ > MultiByteToWideChar(CP_ACP, 0, File, -1, m_File, > (sizeof(m_File)/sizeof(WCHAR))); > m_hr = S_OK; > m_ipStg = NULL; > m_hv = (HV* )newHV(); >} > > >In the test.pl I call init the module with >my $STR = Module->new($file); > > >Thank you, >Reinhard