Andreas 'ac0v' Specht > Class-Std-Fast-v0.0.8 > Class::Std::Fast

Download:
Class-Std-Fast-v0.0.8.tar.gz

Dependencies

Annotate this POD

CPAN RT

Open  1
View/Report Bugs
Module Version: v0.0.8   Source  

NAME ^

Class::Std::Fast - faster but less secure than Class::Std

VERSION ^

This document describes Class::Std::Fast 0.0.8

SYNOPSIS ^

    package MyClass;

    use Class::Std::Fast;

    1;

    package main;

    MyClass->new();

DESCRIPTION ^

Class::Std::Fast allows you to use the beautiful API of Class::Std in a faster way than Class::Std does.

You can get the object's ident via scalarifiyng your object.

Getting the objects ident is still possible via the ident method, but it's faster to scalarify your object.

SUBROUTINES/METHODS ^

new

The constructor acts like Class::Std's constructor. For extended constructors see Constructors below.

    package FastObject;
    use Class::Std::Fast;

    1;
    my $fast_obj = FastObject->new();

ident

If you use Class::Std::Fast you shouldn't use this method. It's only existant for downward compatibility.

    # insted of
    my $ident = ident $self;

    # use
    my $ident = ${$self};

initialize

    Class::Std::Fast::initialize();

Imported from Class::Std. Please look at the documentation from Class::Std for more details.

Methods for accessing Class::Std::Fast's internals

Class::Std::Fast exposes some of it's internals to allow the construction of Class::Std::Fast based objects from outside the auto-generated constructors.

You should never use these methods for doing anything else. In fact you should not use these methods at all, unless you know what you're doing.

ID

Returns an ID for the next object to construct.

If you ever need to override the constructor created by Class::Std::Fast, be sure to use Class::Std::Fast::ID as the source for the ID to assign to your blessed scalar.

More precisely, you should construct your object like this:

    my $self = bless \do { my $foo = Class::Std::Fast::ID } , $class;

Every other method of constructing Class::Std::Fast - based objects will lead to data corruption (duplicate object IDs).

ID_GENERATOR_REF

Returns a reference to the ID counter scalar.

The current value is the next object ID !

You should never use this method unless you're trying to create Class::Std::Fast objects from outside Class::Std::Fast (and possibly outside perl).

In case you do (like when creating perl objects in XS code), be sure to post-increment the ID counter after creating an object, which you may do from C with

    sv_inc( SvRV(id_counter_ref) )

OBJECT_CACHE_REF

Returns a reference to the object cache.

You should never use this method unless your're trying to (re-)create Class::Std::Fast objects from outside Class::Std::Fast (and possibly outside perl).

See <L/EXTENSIONS TO Class::Std> for a description of the object cache facility.

EXTENSIONS TO Class::Std ^

Methods

real_can

Class::Std::Fast saves away UNIVERSAL::can as Class::Std::Fast::real_can before overwriting it. You should not use real_can, because it does not check for subroutines implemented via AUTOMETHOD.

It is there if you need the old can() for speed reasons, and know what you're doing.

Constructors

Class::Std::Fast allows the user to chose between several constructor options.

Destructors

Class::Std sorts the @ISA hierarchy before traversing it to avoid cleaning up the wrong class first. However, this is unneccessary if the class in question has a linear inheritance tree.

Class authors may disable sorting by calling

 use Class::Std::Fast unsorted => 1;

Use only if you know your class' complete inheritance tree...

Object Cache

Synopsis

 use Class::Std::Fast cache => 1;

Description

While inside out objects are basically an implementation of the Flyweight Pattern (object data is stored outside the object), there's still one aspect missing: object reuse. While Class::Std::Fast does not provide flyweights in the classical sense (one object re-used again and again), it provides something close to it: An object cache for re-using destroyed objects.

The object cache is implemented as a simple hash with the class names of the cached objects as keys, and a list ref of cached objects as values.

The object cache is filled by the DESTROY method exported into all Class::Std::Fast based objects: Instead of actually destroying the blessed scalar reference (Class::Std::Fast based objects are nothing more), the object to be destroyed is pushed into it's class' object cache.

new() in turn does not need to create a new blessed scalar, but can just pop one off the object cache (which is a magnitude faster).

Using the object cache is recommended for persistent applications (like running under mod_perl), or applications creating and destroying lots of Class::Std::Fast based objects again and again.

The exported constructor automatically uses the Object Cache when caching is enabled by setting the cache import flag to a true value.

For an example of a user-defined constructor see "Constructors" above.

Memory overhead

The object cache trades speed for memory. This is a very perlish way for adressing performance issues, but may cause your application to blow up if you're short of memory.

On a 32bit Linux, Devel::Size reports 44 bytes for a Class::Std::Fast based object - so a cache containing 1 000 000 (one million) of objects needs around 50MB of memory (Devel Size only reports the memory use it can see - the actual usage is system dependent and something between 4 and 32 bytes more).

If you are anxious about falling short of memory, only enable caching for those classes whose objects you know to be frequently created and destroyed, and leave it turned off for the less frequently used classes - this gives you both speed benefits, and avoids holding a cache of object that will never be needed again.

DIAGNOSTICS ^

see Class::Std.

Additional diagnostics are:

CONFIGURATION AND ENVIRONMENT ^

DEPENDENCIES ^

INCOMPATIBILITIES ^

see Class::Std

BUGS AND LIMITATIONS ^

RCS INFORMATIONS ^

Last changed by

$Author: ac0v $

Id

$Id: Fast.pm 469 2008-05-26 11:26:35Z ac0v $

Revision

$Revision: 469 $

Date

$Date: 2008-05-26 13:26:35 +0200 (Mon, 26 May 2008) $

HeadURL

$HeadURL: file:///var/svn/repos/Hyper/Class-Std-Fast/branches/0.0.8/lib/Class/Std/Fast.pm $

AUTHORS ^

Andreas 'ac0v' Specht <ACID@cpan.org>

Martin Kutter <martin.kutter@fen-net.de>

LICENSE AND COPYRIGHT ^

Copyright (c) 2007, Andreas Specht <ACID@cpan.org>. All rights reserved.

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

syntax highlighting: