Moose::...it::Code(3)

πŸ’– Moose::Meta::Attribute::Native::Trait::Code β€” the whole vibe

okay bestie, so this is a page from your friendly neighborhood User Contributed Perl Documentation section (section 3, the library-calls one, iykyk). It's the manual for Moose::Meta::Attribute::Native::Trait::Code, aka the helper trait that makes your CodeRef attributes do tricks. Let's get into it πŸ’…


✨ NAME ✨

Moose::Meta::Attribute::Native::Trait::Code β€” the helper trait for CodeRef attributes. That's it, that's the name, no notes πŸŽ€


πŸ¦‹ VERSION πŸ¦‹

version 2.4000


🌸 SYNOPSIS 🌸

okay so here's the whole setup, and honestly? it ate:

package Foo;
use Moose;

has 'callback' => (
    traits  => ['Code'],
    is      => 'ro',
    isa     => 'CodeRef',
    default => sub {
        sub { print "called" }
    },
    handles => {
        call => 'execute',
    },
);

my $foo = Foo->new;
$foo->call;    # prints "called"

like, you hand it traits => ['Code'] and suddenly your coderef attribute has main character energy and comes with free delegation methods. periodt πŸ’–


πŸ‘‘ DESCRIPTION πŸ‘‘

This trait provides native delegation methods for code references. fr fr, that's its whole job and it does it flawlessly ✨


πŸ’œ DEFAULT TYPE πŸ’œ

If you don't provide an isa value for your attribute, it will default to CodeRef. So like, it already knows what you meant, no need to over-explain yourself 🫢


πŸŽ€ PROVIDED METHODS πŸŽ€

the girls that get it, get it β€” here's what you actually get:

  • execute(@args) β€” Calls the coderef with the given args. Simple. Iconic. Does exactly what it says on the tin πŸ”₯
  • execute_method(@args) β€” Calls the coderef with the instance as invocant and given args. So the object shows up first like the main character it is πŸ‘‘

πŸ’€ BUGS πŸ’€

See BUGS in Moose for details on reporting bugs. Go snitch, bestie, they wanna know πŸ™ˆ


🌈 AUTHORS 🌈

the whole squad, the legends, the founding mothers and fathers of your delegation dreams:

  • 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>

not me getting emotional over a contributor list 😭 icons only


This software is copyright (c) 2006 by Infinity Interactive, Inc.

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

tl;dr it's free, go wild, just keep the same terms as Perl 5 itself and we're good πŸ’–

and that's the whole page, bestie! πŸ’… this was shipped as part of perl v5.42.0, dated 2025-07-25, and now you know everything the manual knows. slay, go call some coderefs πŸ¦‹βœ¨πŸ“

πŸ“¦ where this page comes from