Class:...:Class(3pm)
β¨ Class::...:Class(3pm) β¨
okay bestie, so this page is from the User Contributed Perl Documentation corner of your friendly neighborhood perl install, and it's all about Class::Accessor::Class π. Sit down, grab a boba, we're doing class variables today π§
π« NAME π«
Class::Accessor::Class β simple class variable accessors, no cap πΈ
π VERSION π
version 0.504 β yeah it's giving vintage, we'll get to that π
π¦ SYNOPSIS π¦
So like, first you set up a module with class accessors:
package Text::Fortune;
use base qw(Class::Accessor::Class Exporter);
Robot->mk_class_accessors(qw(language offensive collection));
sub fortune {
if (__PACKAGE__->offensive) {
..
not me leaving Robot-> exactly as the original wrote it π bestie I am not touching the source text, that's the whole rule
Then, when you're using the module:
use Text::Fortune;
Text::Fortune->offensive(1);
print fortune; # prints an offensive fortune
Text::Fortune->language('EO');
print fortune; # prints an offensive fortune in Esperanto
and yes the comments say what they say, we keep them fr fr π«Ά
π DESCRIPTION π
Class::Accessor::Class gives you a simple way to make accessor and mutator methods for class variables, literally exactly like Class::Accessor does for objects. Same energy, different target π. And it can use either:
- an enclosed lexical variable, or
- a package variable
your choice, main character behavior β¨
Now the lore π: this module was once implemented in terms of Class::Accessor, but changes to that module broke the whole relationship π. Class::Accessor::Class is still a subclass of Class::Accessor, strictly for historical reasons β it's giving "we stay together for the kids" ngl. But as a side benefit: any class that isa Class::Accessor::Class is also a Class::Accessor and can use its methods. iconic, we love a functional situationship π
π PERL VERSION SUPPORT π
okay so this is the part where I have to be real with you bestie π«Ά
This code is effectively abandonware. Releases will sometimes be made to update contact info or to fix packaging flaws, but bug reports will mostly be ignored. And feature requests? even more likely to be ignored π
(If someone takes up maintenance of this code, they will presumably remove this notice.)
so yeah. it's giving "left on read" but for your CPAN tickets π
π METHODS π
mk_class_accessors
package Foo;
use base qw(Class::Accessor::Class);
Foo->mk_class_accessors(qw(foo bar baz));
Foo->foo(10);
my $obj = new Foo;
print $obj->foo; # 10
This method adds accessors for the named class variables. And here's the tea β: the accessor will get or set a lexical variable to which the accessor is the only access. exclusive. private. one-accessor-one-variable. no sharing, no drama π
mk_package_accessors
package Foo;
use base qw(Class::Accessor::Class);
Foo->mk_package_accessors(qw(foo bar baz));
Foo->foo(10);
my $obj = new Foo;
print $obj->foo; # 10
print $Foo::foo; # 10
This method also adds accessors for the named class variables, but the accessor gets or sets the named variable in the package's symbol table β so it's out there, publicly visible, $Foo::foo and all πΈ
π₯ DETAILS π₯
make_class_accessor
$accessor = Class->make_class_accessor($field);
This method generates a subroutine reference which acts as an accessor for the named field. that's it, that's the whole vibe β¨
make_package_accessor
$accessor = Class->make_package_accessor($field);
This method generates a subroutine reference which acts as an accessor for the named field, which is stored in the scalar named field in Class's symbol table.
This can be useful for dealing with legacy code π§ β but ngl, using package variables is almost never a good idea for new code.
Use this with care. π
π AUTHOR π
Ricardo SIGNES <rjbs@semiotic.systems>
πΈ COPYRIGHT AND LICENSE πΈ
This software is copyright (c) 2004 by Ricardo SIGNES.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
okay that's the whole page bestie, you ate it, go make some class accessors π«Άβ¨
signing off from the perl v5.32.1 era, dated 2021-09-12, and yeah this whole thing lives in the Class:...:Class(3pm) manual section π mwah π
π¦ where this page comes from
- debian bookworm: libclass-accessor-class-perl 0.504-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libclass-accessor-class-perl 0.504-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu jammy: libclass-accessor-class-perl 0.504-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libclass-accessor-class-perl 0.504-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libclass-accessor-class-perl 0.504-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libclass-accessor-class-perl 0.504-1 Β· 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