-
-
17 May 2011 16:02:04 UTC
- Distribution: Smart-Args
- Module version: 0.10
- Source (raw)
- Browse (raw)
- Changes
- How to Contribute
- Repository
- Issues (0)
- Testers (1896 / 4 / 3)
- Kwalitee
Bus factor: 1- License: perl_5
- Perl: v5.8.1
- Activity
24 month- Tools
- Download (25.2KB)
- MetaCPAN Explorer
- Permissions
- Subscribe to distribution
- Permalinks
- This version
- Latest version
++ed by:2 non-PAUSE usersand 1 contributors- Tokuhiro Matsuno <tokuhirom slkjfd gmail.com>
- Dependencies
- Exporter
- Mouse
- PadWalker
- Scalar::Util
- and possibly others
- Reverse dependencies
- CPAN Testers List
- Dependency graph
NAME
Smart::Args - argument validation for you
SYNOPSIS
use Smart::Args; sub func2 { args my $p => 'Int', my $q => { isa => 'Int', optional => 1 }; } func2(p => 3, q => 4); # p => 3, q => 4 func2(p => 3); # p => 3, q => undef sub func3 { args my $p => {isa => 'Int', default => 3}, } func3(p => 4); # p => 4 func3(); # p => 3 package F; use Moose; use Smart::Args; sub method { args my $self, my $p => 'Int'; } sub class_method { args my $class => 'ClassName', my $p => 'Int'; } sub simple_method { args_pos my $self, my $p; } my $f = F->new(); $f->method(p => 3); F->class_method(p => 3); F->simple_method(3);
DESCRIPTION
Smart::Args is yet another argument validation library.
This module makes your module more readable, and writable =)
FUNCTIONS
args my $var [, $rule], ...
Checks parameters and fills them into lexical variables. All the parameters are mandatory by default, and unknown parameters (i.e. possibly typos) are reported as
void
warnings.The arguments of
args()
consist of lexical <$var>s and optional $rules.$vars must be a declaration of a lexical variable.
$rule can be a type name (e.g.
Int
), a HASH reference (withtype
,default
, andoptional
), or a type constraint object.Note that if the first variable is named $class or $self, it is dealt as a method call.
See the SYNOPSIS section for examples.
args_pos my $var[, $rule, ...
Check parameters and fills them into lexical variables. All the parameters are mandatory by default.
The arguments of
args()
consist of lexical <$var>s and optional $rules. $vars must be a declaration of a lexical variable.$rule can be a type name (e.g.
Int
), a HASH reference (withtype
,default
, andoptional
), or a type constraint object.Note that if the first variable is named $class or $self, it is dealt as a method call.
See the SYNOPSIS section for examples.
TYPES
The types that
Smart::Args
uses are type constraints ofMouse
. That is, you can define your types in the way Mouse does.In addition,
Smart::Args
also allows Moose type constraint objects, so you can use anyMooseX::Types::*
libraries on CPAN.Type coercions are automatically tried if validations fail.
See Mouse::Util::TypeConstraints for details.
AUTHOR
Tokuhiro Matsuno <tokuhirom slkjfd gmail.com>
SEE ALSO
LICENSE
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Module Install Instructions
To install Smart::Args, copy and paste the appropriate command in to your terminal.
cpanm Smart::Args
perl -MCPAN -e shell install Smart::Args
For more information on module installation, please visit the detailed CPAN module installation guide.