Title: http://dev.perl.org/rfc/73.html

> [25]RFC 73: All Perl core functions should return objects
>
[...]
>
> I'm thinking that the solution is better abstract type support
> for data values that happen to be represented internally by C
> structs. We get bogged down when we try to translate a C
> struct such a struct tm into an actual hash value. On the
> other hand, it's rather efficient to translate a struct tm
> to a struct tm, since it's a no-op.
>
> We can make such a struct look like a Perl object, and access it
> efficiently with attribute methods as if it were a ``real''
> object. And the typology will (hopefully) mostly only impose an
> abstract overhead.

Neil Watkiss <[EMAIL PROTECTED]> and Brian Ingerson <[EMAIL PROTECTED]> have been roughing out ideas for a Inline::Struct module which sounds similar if not related to the this. It's primary objective is simpilfying passing structured data between Perl and C/C++. It also makes a struct look like a Perl object. There is an unreleased module implementing a C++ interface which works quite well. A C version is planned as well. Others may follow. Right now, it works like this:

use Inline CPP => <<'END', STRUCTS => ['Foo'];

struct Foo {
  int inum;
  double dnum;
  char *str;
};
typedef struct Foo Foo;

END

my $o = new Inline::Struct::Foo;
$o->inum(10);
$o->dnum(3.1415);
$o->str('Wazzup?');

my %fields = %{$o->_HASH};
my @keys = @{$o->_KEYS};
my @fields = @{$o->_ARRAY};

package Inline::Struct::Foo;
sub Print {
  my $o = shift;
  print "Foo {\n", (join "\n", map { $o->$_() } $o->_KEYS), "}\n";
}

__END__


Anything that is typemap'd can be used. I'm hoping Inline::Struct will evolve into the compiled complement to Class::Struct. If Perl 6 could do this without requiring a compiler on hand, it would be the perfect replacement/evolution of Class::Struct.

Garrett



Reply via email to