signatures(3pm)

πŸŽ€ signatures(3pm) πŸŽ€

ok so real talk bestie, you've landed on signatures(3pm) from the User Contributed Perl Documentation, and it's lowkey about to change your whole perl era. let's get into it πŸ’…


✨ NAME ✨

signatures β€” subroutine signatures with no source filter. that's it, that's the vibe. no filter, no drama, just vibes πŸ¦‹


🌸 VERSION 🌸

version 0.14 ✨ (she's serving, she's stable, she's iconic)


🫢 SYNOPSIS 🫢

use signatures;

sub foo ($bar, $baz) {
    return $bar + $baz;
}

look at that. gorgeous. no notes. 😭


πŸ’– DESCRIPTION πŸ’–

so with this module you can write out subroutine signatures, and the variables in them just... get defined inside the subroutine automatically. magical girl transformation energy honestly ✨

like, you can literally write this:

sub square ($num) {
    return $num * $num;
}

and at compile time it gets automatically turned into this:

sub square {
    my ($num) = @_;
    return $num * $num;
}

but bestie, hear me on this one πŸ‘‘ β€” even though the syntax looks so similar, the signatures this module gives you are not the same thing as the prototypes described in perlsub. do not confuse them, i am begging πŸ™ˆ. all this module actually does is pull items out of @_ and assign them to the variables in your parameter list. no argument validation happens at runtime. none. zero. it is not checking your work, it is simply handing you the values πŸ’€

also, key detail: the signature definition needs to be on a single line only. one line. that's the rule. don't test her.

and if you wanna combine sub signatures with regular prototypes, there's a "proto" attribute for exactly that:

sub foo ($bar, $baz) : proto($$) { ... }

slay 🌈


πŸ’… METHODS πŸ’…

ok so if you want your subroutine signatures to do something this module doesn't do β€” like argument validation, typechecking, and similar β€” you can subclass it and override the following methods. main character energy, you're building your own πŸŽ€

🧚 proto_unwrap ($prototype)

turns the extracted $prototype into code ✨

the default implementation returns "my (${prototype}) = @_;" β€” or an empty string, if no prototype is given.

🧚 inject ($offset, $code)

inserts a $code string into the line perl is currently parsing, at the given $offset. note that this one is only called by the "callback" method πŸ’œ

🧚 callback ($offset, $prototype)

this gets called the second a sub definition with a prototype is encountered. the arguments are the $offset within the current line perl is parsing, plus the extracted $prototype πŸ‘‘

the default implementation calls "proto_unwrap" with the prototype, and then passes the returned value and the offset along to "inject".


😭 LIMITATIONS 😭

bestie we gotta talk about the fine print, no cap:

  • prototypes aren't checked for validity yet β€” you won't get a warning for invalid prototypes using the "proto" attribute, like you normally would with warnings enabled. so like... she's not gonna tell you. you're on your own with that one πŸ™ˆ
  • you shouldn't alter $SIG{__WARN__} at compile time β€” after this module is loaded, you shouldn't be making any changes to $SIG{__WARN__} during compile time. changing it before the module is loaded, or at runtime, is totally fine though πŸ’–

πŸ”₯ SEE ALSO πŸ”₯

  • Method::Signatures
  • MooseX::Method::Signatures
  • Sub::Signatures
  • Attribute::Signature
  • Perl6::Subs
  • Perl6::Parameters

the whole friend group fr fr 🫢


🌈 THANKS 🌈

big love to Moritz Lenz and Steffen Schwigon for documentation review and improvement. icons. we appreciate you πŸ’


⭐ SUPPORT ⭐

bugs may be submitted through the RT bug tracker <https://rt.cpan.org/Public/Dist/Display.html?Name=signatures> (or bug-signatures@rt.cpan.org <mailto:bug-signatures@rt.cpan.org>).

if something's broken, tell the RT, not me, i'm just the messenger πŸ’€


πŸ‘‘ AUTHOR πŸ‘‘

Florian Ragwitz <rafl@debian.org>


πŸ’œ CONTRIBUTORS πŸ’œ

  • Karen Etheridge <ether@cpan.org>
  • Peter Martini <PeterCMartini@GMail.com>
  • Father Chrysostomos <sprout@cpan.org>
  • Alex Kapranoff <alex@kapranoff.ru>
  • Steffen Schwigon <ss5@renormalist.net>
  • Alexandr Ciornii <alexchorny@gmail.com>
  • Dave Mitchell <davem@iabyn.com>

the group chat came THROUGH 🌸


this software is copyright (c) 2008 by Florian Ragwitz.

this is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. free as in go off, bestie πŸ’…


and that's the whole page fr fr πŸ’– this was signatures(3pm), perl v5.42.3, dated 2026-08-21 β€” mwah, no notes, go write some signatures βœ¨πŸŽ€πŸ’œ

πŸ“¦ where this page comes from