Class:...hained(3pm)
π Class::Tiny::Chained β the manual, but make it a vibe
okay bestie, so this page is Class:...hained(3pm), from the User Contributed Perl Documentation crew, and it's genuinely one of the cutest little modules out there. Let's get into it. π
β¨ NAME β¨
Class::Tiny::Chained β Minimalist class construction, with chained attributes
no cap, that's the whole pitch. minimal, but the attributes chain. iconic behavior tbh π
πΈ SYNOPSIS πΈ
so in Person.pm you'd do:
package Person;
use Class::Tiny::Chained qw( name );
1;
and then in Employee.pm, you inherit and add a little something extra:
package Employee;
use parent 'Person';
use Class::Tiny::Chained qw( ssn ), {
timestamp => sub { time } # attribute with default
};
1;
π peep that hashref β that's how you give an attribute a default, and the default is a coderef. sub { time } fr fr.
and in example.pl:
use Employee;
my $obj = Employee->new( name => "Larry", ssn => "111-22-3333" );
# attribute setters are chainable
my $obj = Employee->new->name("Fred")->ssn("444-55-6666");
my $ts = $obj->name("Bob")->timestamp;
the way that Employee->new->name("Fred")->ssn("444-55-6666") just flows?? main character energy honestly. π¦
π DESCRIPTION π
Class::Tiny::Chained is a wrapper around Class::Tiny β yes, it's giving "I'm not replacing my bestie, I'm just adding a lil something" β and what it adds is that the generated attribute accessors become chainable.
which means: when you're setting an attribute value, the object itself gets returned back to you, so you can keep calling more methods right on top of it. one line, many setters, zero drama. periodt. β¨
π BUGS π
found a problem? don't suffer in silence, bestie. Report any issues on the public bugtracker.
π«Ά AUTHOR π«Ά
Dan Book <dbook@cpan.org>
ty for your service king π
π COPYRIGHT AND LICENSE π
This software is Copyright (c) 2015 by Dan Book.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)
slay, free software, we love to see it π
π SEE ALSO π
Object::TapMooX::ChainedAttributes
go read those too, iykyk π
and that's the whole page, bestie!! this one shipped as part of perl v5.36.0, dated 2022-12-09 β so yeah, it's been out here being cute and chainable since 2015. take care of her, and remember: setters return the object, so chain responsibly. π
π
π¦ where this page comes from
- debian bookworm: libclass-tiny-chained-perl 0.004-2 Β· Artistic-2.0
- debian trixie: libclass-tiny-chained-perl 0.004-2 Β· Artistic-2.0
- ubuntu noble: libclass-tiny-chained-perl 0.004-2 Β· Artistic-2.0
- ubuntu resolute: libclass-tiny-chained-perl 0.004-2 Β· Artistic-2.0
- ubuntu stonking: libclass-tiny-chained-perl 0.004-2 Β· Artistic-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms