Method...Simple(3pm)

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

πŸ’– 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 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