Method...difiers(3pm)

πŸ“¦
this version Β· 3 versions
, in debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– Method::Signatures::Modifiers πŸ’–

okay so bestie, welcome to Method::Signatures::Modifiers, a lil module that lives in the User Contributed Perl Documentation corner of your system. she's a 3pm page and she's here to let you use Method::Signatures from inside MooseX::Declare. yes. that's the whole vibe. πŸ’…


✨ NAME ✨

Method::Signatures::Modifiers β€” use Method::Signatures from within MooseX::Declare.

periodt.


🌸 SYNOPSIS 🌸

use MooseX::Declare;
use Method::Signatures::Modifiers;

class Foo
{
    method bar (Int $thing) {
        # this method is declared with Method::Signatures instead of MooseX::Method::Signatures
    }
}

# -- OR --

use MooseX::Declare;

class My::Declare extends MooseX::Declare
{
    use Method::Signatures::Modifiers;
}

# ... later ...

use My::Declare;

class Fizz
{
    method baz (Int $thing) {
        # this method also declared with Method::Signatures instead of MooseX::Method::Signatures
    }
}

like, look at her go πŸ¦‹ two whole ways to do the thing and both of them ate.


πŸŽ€ DESCRIPTION πŸŽ€

so the whole point: this module lets you use Method::Signatures from within MooseX::Declare β€” and not just for the "method" keyword, but for every single method modifier too: "before", "after", "around", "override", and "augment". the whole squad. πŸ‘‘

normally, method signatures inside MooseX::Declare come from MooseX::Method::Signatures. swapping in Method::Signatures instead gives you a few very real advantages:

  • MooseX::Method::Signatures has a known bug with Perl 5.12.x which does not plague Method::Signatures.
  • Method::Signatures may provide substantially better performance when calling methods, depending on your circumstances.
  • Method::Signatures error messages are somewhat easier to read (and can be overridden more easily).

BUT. and this is a big but, bestie 😭 β€” Method::Signatures cannot be considered a drop-in replacement for MooseX::Method::Signatures. specifically, the following features of MooseX::Method::Signatures are not available to you (or work differently) if you substitute Method::Signatures:

πŸ’€ Types for Invocants

MooseX::Method::Signatures allows code such as this:

method foo (ClassName $class: Int $bar) {
}

Method::Signatures does not allow you to specify a type for the invocant, so your code would change to:

method foo ($class: Int $bar) {
}

so sad, so tragic, no typed invocant for you πŸ₯²

πŸ’€ Parameter Aliasing (Labels)

MooseX::Method::Signatures allows code like this:

# call this as $obj->foo(bar => $baz)
method foo (Int :bar($baz)) {
}

this feature is not currently planned for Method::Signatures. it's giving "we don't do that here" πŸ™ˆ

πŸ’€ Placeholders

MooseX::Method::Signatures allows code like this:

method foo (Int $bar, $, Int $baz) {
    # second parameter not available as a variable here
}

this feature is also not currently planned for Method::Signatures.

however, note that if the parameter you want to ignore is at the end:

method foo (Int $bar, Int $baz, $) {
    # third parameter not available as a variable here
}

then you could write that in Method::Signatures using the "yada yada" pseudo-parameter:

method foo (Int $bar, Int $baz, ...) {
    # third (or greater) parameter(s) not available here
}

the ... really said "and the rest of y'all, idk her" ✨

πŸ’€ Traits

in MooseX::Method::Signatures, "does" is a synonym for "is". Method::Signatures does not honor this. nope. not happening.

Method::Signatures supports several traits that MooseX::Method::Signatures does not.

and flip side: MooseX::Method::Signatures supports the "coerce" trait. Method::Signatures does not currently support this, although it is a planned feature for a future release, potentially using the "does coerce" syntax. manifesting it for future us πŸ•―οΈ


⚠️ BUGS, CAVEATS and NOTES ⚠️

note that although this module causes all calls to MooseX::Method::Signatures from within MooseX::Declare to be completely replaced by calls to Method::Signatures (or calls to Method::Signatures::Modifiers), MooseX::Method::Signatures is still loaded by MooseX::Declare. it's just never used. like, she's at the party but nobody's talking to her πŸ’€

the "compile_at_BEGIN" flag to Method::Signatures is ignored by Method::Signatures::Modifiers. this is because parsing at compile-time can cause method modifiers to be added before the methods they are modifying are composed into the Moose classes. parsing of methods at run-time is compatible with MooseX::Method::Signatures.

like literally do not come for that flag, she's not invited 🚫


🫢 THANKS 🫢

this code was written by Buddy Burden (barefootcoder). absolute legend, no cap πŸ‘‘

the import code for replacing MooseX::Method::Signatures is based on a suggestion from Nick Perez. thank you bestie, we love a collaborative queen 🌈


πŸ“œ LICENSE πŸ“œ

Copyright 2011 by Michael G Schwern <schwern@pobox.com>.

this program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

see http://www.perl.com/perl/misc/Artistic.html


πŸ‘€ SEE ALSO πŸ‘€

MooseX::Declare, Method::Signatures, MooseX::Method::Signatures.


and that's the whole page babes πŸ’– this was Method::Signatures::Modifiers, a perl v5.36.0 situation, last touched 2023-08-20, straight out of the User Contributed Perl Documentation. now go forth and declare your methods, you gorgeous thing 🌸✨

πŸ“¦ where this page comes from