1 package Method
::Signatures
::Simple
;
10 Method::Signatures::Simple - Basic method declarations with signatures, without source filters
18 use base q
/Devel::Declare::MethodInstaller::Simple/;
23 $opts{into
} ||= caller;
24 $opts{invocant
} ||= '$self';
26 $class->install_methodhandler(
36 $proto =~ s/[\r\n]//g;
37 my $invocant = $self->{invocant
};
39 $invocant = $1 if $proto =~ s{^(\$\w+):\s*}{};
41 my $inject = "my ${invocant} = shift;";
42 $inject .= "my ($proto) = \@_;" if defined $proto and length $proto;
50 use Method::Signatures::Simple;
52 method foo { $self->bar }
55 method foo($bar, %opts) {
56 $self->bar(reverse $bar) if $opts{rev};
60 method foo : lvalue { $self->{foo} }
62 # change invocant name
63 method foo ($class: $bar) { $class->bar($bar) }
67 This module provides a basic C<method> keyword with simple signatures. It's intentionally simple,
68 and is supposed to be a stepping stone for its bigger brothers L<MooseX::Method::Signatures> and L<Method::Signatures>.
69 It only has a small benefit over regular subs, so if you want more features, look at those modules.
70 But if you're looking for a small amount of syntactic sugar, this might just be enough.
78 The C<method> keyword automatically injects the annoying C<my $self = shift;> for you. You can rename
79 the invocant with the first argument, followed by a colon:
82 method ($this: $that) {}
86 The signature C<($sig)> is transformed into C<"my ($sig) = \@_;">. That way, we mimic perl's usual
89 method foo ($bar, $baz, %opts) {
95 my ($bar, $baz, %opts) = @_;
114 Rhesa Rozendaal, C<< <rhesa at cpan.org> >>
118 Please report any bugs or feature requests to C<bug-method-signatures-simple at rt.cpan.org>, or through
119 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Method-Signatures-Simple>. I will be notified, and then you'll
120 automatically be notified of progress on your bug as I make changes.
124 You can find documentation for this module with the perldoc command.
126 perldoc Method::Signatures::Simple
129 You can also look for information at:
133 =item * RT: CPAN's request tracker
135 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Method-Signatures-Simple>
137 =item * AnnoCPAN: Annotated CPAN documentation
139 L<http://annocpan.org/dist/Method-Signatures-Simple>
143 L<http://cpanratings.perl.org/d/Method-Signatures-Simple>
147 L<http://search.cpan.org/dist/Method-Signatures-Simple>
151 =head1 ACKNOWLEDGEMENTS
157 For writing L<Devel::Declare> and providing the core concepts.
161 For writing L<Method::Signatures> and publishing about it. This is what got my attention.
165 For helping me abstracting the Devel::Declare bits and suggesting improvements.
171 L<Devel::Declare>, L<Method::Signatures>, L<MooseX::Method::Signatures>.
173 =head1 COPYRIGHT & LICENSE
175 Copyright 2008 Rhesa Rozendaal, all rights reserved.
177 This program is free software; you can redistribute it and/or modify it
178 under the same terms as Perl itself.
183 1; # End of Method::Signatures::Simple