-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Possible to use class name as a type name? #36
Comments
Does this work?
|
It does. Thank you! |
@tobyink ... can you please explain why |
Because you left out the parentheses around the type name.
See the Function::Parameters documentation for what exactly those do. |
In addition to what @tobyink said, you can also define ad-hoc type constants: use constant {
T_URI => InstanceOf['URI'],
};
method foo(T_URI $uri, ArrayOf[T_URI] $uris) { ... } Or for maximum DWIMery, write a custom type reifier that turns undefined type names (which are normally looked up as subroutines in the current package) into |
If you have a recent version of use Function::Parameters;
use Type::Tiny::Class v2.0 qw( URI HTTP::Tiny );
method get_uri ( URI $uri, HTTPTiny $ua ) {
my $response = $ua->get( $uri );
if ( $response->{success} ) {
return $response->{content};
}
die "response failed";
} |
In porting over a codebase from Method::Signatures, I am dealing with a lot of methods that were using class names in the parameter lists. For example:
This seems to not work with
Function::Parameters
, or, I have missed the way to get these working. UsingTypes::Standard
I tried things such as:So either I am missing how to get this to work, or, I need to drop the class type constraints altogether and just use something like:
The text was updated successfully, but these errors were encountered: