Class::Std::Fast(3pm)
π Class::Std::Fast β the perl manual but make it make sense π
okay bestie, welcome to Class::Std::Fast(3pm), the perl module that's literally the same gorgeous API as Class::Std but faster and lowkey less secure about it. yes the name said that, not me. sit down, hydrate, and let's get into it π«Ά
β¨ NAME β¨
Class::Std::Fast β faster but less secure than Class::Std. that's it. that's the whole pitch. she's fast, she's a little reckless, she ate π
πΈ VERSION πΈ
this doc is describing Class::Std::Fast 0.0.8, periodt.
π¦ SYNOPSIS π¦
package MyClass;
use Class::Std::Fast;
1;
package main;
MyClass->new();
boom. that's all it takes to have a whole functioning class. iconic behaviour ngl.
π DESCRIPTION π
so Class::Std::Fast lets you use the beautiful API of Class::Std, except it does the whole thing in a faster way than Class::Std does. same vibes, less drag.
here's the little trick that makes it all work: you can get your object's ident by scalarifying your object. yes, really. just deref it.
getting the object's ident is still possible via the ident method, but bestie, it's faster to just scalarify your object. that's the whole move.
β SUBROUTINES/METHODS β
π« new
the constructor acts like Class::Std's constructor. (want the extended ones? scroll to Constructors below, we got you.)
package FastObject;
use Class::Std::Fast;
1;
my $fast_obj = FastObject->new();
π« ident
if you're using Class::Std::Fast you genuinely should not be using this method. it only exists for downward compatibility. it's giving legacy, respectfully.
# insted of
my $ident = ident $self;
# use
my $ident = ${$self};
(yes the comment says "insted" in the original, we keep the code verbatim, no notes π)
π« initialize
Class::Std::Fast::initialize();
imported straight from Class::Std. go look at the Class::Std documentation for the deets, i'm not gonna retype their whole lore.
π« Methods for accessing Class::Std::Fast's internals
Class::Std::Fast exposes some of its internals so you can build 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. no cap.
π« ID
returns an ID for the next object to construct.
if you ever need to override the constructor that Class::Std::Fast created, be sure to use Class::Std::Fast::ID as the source for the ID you assign to your blessed scalar. no freelancing.
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). and not the cute kind. π
π« ID_GENERATOR_REF
returns a reference to the ID counter scalar.
the current value is the next object ID ! (yes, exclamation mark included, she's excited.)
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 entirely, main character energy).
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 you'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. it's a whole thing.
π 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's there if you need the old can() for speed reasons, and you know what you're doing. that's the whole caveat. respect the caveat.
π§ Constructors
Class::Std::Fast lets you choose between several constructor options. pick your fighter:
- Standard constructor β no special synopsis. acts like
Class::Std's constructor. - Basic constructor
use Class::Std::Fast qw(2);
use Class::Std::Fast constructor => 'basic';
does not call BUILD and START (and does not walk down the inheritance hierarchy calling BUILD and START).
does not perform any attribute initializations.
really fast, but very basic. it's giving speedrun πββοΈ
- No constructor
use Class::Std::Fast qw(3);
use Class::Std::Fast constructor => 'none';
no constructor is exported into the calling class.
the recommended usage is:
use Class::Std::Fast constructor => none;
sub new {
my $self = bless \do { my $foo = Class::Std::Fast::ID } , $_[0];
# do what you need to do after that
}
if you use the Object Cache (see below) the recommended usage is:
use Class::Std::Fast constructor => 'none', cache => 1;
sub new {
my $self = pop @{ Class::Std::Fast::OBJECT_CACHE_REF()->{ $_[0] } }
|| bless \do { my $foo = Class::Std::Fast::ID() } , $_[0];
}
π§ Destructors
Class::Std sorts the @ISA hierarchy before traversing it, so it doesn't clean up the wrong class first. but bestie, this is unnecessary 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
so here's the tea: 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. and Class::Std::Fast does not provide flyweights in the classical sense (one object re-used again and again), but it provides something close to it: an object cache for re-using destroyed objects. recycling era β»οΈ
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 than that), the object to be destroyed is pushed into its 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). slay.
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 addressing performance issues, but it 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 objects that will never be needed again. bestie budgeting πΈ
π DIAGNOSTICS π
see Class::Std.
additional diagnostics are:
Class::Std::Fast loaded too late - put >use Class::Std::Fast< somewhere at the top of your application(warning)
Class::Std has been "use"d before Class::Std::Fast. while both classes happily coexist in one application, Class::Std::Fast must be loaded first for maximum speedup.
this is due to both classes overwriting UNIVERSAL::can. Class::Std::Fast uses the original (fast) can where appropriate, but cannot access it if Class::Std has overwritten it before with its (slow) replacement. tragic. the order matters, bestie. β¨
π CONFIGURATION AND ENVIRONMENT π
(nothing here, she's unbothered, moisturised, in her lane πΈ)
π DEPENDENCIES π
versionClass::StdCarp
π INCOMPATIBILITIES π
see Class::Std
π₯ BUGS AND LIMITATIONS π₯
- you can't use the
:SCALARIFYattribute for your Objects.
we use an increment for building identifiers and not Scalar::Util::refaddr like Class::Std. different girl, different algorithm.
- inheriting from non-
Class::Std::Fastmodules does not work
you cannot inherit from non-Class::Std::Fast classes, not even if you overwrite the default constructor. to be more precise, you cannot inherit from classes which use something different from numeric blessed scalar references as their objects. even so inheriting from similarly constructed classes like Object::InsideOut could work, you would have to make sure that object IDs cannot be duplicated. it is therefore strongly discouraged to build classes with Class::Std::Fast derived from non-Class::Std::Fast classes.
if you really need to inherit from non-Class::Std::Fast modules, make sure you use Class::Std::Fast::ID as described above for creating objects. no shortcuts. π«Ά
- no runtime initialization with
constructor => 'basic'/'none'
when eval'ing Class::Std::Fast based classes using the basic constructor, make sure the last line is
Class::Std::Fast::initialize();
in contrast to Class::Std, Class::Std::Fast performs no run-time initialization when the basic constructor is enabled, so your code has to do it itself. self-care, but for your module.
the same holds true for constructor => 'none', of course.
CUMULATIVE, PRIVATE, RESTRICTED and anticumulative methods won't work if you leave out this line.
πΌ 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>
the icons who built her π
π 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.
and that's the whole page, bestie!! this lovely little doc came to you courtesy of perl v5.36.0, dated 2022-11-19 β Class::Std::Fast(3pm), signed, sealed, delivered. now go scalarify something and be free π¦β¨π
π¦ where this page comes from
- debian bookworm: libclass-std-fast-perl 0.0.8-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libclass-std-fast-perl 0.0.8-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libclass-std-fast-perl 0.0.8-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libclass-std-fast-perl 0.0.8-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libclass-std-fast-perl 0.0.8-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms