Skip to content

Commit 176b724

Browse files
JRaspasskhwilliamson
authored andcommitted
Modernise overloading pragma a little
- Move the version declaration into the package line. - Use v5.40 to get strict, warnings, and the module_true feature. - Make private sub lexical, it's unlikely to be used in darkpan. - Make use of subroutine signatures.
1 parent 99457f8 commit 176b724

File tree

2 files changed

+11
-22
lines changed

2 files changed

+11
-22
lines changed

lib/overloading.pm

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,22 @@
1-
package overloading;
2-
use warnings;
1+
package overloading 0.03;
32

4-
our $VERSION = '0.02';
3+
use v5.40;
54

65
my $HINT_NO_AMAGIC = 0x01000000; # see perl.h
76

8-
require 5.010001;
9-
10-
sub _ops_to_nums {
7+
my sub ops_to_nums (@ops) {
118
require overload::numbers;
129

1310
map { exists $overload::numbers::names{"($_"}
1411
? $overload::numbers::names{"($_"}
1512
: do { require Carp; Carp::croak("'$_' is not a valid overload") }
16-
} @_;
13+
} @ops;
1714
}
1815

19-
sub import {
20-
my ( $class, @ops ) = @_;
21-
16+
sub import ($, @ops) {
2217
if ( @ops ) {
2318
if ( $^H{overloading} ) {
24-
vec($^H{overloading} , $_, 1) = 0 for _ops_to_nums(@ops);
19+
vec($^H{overloading} , $_, 1) = 0 for ops_to_nums(@ops);
2520
}
2621

2722
if ( $^H{overloading} !~ /[^\0]/ ) {
@@ -34,12 +29,10 @@ sub import {
3429
}
3530
}
3631

37-
sub unimport {
38-
my ( $class, @ops ) = @_;
39-
32+
sub unimport ($, @ops) {
4033
if ( exists $^H{overloading} or not $^H & $HINT_NO_AMAGIC ) {
4134
if ( @ops ) {
42-
vec($^H{overloading} ||= '', $_, 1) = 1 for _ops_to_nums(@ops);
35+
vec($^H{overloading} ||= '', $_, 1) = 1 for ops_to_nums(@ops);
4336
} else {
4437
delete $^H{overloading};
4538
}
@@ -48,7 +41,6 @@ sub unimport {
4841
$^H |= $HINT_NO_AMAGIC;
4942
}
5043

51-
1;
5244
__END__
5345
5446
=head1 NAME

lib/overloading.t

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
#./perl
22

3-
use Test::More;
4-
5-
no warnings 'experimental::builtin';
6-
use builtin qw(refaddr);
3+
use v5.40;
74

8-
{
9-
package Stringifies;
5+
use Test::More;
106

7+
package Stringifies {
118
use overload (
129
fallback => 1,
1310
'""' => sub { "foo" },

0 commit comments

Comments
 (0)