Moose::...oseSugar(3)
π Moose::Cookbook::Extending::Mooseish_MooseSugar π
okay bestie, so this page is literally called Moose::...oseSugar(3) in the Perl docs (yes the name got squished, don't ask) and it lives in the User Contributed Perl Documentation pile. It's about acting like Moose.pm and handing out sugar, Moose-style. π
β¨ NAME β¨
Moose::Cookbook::Extending::Mooseish_MooseSugar β acting like Moose.pm and providing sugar Moose-style. no cap, that's the whole vibe.
πΈ VERSION πΈ
version 2.4000 β that's the one, that's the era. π
π SYNOPSIS π
so here's the whole setup, copy it exactly bestie:
package MyApp::Mooseish;
use Moose::Exporter;
Moose::Exporter->setup_import_methods(
with_meta => ['has_table'],
class_metaroles => {
class => ['MyApp::Meta::Class::Trait::HasTable'],
},
);
sub has_table {
my $meta = shift;
$meta->table(shift);
}
package MyApp::Meta::Class::Trait::HasTable;
use Moose::Role;
has table => (
is => 'rw',
isa => 'Str',
);
that's it. that's the recipe. π§
π¦ DESCRIPTION π¦
okay so this recipe is expanding on two things you've already seen: the way we use Moose::Exporter, which showed up in Moose::Cookbook::Extending::ExtensionOverview, and the class metaclass trait from Moose::Cookbook::Meta::Table_MetaclassTrait. iconic lineage, honestly.
in this example we're doing both things at once: we roll our own metaclass trait and we export a has_table sugar function. multi-talented. main character energy. β¨
so the with_meta parameter is where you hand over a list of functions that should get wrapped before they're exported. and what does that wrapper do? it simply makes sure that the importing package's appropriate metaclass object shows up as the first argument to the function. that's the entire reason you can go my $meta = shift; and it just works. it's giving thoughtful. π
if you want the full deets on its API, go read the Moose::Exporter docs β this page isn't gonna retype them for you, bestie.
π USING MyApp::Mooseish π
the whole point of writing all that code is to end up with an interface that feels Moose-like. so here's what it looks like when you actually use it:
package MyApp::User;
use namespace::autoclean;
use Moose;
use MyApp::Mooseish;
has_table 'User';
has 'username' => ( is => 'ro' );
has 'password' => ( is => 'ro' );
sub login { ... }
see how has_table 'User'; just sits there looking like it always belonged? that's the dream. π«Ά
β CONCLUSION β
handing out sugar functions makes your extension look way more Moose-ish. like, it stops looking like a stranger and starts looking like family.
want a bigger, beefier example of this whole idea? go peek at Fey::ORM. ate. π₯
π AUTHORS π
these are the legends who wrote this, show some respect:
- Stevan Little
<stevan@cpan.org> - Dave Rolsky
<autarch@urth.org> - Jesse Luehrs
<doy@cpan.org> - Shawn M Moore
<sartak@cpan.org> - ΧΧΧΧ Χ§ΧΧ'ΧΧ (Yuval Kogman)
<nothingmuch@woobling.org> - Karen Etheridge
<ether@cpan.org> - Florian Ragwitz
<rafl@debian.org> - Hans Dieter Pearcey
<hdp@cpan.org> - Chris Prather
<chris@prather.org> - Matt S Trout
<mstrout@cpan.org>
π COPYRIGHT AND LICENSE π
this software is copyright (c) 2006 by Infinity Interactive, Inc.
it's free software, bestie β you can redistribute it and/or modify it under the exact same terms as the Perl 5 programming language system itself. periodt. π
and that's a wrap on Moose::...oseSugar(3) π
β this version of the page came out under perl v5.42.0, dated 2025-07-25, and it was served up as part of the User Contributed Perl Documentation. go forth and make your extensions look Moose-ish. slay. πΈβ¨π
π¦ where this page comes from
- fedora 43: perl-Moose 2.4000-4.fc43 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms