Watch your fingers when typing named arguments
Perl 6
Switch branches/tags
Nothing to show
Latest commit 351ff23 Apr 23, 2017 @nxadm Add license to meta
Permalink
Failed to load latest commit information.
doc add pod6-file Dec 31, 2015
examples add example file Dec 31, 2015
lib we can have coloured error messages. How cool is that! Dec 31, 2015
t Make author test travis friendly Dec 29, 2015
.gitignore ignore .precomp Dec 29, 2015
.travis.yml travis Dec 29, 2015
LICENSE first commit Dec 21, 2015
META6.json Add license to meta Apr 23, 2017
README.md vim typo Dec 29, 2015

README.md

StrictNamedArguments

Build Status

While Perl 6 is strict on types when one is specified in the parameter definition, the default behaviour for values for unknown named parameters in methods (and constructors) is just to ignore them. With this module, you can let Perl 6 throw an exception when invalid named parameters are supplied. Let Perl6 watch yours fingers for these typos.

See https://perl6advent.wordpress.com/2015/12/13/a-new-trait-for-old-methods/

Usage:

use v6;
use StrictNamedArguments;

# Just use the trait 'strict' for methods
class Foo { 	 # your class
    has $.valid; # attribute, used by .new

	# A regular method that expects a named argument:
	# msg => 'some_value'
	# and returns the value in upper case (in this example)
    method shout(:$msg) is strict { $msg.uc }

	# The Perl6 constructor is a regular method and can also
	# me made strict if you provide the method strictly.
	# The syntax of named parameters is a hash to be blessed.
    method new(:$valid) is strict { self.bless(valid => $valid) }
}

Example output for $foo.shout( msg_ => 'some_value' ) method call:

The method shout of Foo received an invalid named parameter(s): msg_
  in method <anon> at /home/claudio/Code/StrictNamedArguments/lib/StrictNamedArguments.pm line 47
  in any enter at gen/moar/m-Metamodel.nqp line 3927
  in block <unit> at t/strict2.t line 19