Method::Signatures::Simple - Basic method declarations with signatures, without source filters


Method-Signatures-Simple documentation  | view source Contained in the Method-Signatures-Simple distribution.

Index


NAME

Top

Method::Signatures::Simple - Basic method declarations with signatures, without source filters

VERSION

Top

version 0.06

SYNOPSIS

Top

    use Method::Signatures::Simple;

    method foo { $self->bar }

    # with signature
    method foo($bar, %opts) {
        $self->bar(reverse $bar) if $opts{rev};
    }

    # attributes
    method foo : lvalue { $self->{foo} }

    # change invocant name
    method foo ($class: $bar) { $class->bar($bar) }

RATIONALE

Top

This module provides a basic method keyword with simple signatures. It's intentionally simple, and is supposed to be a stepping stone for its bigger brothers MooseX::Method::Signatures and Method::Signatures. It only has a small benefit over regular subs, so if you want more features, look at those modules. But if you're looking for a small amount of syntactic sugar, this might just be enough.

FEATURES

Top

* invocant

The method keyword automatically injects the annoying my $self = shift; for you. You can rename the invocant with the first argument, followed by a colon:

    method ($this:) {}
    method ($this: $that) {}

* signature

The signature ($sig) is transformed into "my ($sig) = \@_;". That way, we mimic perl's usual argument handling.

    method foo ($bar, $baz, %opts) {

    # becomes

    sub foo {
        my $self = shift;
        my ($bar, $baz, %opts) = @_;

ADVANCED CONFIGURATION

Top

Since this module subclasses Devel::Declare::MethodInstaller::Simple, you can change the keyword and the default invocant with import arguments. These changes affect the current scope.

* 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 keyword

You can install a different keyword (instead of the default 'method'), by passing a name to the use line:

    use Method::Signatures::Simple name => 'action';

    action foo ($some, $args) { ... }

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 name => 'routine';
        method x (Int $x) { ... }    # uses MooseX::Method::Signatures
        routine y ($y) { ... }       # uses this module
    }

* 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'
    use Method::Signatures::Simple name => 'action';

    method x { ... }
    action do_y { ... }

AUTHOR

Top

Rhesa Rozendaal, <rhesa at cpan.org>

BUGS

Top

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.

SUPPORT

Top

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

Top

* MSTROUT

For writing Devel::Declare and providing the core concepts.

* 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.

SEE ALSO

Top

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

COPYRIGHT & LICENSE

Top


Method-Signatures-Simple documentation  | view source Contained in the Method-Signatures-Simple distribution.