Class::Field(3pm)
π Class::Field π
okay so bestie, welcome to Class::Field β the Class Field Accessor Generator β¨ she makes accessors for you and she is fast, no cap.
πΈ VERSION πΈ
This doc describes Class::Field version 0.24. periodt.
β¨ SYNOPSIS β¨
like, literally just:
package Thing;
use Class::Field qw'field const';
field 'this';
field 'list' => [];
field 'map' => {};
field 'that', -init => '$self->setup_that';
field 'circular_ref' => -weaken;
const 'answer' => 42;
and boom π your class has fields now.
π¦ DESCRIPTION π¦
Class::Field exports two subroutines, field and const. You use these lil cuties to declare fields and constants in your class.
And the vibe check? Class::Field generates custom code for each accessor that is optimized for speed π₯ like she's not just handing you a generic sub, she's hand-crafting it for you. main character energy fr fr.
π FUNCTIONS π
π field
Defines accessor methods for a field of your class. obsessed:
package Example;
use base 'Parent';
use Class::Field qw'field const';
field 'foo';
field bar => [];
sub lalala {
my $self = shift;
$self->foo(42);
push @{$self->{bar}}, $self->foo;
}
The first parameter passed to field is the name of the attribute being defined, iykyk. Accessors can be given an optional default value. This value gets returned if no value for the field has been set in the object β so it's like your lil fallback bestie π«Ά.
π const
const bar => 42;
The const function is similar to field except that it is immutable π« β no touching, no changing. It also does not store data in the object. And ngl, you probably always want to give a const a default value, otherwise the generated method will be somewhat useless π like what is she even doing at that point.
π NOTE π
This code was taken directly out the Spiffy module for those people who just want this functionality without using the rest of Spiffy. so like, if Spiffy is too much for you and you just want the one thing? she's right here π.
π AUTHOR π
Ingy dΓΆt Net <ingy@cpan.org>
π COPYRIGHT AND LICENSE π
Copyright 2006-2019. Ingy dΓΆt Net.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
See <http://www.perl.com/perl/misc/Artistic.html>
and that's the whole page bestie!! this one shipped as part of perl v5.36.0, dated 2022-12-07, filed under Class::Field(3pm) β go forth and field responsibly, ily πβ¨ππ¦
π¦ where this page comes from
- debian bookworm: libclass-field-perl 0.24-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libclass-field-perl 0.24-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libclass-field-perl 0.24-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libclass-field-perl 0.24-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libclass-field-perl 0.24-2 Β· 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