Perl Subroutine Signatures Opinion Blog

This site is an opinion blog about Perl Subroutine Signatures. Subroutine Signatures is plan to added to Perl in the near future. I have a very strong concern in the future of Perl, so I created an independent site about sub signatures. My name is Yuki Kimoto. I'm Perl Light User. I have no media power, community power, political power, and big company power. I just feel and talk about the heart of a weak perl user without a voice.

Type Constraints using Type::Tiny and attribute handler

If you can perform type checking with an attribute handler and Type::Tiny, Perl will be more attractive.

For example.

use Type::Tiny::Signatures;

sub foo ($str : Str, $num : Int) {
  
}

What is attribute handler?

The attribute handler is a function that can handle the attribute setting of subroutines and variables from Perl 5.6.

#!perl -w
use strict;

sub MODIFY_CODE_ATTRIBUTES{
  my($class, $code_ref, $attr_name) = @_;
  Dump($code_ref);
}

# Subroutine attribute
sub foo : MyAttr {

}

Perl already has a syntax called attributes.

sub foo : attribute

Attribute for arguments of subroutine signatures

We are fortunate.

Aattributes of subroutine argument are not yet implemented.

We can implement the use of subroutine attributes without worrying about the past.

It would be nice to be able to check arguments by combining a subroutine argument attribute handler with Type::Tiny.

use Type::Tiny::Signatures;

sub foo ($str : Str, $num : Int) {
  
}

Perl core is all dynamic, and you can add listrictions by module

We have known for 30 years that all Perl core is dynamic.

Perl has no restrictions by default.

On the other hand, you can incorporate constraints by using modules.

For example,

fields modules for field listrictions.

Hash::Util::lock_keys for hash key listrictions.

Sure, Type::Tiny for type constraints.

This is 30 years of Perl convention.

If signatures is dynamic and, add listrictions by module and attribute handler,

We are likely to be able to work with the old and the new and solve the Perl community's dissatisfaction.

I hope that older users who have enjoyed the dynamic types of Perl can collaborate with the Perl community who wanted to do type checking.

I suggest an implementation where Type::Tiny works correctly with subroutine signatures.

Toby proposal

I discussion about Type::Tiny with Toby Inkster in blogs.perl.org.

Type Constraints using Type::Tiny and attribute handler of subroutine signatures