Syntax::Feature::Simple - DWIM syntax extensions
version 0.002
This is a more of a syntax extension package than a simple extension by itself. It will detect what kind of package it is imported into, and setup appropriate syntax extensions depending on the type.
If a Moose class or role is detected, this extension will setup a fun keyword for function declarations, a method keyword, and one keyword each for before, after and around.
fun
method
before
after
around
The modifiers behave exactly like normal method declarations, except for around which will provide the original method in a lexical named $orig.
$orig
package MyProject::MooseClassOrRole; use Moose; # or use Moose::Role # or use MooseX::Role::Parameterized, # but with body inside role { ... } use syntax qw( simple/v2 ); fun foo ($x) { ... } my $anon_f = fun ($x) { ... }; method bar ($x) { $self->say($x) } my $anon_m = method ($x) { $self->say($x) }; before baz ($x) { $self->say($x) } after baz ($x) { $self->say($x) } around baz ($x) { $self->say($self->$orig($x)) } 1;
In case of a parameterizable role the right callback will be called, but compatibility with anonymous method declarations will be preserved:
package MyProject::ParamRole; use MooseX::Role::Parameterized; use syntax qw( simple/v2 ); parameter method_name => (is => 'ro'); # defaults to $parameter role ($param) { my $name = $param->method_name; method "$name" ($n) { $self->say($n) } my $anon = method ($n) { $self->say($n) }; } 1;
As of version 2 you will also get sugar for the role body that allows you to specify a signature. By default, the parameter object will be available in a variable named $parameter.
role
$parameter
By default, if no other kind of package type is detected, simple/v1 will only setup the function syntax, while simple/v2 will setup the function and the method extension.
simple/v1
simple/v2
package MyProject::Util; use strictures 1; use syntax qw( simple/v2 ); fun foo ($x) { ... } my $anon_f = fun ($x) { ... }; method bar ($class: $x, $y) { ... } my $anon_m = method ($x) { ... }; 1;
simple/v*
no indirect
use true
Try::Tiny
simple/x*
Smart::Match if a valid Perl version was declared
Version 1 of the extension set.
Version 2 of the extension set.
The syntax dispatching module.
Contains general information about this extension.
Specifics about the method and modifier keywords.
Specifics about the fun function keyword.
Post-modern object-orientation.
Parameterizable roles for Moose.
Please report any bugs or feature requests to bug-syntax-feature-simple@rt.cpan.org or through the web interface at: http://rt.cpan.org/Public/Dist/Display.html?Name=Syntax-Feature-Simple
Robert 'phaylon' Sedlacek <rs@474.at>
This software is copyright (c) 2011 by Robert 'phaylon' Sedlacek.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Syntax::Feature::Simple, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Syntax::Feature::Simple
CPAN shell
perl -MCPAN -e shell install Syntax::Feature::Simple
For more information on module installation, please visit the detailed CPAN module installation guide.