Skip to content

Commit 813423d

Browse files
committed
perlxs.pod: document ATTRS
This keyword was undocumented, even though it had been added 25 years ago.
1 parent 6a7025f commit 813423d

File tree

1 file changed

+45
-1
lines changed

1 file changed

+45
-1
lines changed

dist/ExtUtils-ParseXS/lib/perlxs.pod

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3557,7 +3557,51 @@ to be rewritten more cleanly as:
35573557

35583558
=head3 The ATTRS: Keyword
35593559

3560-
XXX TBC
3560+
MODULE = Foo::Bar PACKAGE = Foo::Bar
3561+
3562+
SV*
3563+
debug()
3564+
ATTRS: lvalue
3565+
PPCODE:
3566+
# return $Foo::Bar::DEBUG, creating it if not already present:
3567+
PUSHs(GvSV(gv_fetchpvs("Foo::Bar::DEBUG", GV_ADD, SVt_IV)));
3568+
3569+
# Using it from Perl:
3570+
use Foo::Bar;
3571+
Foo::Bar::debug() = 99;
3572+
print "$Foo::Bar::DEBUG\n"; # prints 99
3573+
3574+
The C<ATTRS> keyword allows you to apply subroutine attributes to an XSUB
3575+
in a similar fashion to Perl subroutines. The XSUB in the example above is
3576+
equivalent to this Perl:
3577+
3578+
sub debug :lvalue { return $Foo::Bar::DEBUG }
3579+
3580+
This keyword consumes all lines until the next keyword. The contents of
3581+
each line are interpreted as space-separated attributes. The attributes
3582+
are applied at the time the XS module is loaded. This:
3583+
3584+
void
3585+
foo(...)
3586+
ATTRS: aaa
3587+
bbb(x,y) ccc
3588+
3589+
is approximately equivalent to:
3590+
3591+
use attributes Foo::Bar, \&foo, 'aaa';
3592+
use attributes Foo::Bar, \&foo, 'bbb(x,y)';
3593+
use attributes Foo::Bar, \&foo, 'ccc';
3594+
3595+
Currently the parsing of white-space is crude: C<bbb(x, y)> is
3596+
misinterpreted as two separate attributes, C<"bbb(x,"> and C<"y)">.
3597+
3598+
Note that not all built-in subroutine attributes necessarily make sense
3599+
applied to XSUBs. User-defined attributes will, just like with Perl subs,
3600+
trigger a call to C<MODIFY_CODE_ATTRIBUTES()>, as described in
3601+
L<attributes>.
3602+
3603+
The C<ATTR> keyword can't currently be used in conjunction with C<ALIAS>
3604+
or C<INTERFACE>; in this case, the attributes are just silently ignored.
35613605

35623606
=head2 Sharing XSUB bodies
35633607

0 commit comments

Comments
 (0)