ActiveState Powered by ActiveState

ActiveState Community


plc and forward declaring perl classes

Posted by frode on 2007-06-19 04:43
OS: Windows

Hi!

I'm newbie to perl, but experience C programmer, trying to make my perl modules into a .NET DLL library.

My problem is that while wrapping my existing modules into C# interface, one of my class Person uses another class Group declared after the class Person. This results in an error that Group is not defined:

System.ApplicationException: Can't locate type Group

Is it possible to forward declare class Group before class Person is declared, so PLC compiler knows about it?
Or, is there some other way around this?

Currently, I'm adding all interface definitions in an own file, instead of modifying the original Perl source-code. Like so:

# -------------------------------------------------------------------

package My::Person;
#use My::Group; # this forwarding does not work

=for interface
  [interface: pure]
  static Person();
  bool IsMemberOf(Group theGroup); # error
=cut

require My::Person;

# -------------------------------------------------------------------

package My::Group;

=for interface
  [interface: pure]
  static Group();
  wantarray Person[] GetMembers(); # ok, Person is declared here
=cut

require My::Group;

Here, the class Person need to know Group in advance...

Hope I'm making myself understandable. :-)

Thanks in advance for any hints!
Regards, Frode

frode | Wed, 2007-06-20 12:29

Looks like splitting the interface definition did the trick!

# -------------------------------------------------------------------

package My::Person;

=for interface
[interface: pure]
static Person();
=cut

require My::Person;

# -------------------------------------------------------------------

package My::Group;

=for interface
[interface: pure]
static Group();
wantarray Person[] GetMembers(); # ok, Person is declared here
=cut

require My::Group;

# -------------------------------------------------------------------

package My::Person;

=for interface
bool IsMemberOf(Group theGroup); # now ok
=cut

-->