Skip to content
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

Open
mschout opened this issue Nov 2, 2018 · 4 comments
Open

Possible to use class name as a type name? #36

mschout opened this issue Nov 2, 2018 · 4 comments

Comments

@mschout
Copy link

@mschout mschout commented Nov 2, 2018

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:

use Function::Parameters;
use URI;
use Types::Standard qw(ArrayRef);
method foo(URI $uri) { ... }   # Undefined type name error
method foobar(ArrayRef[URI] $uris) { ... }  # missing type name after '[' error

This seems to not work with Function::Parameters, or, I have missed the way to get these working. Using Types::Standard I tried things such as:

use Types::Standard qw(InstanceOf ArrayRef);
method foo1(InstanceOf[URI] $uri) { ... }    # Undefined type name URI error
method foo2(InstanceOf['URI'] $uri) { ... }  # missing type name after '[' error
method foo3(ArrayRef[ InstanceOf[URI] ] $uris) { ... }    # Undefined type name URI error
method foo4(ArrayRef[ InstanceOf['URI'] ] $uris) { ... }  # missing type name after '[' error

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:

method foo1($uri) { ... }
method foo2(ArrayRef $uris) { ... }
@tobyink

This comment has been minimized.

Copy link

@tobyink tobyink commented Nov 2, 2018

Does this work?

method foo2((InstanceOf['URI']) $uri) { ... }
@mschout

This comment has been minimized.

Copy link
Author

@mschout mschout commented Nov 3, 2018

It does. Thank you!

@vanHoesel

This comment has been minimized.

Copy link

@vanHoesel vanHoesel commented Feb 11, 2019

@tobyink ... can you please explain why method foo( InstanceOf['URI'] $uri) { ... } is not working?

@tobyink

This comment has been minimized.

Copy link

@tobyink tobyink commented Feb 18, 2019

Because you left out the parentheses around the type name.

method foo((InstanceOf['URI']) $uri) { ... }

See the Function::Parameters documentation for what exactly those do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.