Attribute::Signature - allows you to define a call signature for subroutines
package Some::Package; use Attribute::Signature; sub somesub : with(float, string, Some::Other::Class) returns(float) { # .. do something .. } package main; my $array = Attribute::Signature->getSignature('Some::Package::somesub');
This module allows you to declare calling and returning signatures for a method. As yet it does not provide multimethod type functionality, but it does prevent you from writing lots of annoying code to check argument types inside your subroutine. Attribute::Signature takes two forms, the first is attributes on standard subroutines, in which it examines every parameter passed to the subroutine. However, if the subroutine is marked with the method attribute, then Attribute::Signature will not examine the first argument, which can be either the class or the instance.
Attribute::Signature
Attribute::Signature can also check the values that are returned from the method / subroutine, by use of the returns attribute.
returns
Attribute::Signature checks for the following types:
as well as, in the case of classes, that the object's class inherits from the named class. For example:
sub test : (Some::Class) { # .. do something .. }
would check to make sure that whatever was passed as the argument was blessed into a class which returned 1 when the isa method was called on it.
isa
Finally Attribute::Signature allows for some measure of type testing. Any type that is all in lower case is tested by calling a function having the same name in the Attribute::Signature namespace. Attribute::Signature comes with the following type tests:
Note that the float type mistakenly decides that 10.0 is not a float as Perl optimises it to be 10. You can define more tests by declaring subs in the Attribute::Signature namespace.
Attribute::Signature also allows you to call the getSignature method. The string should be the complete namespace and subroutine. This returns the attribute signature and returned values signature for the function as two array references.
James A. Duncan <jduncan@fotango.com> Leon Brocard <leon@fotango.com>
perl(1) UNIVERSAL(3)
2 POD Errors
The following errors were encountered while parsing the POD:
'=item' outside of any '=over'
You forgot a '=back' before '=head1'
To install Attribute::Signature, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Attribute::Signature
CPAN shell
perl -MCPAN -e shell install Attribute::Signature
For more information on module installation, please visit the detailed CPAN module installation guide.