Skip Menu |

This queue is for tickets about the Class-XSAccessor CPAN distribution.

Report information
The Basics
Id: 61283
Status: open
Priority: 0/
Queue: Class-XSAccessor

People
Owner: Nobody in particular
Requestors: alim [...] gmx.net
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: (no value)



Subject: Would be nice to have a slightly advanced constructor
Quite often I have two requirements for the constructor. The first is to be able to pass either a hash ref or a list of key value pairs. Something along the lines of defined $_[0] && UNIVERSAL::isa($_[0], 'HASH') ? shift : { @_ }; The second requirement is to have the whole initialisation done by an init method. Then the constructor must have something like $self->$init_method(@_); at the end, of course. additional parameters for this could be init_method => '_init', allow_hashref_for_initialisation => 1, allow_hashref_for_initialisation would affect either the constructor or the init_method if set. Of course I can always write my own constructor and/or init-method as I do now but it would be nice to have it together with the accessor definitions and perhaps it is also a bit faster.
Subject: Re: [rt.cpan.org #61283] Would be nice to have a slightly advanced constructor
Date: Mon, 13 Sep 2010 09:22:12 +0200
To: bug-Class-XSAccessor [...] rt.cpan.org
From: Steffen Mueller <smueller [...] cpan.org>
Hi, Michael Lackhoff via RT wrote: Show quoted text
> Sun Sep 12 04:50:45 2010: Request 61283 was acted upon. > Transaction: Ticket created by michaell > Queue: Class-XSAccessor > Subject: Would be nice to have a slightly advanced constructor
Show quoted text
> Quite often I have two requirements for the constructor. > The first is to be able to pass either a hash ref or a list of key value > pairs. Something along the lines of > > defined $_[0] && UNIVERSAL::isa($_[0], 'HASH') ? shift : { @_ }; > > The second requirement is to have the whole initialisation done by an > init method. Then the constructor must have something like > $self->$init_method(@_); > at the end, of course. > > additional parameters for this could be > init_method => '_init', > allow_hashref_for_initialisation => 1, > > allow_hashref_for_initialisation would affect either the constructor or > the init_method if set. > > Of course I can always write my own constructor and/or init-method as I > do now but it would be nice to have it together with the accessor > definitions and perhaps it is also a bit faster.
thanks for the wishlist item. Unfortunately, I don't think this will happen. Having such an init method would essentially negate the benefit of having a constructor written in XS in the first place. Additionally, due to the way the module is written, adding more special cases for method generation does incur both significant work and some extra run-time overhead. Instead, I suggest you fall back to writing custom constructors for these cases. I'll consider the allow-hashref-instead of key/value pairs case if I find copious spare time for hacking, but even that seems fairly unlikely. (Your one line of Perl is bound to become a significant bit of C.) I'll keep the ticket open for future consideration. Best regards, Steffen
... many years pass ... You could check out Class::XSConstructor.