Class:...ntlers(3pm)

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

✨ NAME ✨

Class::Tiny::Antlers β€” Moose-like sugar for Class::Tiny, and yes bestie it's giving exactly what you think it's giving πŸ’…

It's a Perl module, Class:...ntlers(3pm) if you're looking it up in the man pages, and it exists purely to make Class::Tiny feel like its glamorous Moose cousin.


🌸 SYNOPSIS 🌸

{
   package Point;
   use Class::Tiny::Antlers;
   has x => (is => 'ro');
   has y => (is => 'ro');
}

{
   package Point3D;
   use Class::Tiny::Antlers;
   extends 'Point';
   has z => (is => 'ro');
}

Look at that. Clean. Cozy. No boilerplate trauma. 🫢


πŸ’– DESCRIPTION πŸ’–

Okay so here's the tea: Class::Tiny::Antlers hands you Moose-like has, extends, with, before, after and around keywords, but for Class::Tiny. Best of both worlds fr fr.

Heads up though: the with keyword needs Role::Tiny, and the method modifiers need Class::Method::Modifiers. Not optional. That's the deal. πŸ™ˆ

Now, Class::Tiny does not support every single Moose attribute option in existence, and has should throw you an error if you try to do something it doesn't support (like triggers). So don't come for it when it yells at you, it's literally just doing its job. πŸ’€

But here's where it gets cute: Class::Tiny::Antlers does hack in support for is => 'ro' and Moo-style is => 'rwp', plus clearers and predicates. Slay. ✨

And from version 0.24, Class::Tiny::Antlers also adds support for isa and coerce using Type::Tiny. (I mean, this is a TOBYINK module, so what do you expect?!) πŸ‘‘ Technically MooseX::Types, MouseX::Types, Specio, and Type::Nano should work too, but those are less tested. Lowkey experimental energy, you've been warned.


πŸŽ€ Export πŸŽ€

By default, Class::Tiny::Antlers exports has, with and extends, and it also imports strict into its caller. Free strict, no cap. πŸ”₯

You can optionally also import confess and warnings:

use Class::Tiny::Antlers qw( -default confess warnings );

And you can pull in the Class::Method::Modifiers keywords:

use Class::Tiny::Antlers qw( -default before after around );
use Class::Tiny::Antlers qw( -default -cmm );  # same thing

(Yes those two lines do the exact same thing. -cmm is just the shorthand, iykyk.)

And if you just want everything:

use Class::Tiny::Antlers qw( -all );

Go off, main character. 🌈

Class::Tiny::Antlers also makes sure that Class::Tiny's import method gets called for your class. It's got your back.

Oh and btw, you can drop a no Class::Tiny::Antlers statement at the end of your class definition to wipe the imported functions right out of your namespace. Poof. Gone. πŸ¦‹

Careful though: this does not unimport strict/warnings. Those are staying, bestie. If you want a thorough namespace cleanup, use something like namespace::sweep.

🧚 Functions 🧚

  • has $attr, %spec β€” Creates an attribute. The specification hash roughly supports is, default, clearer and predicate as per Moose and Moo.
  • extends @classes β€” Sets the base class(es) for your class. Your whole lineage, sorted. πŸ‘‘
  • with @roles β€” Composes Role::Tiny roles with your class. Mixing in that flavor. πŸ“
  • before $name, \&code β€” Installs a before modifier using Class::Method::Modifiers.
  • after $name, \&code β€” Installs a after modifier using Class::Method::Modifiers.
  • around $name, \&code β€” Installs a around modifier using Class::Method::Modifiers.
  • confess $format, @list β€” A sprintf-fueled version of Carp's confess. It will tell you what went wrong, and it will do it with formatting. 😭

πŸ’œ Methods πŸ’œ

Class::Tiny::Antlers inherits the get_all_attributes_for and get_all_attribute_defaults_for methods from Class::Tiny, and it also provides this one:

  • Class::Tiny::Antlers->get_all_attribute_specs_for($class) β€” Gets Moose-style attribute specification hashes for all the class' attributes as one big hashref. (Includes inherited attributes, so you get the whole family tree, not just the immediate vibes.) 🌸

πŸ’€ BUGS πŸ’€

Please report any bugs to <http://rt.cpan.org/Dist/Display.html?Queue=Class-Tiny-Antlers>.

Not me asking you to snitch, but like... kindly. πŸ™ˆ


⭐ SEE ALSO ⭐

Class::Tiny, Role::Tiny, Class::Method::Modifiers, Type::Tiny::Manual.

Moose, Mouse, Moo.

The whole friend group, honestly. 🫢


πŸ‘‘ AUTHOR πŸ‘‘

Toby Inkster <tobyink@cpan.org>.


This software is copyright (c) 2013, 2019 by Toby Inkster.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.


πŸŽ€ DISCLAIMER OF WARRANTIES πŸŽ€

THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.

Read it and weep, because there's genuinely no warranty. It said what it said. πŸ’…


That's the whole page, bestie β€” perl v5.36.0, dated 2022-12-08, from the Class:...ntlers(3pm) corner of the User Contributed Perl Documentation. Go write some attributes, you absolute icon. βœ¨πŸ¦‹πŸ’–

πŸ“¦ where this page comes from