Signatures producing warning messages despite "no warnings qw(experimental::signatures)"
Asked Answered
R

1

5

Created a package and wanted to use signatures.

package Foo;
use strict;
use warnings;
use feature qw(signatures);
no warnings qw(experimental::signatures);

use Moose;

has bar => ( is => 'ro', isa => 'Str' );

sub boom ($self, $stuff) {
    print "$stuff\n";
}
1;

Test it:

perl -wc Foo.pm
The signatures feature is experimental at ./Foo.pm line 11.

What's going on? I thought the "no warnings" pragma would suppress that warning!

Riker answered 28/10, 2021 at 20:49 Comment(3)
use experimental, btw.Irritable
What Shawn is saying is that use feature qw(signatures); can be used in lieu of use feature qw(signatures); no warnings qw(experimental::signatures);Befitting
Pretty sure you meant use experimental qw(signatures) @Befitting ;-)Haymes
R
7

The problem is that the use Moose; line re-enables all warnings.

The fix is to move the no warnings qw(experimental::signatures) below the use Moose; line.

E.g.:

use Moose;
no warnings qw(experimental::signatures);
Riker answered 28/10, 2021 at 20:49 Comment(1)
Mojo::Base will do that too, along what a few other conveniences. Too bad Moose hides this feature in a code comment in its synopsis.Brom

© 2022 - 2024 — McMap. All rights reserved.