I'm using an AUTOLOAD
example from @ikegami's post here. A recent CPAN testers report for my RF::Component::Multi module says:
Bareword found where operator expected at .../RF/Component/Multi.pm line 102, near "s/^.*:://sr"
syntax error at .../RF/Component/Multi.pm line 102, near "s/^.*:://sr"
The code is below and here on GitHub.
- What is it that Perl 5.10 doesn't like?
- Is there a Perl feature requiring >5.10 hidden in here that I'm missing? (My Perl 5.26.3 is working)
- If so can it be made more backwards compatible? How?
- If not, where do I find the version so I can do the right
use 5.xx
?
- Do I need
use vars '$AUTOLOAD'
?
# Thanks @ikegami:
# https://stackoverflow.com/a/74229589/14055985
sub AUTOLOAD
{
my $method_name = our $AUTOLOAD =~ s/^.*:://sr;
my $method = sub {
my $self = shift;
return [ map { $_->$method_name(@_) } @$self ];
};
{
no strict 'refs';
*$method_name = $method;
}
goto &$method;
}
CodePudding user response:
s///r
was added in 5.14.
my $method_name = our $AUTOLOAD =~ s/^.*:://sr;
could be replaced with
( my $method_name = our $AUTOLOAD ) =~ s/^.*:://s;
CodePudding user response:
You can use Perl::MinimumVersion to answer questions like this.
$ perlver your-code.pl
--------------------------------------
| file | explicit | syntax | external |
| -------------------------------------- |
| minver | ~ | v5.13.2 | n/a |
| -------------------------------------- |
| Minimum explicit version : ~ |
| Minimum syntax version : v5.13.2 |
| Minimum version of perl : v5.13.2 |
--------------------------------------
And, for more details,
$ perlver --blame your-code.pl
------------------------------------------------------------
File : minver
Line : 3
Char : 40
Rule : _regex
Version : 5.013002
------------------------------------------------------------
s/^.*:://sr
------------------------------------------------------------