.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.40) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "signatures 3pm" .TH signatures 3pm "2020-11-09" "perl v5.32.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" signatures \- Subroutine signatures with no source filter .SH "VERSION" .IX Header "VERSION" version 0.14 .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use signatures; \& \& sub foo ($bar, $baz) { \& return $bar + $baz; \& } .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" With this module, we can specify subroutine signatures and have variables automatically defined within the subroutine. .PP For example, you can write .PP .Vb 3 \& sub square ($num) { \& return $num * $num; \& } .Ve .PP and it will be automatically turned into the following at compile time: .PP .Vb 4 \& sub square { \& my ($num) = @_; \& return $num * $num; \& } .Ve .PP Note that, although the syntax is very similar, the signatures provided by this module are not to be confused with the prototypes described in perlsub. All this module does is extracting items of \f(CW@_\fR and assigning them to the variables in the parameter list. No argument validation is done at runtime. .PP The signature definition needs to be on a single line only. .PP If you want to combine sub signatures with regular prototypes a \f(CW\*(C`proto\*(C'\fR attribute exists: .PP .Vb 1 \& sub foo ($bar, $baz) : proto($$) { ... } .Ve .SH "METHODS" .IX Header "METHODS" If you want subroutine signatures doing something that this module doesn't provide, like argument validation, typechecking and similar, you can subclass it and override the following methods. .SS "proto_unwrap ($prototype)" .IX Subsection "proto_unwrap ($prototype)" Turns the extracted \f(CW$prototype\fR into code. .PP The default implementation returns \f(CW\*(C`my (${prototype}) = @_;\*(C'\fR or an empty string, if no prototype is given. .ie n .SS "inject ($offset, $code)" .el .SS "inject ($offset, \f(CW$code\fP)" .IX Subsection "inject ($offset, $code)" Inserts a \f(CW$code\fR string into the line perl currently parses at the given \&\f(CW$offset\fR. This is only called by the \f(CW\*(C`callback\*(C'\fR method. .ie n .SS "callback ($offset, $prototype)" .el .SS "callback ($offset, \f(CW$prototype\fP)" .IX Subsection "callback ($offset, $prototype)" This gets called as soon as a sub definition with a prototype is encountered. Arguments are the \f(CW$offset\fR within the current line perl is parsing and extracted \f(CW$prototype\fR. .PP The default implementation calls \f(CW\*(C`proto_unwrap\*(C'\fR with the prototype and passes the returned value and the offset to \f(CW\*(C`inject\*(C'\fR. .SH "LIMITATIONS" .IX Header "LIMITATIONS" .IP "prototypes aren't checked for validity yet" 4 .IX Item "prototypes aren't checked for validity yet" You won't get a warning for invalid prototypes using the \f(CW\*(C`proto\*(C'\fR attribute, like you normally would with warnings enabled. .ie n .IP "you shouldn't alter $SIG{_\|_WARN_\|_} at compile time" 4 .el .IP "you shouldn't alter \f(CW$SIG\fR{_\|_WARN_\|_} at compile time" 4 .IX Item "you shouldn't alter $SIG{__WARN__} at compile time" After this module is loaded you shouldn't make any changes to \f(CW$SIG{_\|_WARN_\|_}\fR during compile time. Changing it before the module is loaded or at runtime is fine. .SH "SEE ALSO" .IX Header "SEE ALSO" .IP "\(bu" 4 Method::Signatures .IP "\(bu" 4 MooseX::Method::Signatures .IP "\(bu" 4 Sub::Signatures .IP "\(bu" 4 Attribute::Signature .IP "\(bu" 4 Perl6::Subs .IP "\(bu" 4 Perl6::Parameters .SH "THANKS" .IX Header "THANKS" Moritz Lenz and Steffen Schwigon for documentation review and improvement. .SH "SUPPORT" .IX Header "SUPPORT" Bugs may be submitted through the \s-1RT\s0 bug tracker (or bug\-signatures@rt.cpan.org ). .SH "AUTHOR" .IX Header "AUTHOR" Florian Ragwitz .SH "CONTRIBUTORS" .IX Header "CONTRIBUTORS" .IP "\(bu" 4 Karen Etheridge .IP "\(bu" 4 Peter Martini .IP "\(bu" 4 Father Chrysostomos .IP "\(bu" 4 Alex Kapranoff .IP "\(bu" 4 Steffen Schwigon .IP "\(bu" 4 Alexandr Ciornii .IP "\(bu" 4 Dave Mitchell .SH "COPYRIGHT AND LICENCE" .IX Header "COPYRIGHT AND LICENCE" This software is copyright (c) 2008 by Florian Ragwitz. .PP This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.