Class::Axelerator - Evade OO taxes
$Id: Axelerator.pm,v 0.2 2009/02/15 02:25:03 dankogai Exp dankogai $
my $obj = Klass->new(name => 'anon'); use Class::Axelerator; $obj->name eq 'anon' or die; # $obj->{name} ... $obj->name() eq 'anon' or die; # $obj->name() ...; no change $obj->pass = 'ymous'; # $obj->{pass} = .... no Class::Axelerator;
Perl's object orientation (POO as follows) is powerful, flexible and ... expensive. Since all methods are implemented as function calls, even simple accessors are 2-4 times more costly than non OO approach. Simply put,
my $attr = $obj->attr;
is 2-4x costlier than
my $attr = $obj->{attr};
This module axelerates the code by replacing all occurance of ->whatever with ->{whatever}, while ->whatever() remains intact.
->whatever
->{whatever}
->whatever()
Since the blessed hash reference is the de-facto POO standard, this accelerates most cases. This is true for Class::Accessor and its friends and even Moose and its family.
Whenever you want to call the method, just append ().
()
It is recommended that you end the section to axelerate with no Class::Axelerator. This module is NOT LEXICAL and its effect spans till the end of source without it.
no Class::Axelerator
Here is a result of simple benchmark on my MacBook Pro. See t/benchmark.pl.
Rate normal axelerated normal 1035642/s -- -78% axelerated 4797439/s 363% --
Rate normal axelerated normal 920425/s -- -80% axelerated 4691781/s 410% --
Rate normal axelerated normal 1281574/s -- -72% axelerated 4637948/s 262% --
It comes naturally since this module accelerates accessors/mutators by axing encapslulation.
None. This is a source filter module.
Dan Kogai, <dankogai at dan.co.jp>
<dankogai at dan.co.jp>
Tax evasion is considered felony in most countries and territories :)
Even in the Programming Republic of Perl, it is considered a bad practice.
Please report any bugs or feature requests to bug-class-axelerator at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Class-Axelerator. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-class-axelerator at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc Class::Axelerator
You can also look for information at:
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Class-Axelerator
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/Class-Axelerator
CPAN Ratings
http://cpanratings.perl.org/d/Class-Axelerator
Search CPAN
http://search.cpan.org/dist/Class-Axelerator/
Proof of concept http://blog.livedoor.jp/dankogai/archives/51077786.html
Copyright 2009 Dan Kogai, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Class::Axelerator, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Class::Axelerator
CPAN shell
perl -MCPAN -e shell install Class::Axelerator
For more information on module installation, please visit the detailed CPAN module installation guide.