1
- package attributes ;
1
+ package attributes 0.37 ;
2
2
3
- our $VERSION = 0.36 ;
3
+ use v5.40 ;
4
4
5
- @EXPORT_OK = qw( get reftype) ;
6
- @EXPORT = ();
7
- %EXPORT_TAGS = (ALL => [@EXPORT , @EXPORT_OK ]);
5
+ our @EXPORT_OK = qw( get reftype) ;
6
+ our @EXPORT = ();
7
+ our %EXPORT_TAGS = (ALL => [@EXPORT , @EXPORT_OK ]);
8
8
9
- use strict;
9
+ # Older versions of this module provided a `reftype` in attributes.xs, and
10
+ # there may exist code out there that relies on being able to find it.
11
+ *reftype = \&builtin::reftype;
10
12
11
13
sub croak {
12
14
require Carp;
@@ -28,27 +30,24 @@ my %msg = (
28
30
const => ' Useless use of attribute "const"' ,
29
31
);
30
32
31
- sub _modify_attrs_and_deprecate {
32
- my $svtype = shift ;
33
+ my sub modify_attrs_and_deprecate ($svtype , @args ) {
33
34
# After we've removed a deprecated attribute from the XS code, we need to
34
35
# remove it here, else it ends up in @badattrs. (If we do the deprecation in
35
36
# XS, we can't control the warning based on *our* caller's lexical settings,
36
37
# and the warned line is in this package)
37
38
grep {
38
39
$deprecated {$svtype } && / $deprecated {$svtype }/ ? do {
39
- require warnings;
40
40
warnings::warnif(' deprecated' , " Attribute \" $1 \" is deprecated, " .
41
41
" and will disappear in Perl 5.28" );
42
42
0;
43
43
} : $svtype eq ' CODE' && exists $msg {$_ } ? do {
44
- require warnings;
45
44
warnings::warnif(
46
45
' misc' ,
47
46
$msg {$_ }
48
47
);
49
48
0;
50
49
} : 1
51
- } _modify_attrs(@_ );
50
+ } _modify_attrs(@args );
52
51
}
53
52
54
53
sub import {
@@ -64,7 +63,7 @@ sub import {
64
63
if defined $home_stash && $home_stash ne ' ' ;
65
64
my @badattrs ;
66
65
if ($pkgmeth ) {
67
- my @pkgattrs = _modify_attrs_and_deprecate ($svtype , $svref , @attrs );
66
+ my @pkgattrs = modify_attrs_and_deprecate ($svtype , $svref , @attrs );
68
67
@badattrs = $pkgmeth -> ($home_stash , $svref , @pkgattrs );
69
68
if (!@badattrs && @pkgattrs ) {
70
69
require warnings;
@@ -82,7 +81,7 @@ sub import {
82
81
}
83
82
}
84
83
else {
85
- @badattrs = _modify_attrs_and_deprecate ($svtype , $svref , @attrs );
84
+ @badattrs = modify_attrs_and_deprecate ($svtype , $svref , @attrs );
86
85
}
87
86
if (@badattrs ) {
88
87
croak " Invalid $svtype attribute" .
@@ -92,13 +91,11 @@ sub import {
92
91
}
93
92
}
94
93
95
- sub get ($ ) {
96
- @_ == 1 && ref $_ [0] or
94
+ sub get :prototype( $) ( $svref ) {
95
+ ref $svref or
97
96
croak ' Usage: ' .__PACKAGE__ .' ::get $ref' ;
98
- my $svref = shift ;
99
97
my $svtype = uc reftype($svref );
100
- my $stash = _guess_stash($svref );
101
- $stash = caller unless defined $stash ;
98
+ my $stash = _guess_stash($svref ) // scalar caller ;
102
99
my $pkgmeth ;
103
100
$pkgmeth = UNIVERSAL::can($stash , " FETCH_${svtype} _ATTRIBUTES" )
104
101
if defined $stash && $stash ne ' ' ;
@@ -113,7 +110,6 @@ sub require_version { goto &UNIVERSAL::VERSION }
113
110
require XSLoader;
114
111
XSLoader::load();
115
112
116
- 1;
117
113
__END__
118
114
#The POD goes here
119
115
@@ -295,9 +291,11 @@ Otherwise, only L<built-in attributes|"Built-in Attributes"> will be returned.
295
291
296
292
=item reftype
297
293
298
- This routine expects a single parameter--a reference to a subroutine or
299
- variable. It returns the built-in type of the referenced variable,
300
- ignoring any package into which it might have been blessed.
294
+ This is an alias to L<builtin::reftype|builtin/reftype> . It is maintained
295
+ here for backward compatibility for any code that expected to be able to call
296
+ it from this module. Newly-written code should use the function from the
297
+ L<builtin> module directly.
298
+
301
299
This can be useful for determining the I<type > value which forms part of
302
300
the method names described in L<"Package-specific Attribute Handling"> below.
303
301
0 commit comments