MouseX...CodeRef(3pm)

πŸ“¦
version 1.09 Β· 4 versions
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– NAME πŸ’–

MouseX::NativeTraits::CodeRef β€” bestie, it's a helper trait for CodeRef attributes. That's the whole vibe. It's a page from the User Contributed Perl Documentation corner of the manual, and it's giving "small but mighty." ✨


πŸŽ€ SYNOPSIS πŸŽ€

okay so picture this: you've got a class, and you want an attribute that is literally a function. Watch:

package Foo;
use Mouse;

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

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

So traits => ['Code'] is you opting into this trait, isa => 'CodeRef' keeps it honest, and the handles bit maps a method name (call) onto an operation this trait hands you (execute). Then $foo->call just... runs the thing. And it prints called. No cap. πŸ’…


🌸 DESCRIPTION 🌸

This provides operations on coderef attributes. That's it, that's the whole description, and honestly? Iconic minimalism. It exists so your coderef attributes can do stuff instead of just sitting there being a blessed reference. πŸ¦‹


✨ PROVIDED METHODS ✨

  • execute(@args) β€” Calls the coderef with the given args. Yeah, that's it. You pass it args, it feeds them straight into your coderef. Simple, clean, does exactly what it says on the tin. 🫢

πŸ’… METHODS πŸ’…

these are the methods, no notes:

  • meta
  • method_provider_class
  • helper_type

πŸ‘‘ SEE ALSO πŸ‘‘

  • MouseX::NativeTraits β€” the main character. Go read that one next, fr fr. πŸ’œ

and that's the whole page, bestie πŸŽ€ this one came from the User Contributed Perl Documentation, version perl v5.34.0, dated 2022-06-16, and it's filed under MouseX...CodeRef(3pm) β€” go forth and call your coderefs πŸ’–βœ¨πŸŒˆ

πŸ“¦ where this page comes from