Method...Simple(3pm)
π Method::Signatures::Simple β the vibe π
okay bestie, so this is Method::Signatures::Simple (a Perl module, manual page Method...Simple(3pm), iykyk) and it does exactly what it says on the tin: basic method declarations with signatures, and no source filters β¨ like, none. zero. iconic.
π NAME
Method::Signatures::Simple β basic method declarations with signatures, without source filters. periodt π
π’ VERSION
version 1.07 π
β¨ SYNOPSIS
here's the whole vibe, bestie, copy-paste ready:
# -- a basic class -- #
package User;
use Method::Signatures::Simple;
method new ($class: $name, $email) {
my $user = {
id => new_id(42),
name => $name,
email => $email,
};
bless $user, $class;
}
func new_id ($seed) {
state $id = $seed;
$id++;
}
method name { $self->{name}; }
method email { $self->{email}; }
1;
# -- other features -- #
# attributes
method foo : lvalue { $self->{foo} }
# change invocant name
use Method::Signatures::Simple invocant => '$this';
method foo ($bar) { $this->bar($bar) }
method bar ($class: $bar) { $class->baz($bar) }
# use a different function keyword
use Method::Signatures::Simple function_keyword => 'fun';
fun triple ($num) { 3 * $num }
# use a different method keyword
use Method::Signatures::Simple method_keyword => 'action';
action foo { $self->bar }
π§ RATIONALE
so this module gives you the basic method and func keywords with nice simple signatures. it is intentionally simple, okay? like, on purpose. it's meant to be a stepping stone for its bigger brothers MooseX::Method::Signatures and Method::Signatures π
ngl it only gives you a small benefit over regular subs, so if you want more features, go look at those modules. but if you're just here for a tiny sprinkle of syntactic sugar? this might just be enough π
π FEATURES
- invocant π«Ά
the method keyword automatically injects that annoying my $self = shift; for you. you can rename the invocant with the first argument, followed by a colon:
method ($this:) {}
method ($this: $that) {}
the func keyword does not inject an invocant, but it does do the signature processing below:
func ($that) {}
- signature πΈ
the signature ($sig) gets transformed into my ($sig) = \@_;. that way we mimic perl's usual argument handling. chef's kiss.
method foo ($bar, $baz, %opts) {
func xyzzy ($plugh, @zorkmid) {
# becomes
sub foo {
my $self = shift;
my ($bar, $baz, %opts) = @_;
sub xyzzy {
my ($plugh, @zorkmid) = @_;
π οΈ ADVANCED CONFIGURATION
since this module subclasses Devel::Declare::MethodInstaller::Simple, you can change the keywords and the default invocant with import arguments. these changes affect the current scope β so like, they only hit where you're standing, not the whole building π
- change the invocant name
use Method::Signatures::Simple invocant => '$this';
method x { $this->{x} }
method y { $this->{y} }
# and this of course still works:
method z ($self:) { $self->{z} }
- change the keywords
you can install a different keyword (instead of the default 'method' and 'func'), by passing names to the use line:
use Method::Signatures::Simple method_keyword => 'action',
function_keyword => 'thing';
action foo ($some, $args) { ... }
thing bar ($whatever) { ... }
one benefit of this is that you can use this module together with e.g. MooseX::Declare:
# untested
use MooseX::Declare;
class Foo {
use Method::Signatures::Simple method_keyword => 'routine';
method x (Int $x) { ... } # from MooseX::Method::Signatures
routine y ($y) { ... } # from this module
}
if you specify neither method_keyword nor function_keyword, then we default to injecting method and func. if you only specify one of these options, then we only inject that one keyword into your scope.
examples:
# injects 'method' and 'func'
use Method::Signatures::Simple;
# only injects 'action'
use Method::Signatures::Simple method_keyword => 'action';
# only injects 'procedure'
use Method::Signatures::Simple function_keyword => 'procedure';
# injects 'action' and 'function'
use Method::Signatures::Simple method_keyword => 'action',
function_keyword => 'function';
- install several keywords π
you're not limited to a single use line, so you can install several keywords with the same semantics as 'method' into the current scope:
use Method::Signatures::Simple; # provides 'method' and 'func'
use Method::Signatures::Simple method_keyword => 'action';
method x { ... }
func y { ... }
action z { ... }
π AUTHOR
Rhesa Rozendaal, "<rhesa at cpan.org>" β shoutout to the icon who made this π«Ά
π BUGS
please report any bugs or feature requests to "bug-method-signatures-simple at rt.cpan.org", or through the web interface at <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Method-Signatures-Simple>. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. we love a feedback loop π
π SUPPORT
you can find documentation for this module with the perldoc command.
perldoc Method::Signatures::Simple
you can also look for information at:
- RT: CPAN's request tracker
<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Method-Signatures-Simple>
- AnnoCPAN: Annotated CPAN documentation
<http://annocpan.org/dist/Method-Signatures-Simple>
- CPAN Ratings
<http://cpanratings.perl.org/d/Method-Signatures-Simple>
- Search CPAN
<http://search.cpan.org/dist/Method-Signatures-Simple>
π«Ά ACKNOWLEDGEMENTS
- MSTROUT
for writing Devel::Declare and providing the core concepts. the blueprint fr fr π§
- MSCHWERN
for writing Method::Signatures and publishing about it. this is what got my attention π
- FLORA
for helping me abstracting the Devel::Declare bits and suggesting improvements.
- CHIPS
for suggesting we add a 'func' keyword. king behaviour honestly π
π SEE ALSO
Devel::Declare, Method::Signatures, MooseX::Method::Signatures.
βοΈ COPYRIGHT & LICENSE
Copyright 2011 Rhesa Rozendaal, all rights reserved.
this program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. slay.
ok that's the whole page bestie, no cap, nothing skipped π―
and finally, the receipts: this was perl v5.34.0, dated 2022-06-15, and the page is Method...Simple(3pm) πβ¨π
π¦ where this page comes from
- debian bookworm: libmethod-signatures-simple-perl 1.07-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libmethod-signatures-simple-perl 1.07-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libmethod-signatures-simple-perl 1.07-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libmethod-signatures-simple-perl 1.07-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libmethod-signatures-simple-perl 1.07-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms