Atsushi Kobayashi

NAME

Sub::Args - Simple check/get arguments.

SYNOPSIS

  package Your::Class;
  use Sub::Args;
  sub foo {
      my $class = shift;
      my $args = args(
          {
              name => 1,
              age  => 0,
          }
      );
      $args;
  }
  sub bar {
      my $class = shift;
      my $args = args(
          {
              name => 1,
              age  => 0,
          }
      );
      $args->{email}; # die: email is not defined hash key.
  }
  sub baz {
      my $class = shift;
      my ($var1, $var2) = args_pos(1,0);
  }
  
  # got +{name => nekokak, age => undef}
  Your::Class->foo(
      {
          name => 'nekokak',
      }
  );
  
  # got +{name => 'nekokak', age => 32}
  Your::Class->foo(
      {
          name => 'nekokak',
          age  => 32,
      }
  );
  
  # die: nick parameter don't defined for args method.
  Your::Class->foo(
      {
          name => 'nekokak',
          age  => 32,
          nick => 'inukaku',
      }
  );
  
  # die: name arguments must required.
  Your::Class->foo(
      {
          age => 32,
      }
  );

  Your::Class->baz('val1');

or

  package Your::Class;
  use Sub::Args;
  sub foo {
      my $class = shift;
      my $args = args(
          {
              name => 1,
              age  => 0,
          }, @_
      );
      $args;
  }
  
  # got +{name => nekokak}
  Your::Class->foo(
      {
          name => 'nekokak',
      }
  );

or

  package Your::Class;
  use Sub::Args;
  sub foo {
      my $args = args(
          {
              name => 1,
              age  => 0,
          }, @_
      );
      $args;
  }
  # got +{name => nekokak, age => undef}
  foo(
      {
          name => 'nekokak',
      }
  );

DESCRIPTION

This module makes your module more readable, and writable =p

and restrict a argument's hash. =(

When it accesses the key that doesn't exist, the exception is generated.

FUNCTIONS

my $hash_ref = args(\%rule, [@_]);

Check parameter and return read only hash-ref.

my @vals = args_pos(@rule);

Check parameter and return array or array-ref.

AUTHOR

Atsushi Kobayashi <nekokak _at_ gmail _dot_ com>

CONTRIBUTORS

hirobanex : Hiroyuki Akabane

SEE ALSO

Params::Validate

Smart::Args

Data::Validator

LICENSE

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.




Hosting generously
sponsored by Bytemark