NAME

Attribute::Args - check subroutine param types

SYNOPSIS

        use Attribute::Args;

	sub foo :ARGS('scalar', 'HASH') {
		my ($scalar, $hashref) = @_;
		# code
	}

	foo(42, { 'key' => 'value' }); # good
	foo(['array', 'elements']); # bad

OVERVIEW

:ARGS() attribute wraps method and adds runtime type checks for method calls. dies whenever the parameters dont match.

SUPPORTED TYPES

any

parameter of any type. useful for defining subs that can accept different types for some parameters.

scalar

scalar value. can be null. cannot be ref.

null

does not accept anything except undef.

list

accepts array. can only be the last param. must have at least one element. can be null. use the 'optional' modifier to declare an array that can be empty.

hash

same as list, but is also checked for parity. must have at least one key/value pair. can be null.

any other type

other values are treated as refs. e.g. 'ARRAY', 'HASH', 'Class::Name', etc. for classes also isa() is checked to figure out if the actual parameters class is inherited from the requested one. cannot be null.

TYPE MODIFIERS

currently the only modifier is the 'optional' modifier. it is denoted by a question mark after the type.

sub foo :ARGS('scalar', 'scalar?') { ... }

foo(42, 29); # good
foo(42); # good

MANUAL CHECK

for anonymous subs and other special cases manual type check can be used:

sub foo {
	my ($x, %y) = Attribute::Args::check(['scalar', 'hash?'], \@_);
	# ...
}

CAVEATS

in some modules Attribute::Handlers, that is used in Attribute::Args, goes crazy and thinks that all subs are anonymous. you will have to use manual check for them.

Attribute::Args distinguishes between null values and non-existing ones. you cannon pass null for optional param if it does not accept one.

list or hash can only be the last param. whenever is is found it takes all remaining args as it's elements and anything after the list will die as if it wasnt specified.

AUTHOR

Alex Alexandrov, <swined at cpan.org>

BUGS

Please report any bugs or feature requests to bug-attribute-args at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Attribute-Args. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

perldoc Attribute::Args

You can also look for information at:

COPYRIGHT & LICENSE

Copyright 2009 Alex Alexandrov, all rights reserved.

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