2009年02月14日 08:00 [Edit]

perl - new module - Class::Axelerator

Enjoy!

Dan the Perl Monger

NAME
    Class::Axelerator - Evade OO taxes

VERSION
    $Id: Axelerator.pm,v 0.1 2009/02/13 22:59:21 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
    One of the drawbacks of the Perl's object orientation (POO as follows)
    is that it is its cost. 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 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

        <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/>

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.

この記事へのトラックバックURL

この記事へのコメント
「DESCRIPTION ... is that it is its cost.」 → 「DESCRIPTION ... is its cost.」かな。

Posted by ぶぬ at 2009年02月14日 09:40
ぷぬさん、
文字でどもってどーする>弾。というわけでRepositoryは直しました。
Dan the Dyslexic
Posted by at 2009年02月14日 13:09
「ぷぬさん、」→「ぶぬさん、」かな。
Posted by かっか at 2009年02月14日 13:21