Subject: | Warning for earlier declare if method param name the same as an attribute name |
Date: | Mon, 7 Aug 2017 18:21:24 -0400 |
To: | bug-Dios [...] rt.cpan.org |
From: | William Barker <wrb4181 [...] gmail.com> |
Dios-00.2007
Strawberry 5.26.0
Windows 10 64-bit
If you 'use warnings' and create an attribute, then that variable will be
used within the same lexical scope that method params are used (subroutine
signature).
Example:
use 5.26.0;
use warnings;
use Dios;
class Foo {
has Str $.bar;
method print ( $foo, $bar, $baz, $qux ) {
say $foo;
say $bar;
say $baz;
say $qux;
}
}
1;
However in standard Perl using subroutine signatures this is allowed.
Example:
use 5.26.0;
use warnings;
use feature 'signatures';
no warnings qw(experimental::signatures);
package Foo {
my $bar;
sub new {
my $class;
my $self = {};
bless $self, $class;
return $self;
}
sub print ( $foo, $bar, $baz, $qux ) {
say $foo;
say $bar;
say $baz;
say $qux;
}
}
1;