Class:...hained(3pm)

πŸ“¦
version 0.004 Β· 2 versions
  • 0.004 Β· debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking (latest)
  • 0.004 Β· ubuntu jammy
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ‘‘ 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 πŸ‘‘


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::Tap
  • MooX::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. πŸ’…πŸŒŸ