AutoXS::Accessor - Identify accessors and replace them with XS
package MyClass; use AutoXS plugins => 'Accessor'; # or load all installed optimizing plugins use AutoXS ':all'; sub new {...} sub get_foo { $_[0]->{foo} } sub other_stuff {...} # get_foo will be auto-replaced with XS and faster
This is an example plugin module for the AutoXS module. It searches the user package (MyClass above) for read-only accessor methods of certain forms and replaces them with faster XS code.
MyClass
Note that whitespace, a trailing semicolon, and the method names don't matter. Also please realize that this is not a source filter.
sub get_acc { $_[0]->{acc} } sub get_bcc { my $self = shift; $self->{bcc} } sub get_ccc { my $self = shift; return $self->{ccc}; } sub get_dcc { return $_[0]->{dcc} } sub get_ecc { shift->{ecc} } sub get_fcc { my ($self) = @_; $self->{fcc} } sub get_gcc { my ($self) = @_; return $self->{gcc}; } sub get_icc { my ($self) = shift; $self->{icc} } sub get_jcc { my ($self) = shift; return $self->{jcc}; }
AutoXS
Class::XSAccessor
Steffen Mueller, <smueller@cpan.org>
Copyright (C) 2008 by Steffen Mueller
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8 or, at your option, any later version of Perl 5 you may have available.
To install AutoXS, copy and paste the appropriate command in to your terminal.
cpanm
cpanm AutoXS
CPAN shell
perl -MCPAN -e shell install AutoXS
For more information on module installation, please visit the detailed CPAN module installation guide.