NAME
Class::Axelerator - Evade OO taxes
VERSION
$Id: Axelerator.pm,v 0.2 2009/02/15 02:25:03 dankogai Exp dankogai $
SYNOPSIS
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;
DESCRIPTION
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.
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.
BENCHMARK
Here is a result of simple benchmark on my MacBook Pro. See t/benchmark.pl.
- Accessor
-
Rate normal axelerated normal 1035642/s -- -78% axelerated 4797439/s 363% --
- Mutator
-
Rate normal axelerated normal 920425/s -- -80% axelerated 4691781/s 410% --
- Lvalue Mutator
-
Rate normal axelerated normal 1281574/s -- -72% axelerated 4637948/s 262% --
Axelerate?
It comes naturally since this module accelerates accessors/mutators by axing encapslulation.
EXPORT
None. This is a source filter module.
AUTHOR
Dan Kogai, <dankogai at dan.co.jp>
BUGS
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.
SUPPORT
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
AnnoCPAN: Annotated CPAN documentation
CPAN Ratings
Search CPAN
ACKNOWLEDGEMENTS
Proof of concept http://blog.livedoor.jp/dankogai/archives/51077786.html
COPYRIGHT & LICENSE
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.