Hi Garrett,
> Can you make a 'pre' version available for the more curious inliners who
> don't mind patching inline themselves?
Sure! When I get home, I'll fire a dist together and put it on a webpage.
> > FEATURES
> > o Automatically generates three things for bound structs:
> > - a Perl class with the following autogenerated methods:
> [...]
> > _HASH -- returns a hash ref containing the field/value pairs.
> > _ARRAY -- returns an array ref containing the field
> > values. Struct
> > order.
> > _KEYS -- returns an array ref containing the field names. Struct
> > order.
>
> In both of the following cases, I assume you are just trying to avoid
> clobbering the package namespace, but
> o Do you mean to infer private with the leading _'s?
> o Uppercase usually denotes Class methods
Both true. It's possible to use a different method of denoting special
cases, but I wasn't sure what to use.
The question is, what "special" methods do Inline::Struct objects need to
support?
o give me the keys (in the struct order)
o give me the values (in the struct order)
o give me the hash (in hash or struct order, I don't care)
o give me the array (in the struct order)
o give me the value of this field
o set this field to this value
> Perhaps a future version will support:
> o TIEHASH and/or TIEARRAY?
> o _VALUES?
Tied hashed would be pretty cool -- the keys would be in the correct
order. The _VALUES is already secretly supported; it's called _ARRAY.
> > In addition, each field generates a method of the same
> > name. If you pass it no arguments, it returns the value
> > of that field. If you pass it an argument, it sets that
> > field and returns the object, so that you can chain such
> > assignments: $o->inum(10)->dnum(3.1415);
>
> hmm that's interesting. Haven't seen that before.
I got the idea from Data::Dumper, which uses similar ideas for its
methods.
> What does it return if you attempt to assign invalid data?
There's very little in the way of invalid data that you can get from Perl.
Here's my old example:
----8<----
struct Foo {
int inum;
double dnum;
char *str;
};
----8<----
Here's the XS generated for 'inum()' (I think -- I didn't check):
void
inum(obj, ...)
Foo * obj
PPCODE:
if (items != 1) {
SV *tmp;
thing->inum = (int)SvIV(ST(1));
sv_setref_pv( tmp, "Inline::Struct::Foo", (void*)obj );
XPUSHs(tmp);
}
else {
SV *tmp;
sv_setiv(tmp, (IV)thing->inum);
XPUSHs(tmp);
}
It's unlikely that Perl will ever see an error. If you said something like
$o->inum('HELLO');
then Perl would write a 0 to that field, since SvIV(newSVpv("HELLO",0))=0.
> Can you nest structures?
Yes, but currently not recursively. And you can only use a pointer to a
struct, you can't directly embed structs. (At least not yet).
Later,
Neil