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.

The way that CPAN authors use subroutine signatures in natural

Perl users contains CPAN authors, not only application users who use the new version of Perl.

Generally, CPAN authors use Perl old grammar to support older versions of Perl.

Most CPAN modules support Perl 5.8+, and Some modules support Perl 5.10+ and 5.12+.

CPAN authors also want to use subroutine signatures

Perl's new feature is for the new Perl, but when it comes to subroutine signatures, CPAN Author also maybe wants to use it.

If CPAN authors can use subroutine signatures, both application code and CPAN module code can be written in one source.

I think new features should work with the new Perl, but I'm happy that only the subroutine signature feature can be backported.

Wouldn't it be nice if you could use subroutine signatures with tens of thousands of CPAN modules?

But is there such a way?

Use signatures.pm if the perl version is lower than subroutine signatures

Use signatures.pm if the perl version is lower than Perl which support subroutine signatures.

I write the code. CPAN author can use signatures.pm instead of core subroutine signatures.

This code use SigImport. SigImport export signatures.pm features to Foo.

package Foo;

use strict;
use warnings;
use utf8;
use FindBin;

use lib "$FindBin::Bin";

use SigImport;

# Subroutine signatures imported from signatures.pm
sub func($foo) {
  return $foo;
}

package main;

print Foo::func(1, 2);

SigImport. This contains some signatures.pm fix.

package SigImport;

BEGIN {
  require signatures;
}

BEGIN {
  no warnings 'redefine';
  sub signatures::import {
    my ($class, $caller) = @_;
    $caller ||= caller();
    $pkgs{$caller} = $class->setup_for($caller);
    return;
  }
}

sub import {
  my $caller = caller;
  
   
  #if ($] >= 5.034001) {
  #  feature->import('signatures');
  #}
  #else {
    signatures->import($caller);
  #}
}

1;

This code work well. Swich signatures features by Perl version.

In this way, a more several things is needed.

the number of arguments in the subroutine signature is not checked by default

the number of arguments in the subroutine signature is not checked by default.

See also the following entry.

Risk increased by checking the number of subroutine arguments

signatures.pm is bandled to Perl core

If signatures.pm is bandled to Perl core, we can write the following in Makefile.PL

    PREREQ_PM => {
      'signatures.pm' => 0.15,
    },

CPAN authores can switch signature.pm to core subroutine signatures.

Wouldn't it be nice if you could fix the past in a subroutine signature?