@@ -3596,7 +3596,53 @@ to be rewritten more cleanly as:
35963596
35973597=head3 The ATTRS: Keyword
35983598
3599- XXX TBC
3599+ MODULE = Foo::Bar PACKAGE = Foo::Bar
3600+
3601+ SV*
3602+ debug()
3603+ ATTRS: lvalue
3604+ PPCODE:
3605+ # return $Foo::Bar::DEBUG, creating it if not already present:
3606+ PUSHs(GvSV(gv_fetchpvs("Foo::Bar::DEBUG", GV_ADD, SVt_IV)));
3607+
3608+ The C<ATTRS> keyword allows you to apply subroutine attributes to an XSUB
3609+ in a similar fashion to Perl subroutines. The XSUB in the example above is
3610+ equivalent to this Perl:
3611+
3612+ sub debug :lvalue { return $Foo::Bar::DEBUG }
3613+
3614+ and both can be called like this:
3615+
3616+ use Foo::Bar;
3617+ Foo::Bar::debug() = 99;
3618+ print "$Foo::Bar::DEBUG\n"; # prints 99
3619+
3620+ This keyword consumes all lines until the next keyword. The contents of
3621+ each line are interpreted as space-separated attributes. The attributes
3622+ are applied at the time the XS module is loaded. This:
3623+
3624+ void
3625+ foo(...)
3626+ ATTRS: aaa
3627+ bbb(x,y) ccc
3628+
3629+ is approximately equivalent to:
3630+
3631+ use attributes Foo::Bar, \&foo, 'aaa';
3632+ use attributes Foo::Bar, \&foo, 'bbb(x,y)';
3633+ use attributes Foo::Bar, \&foo, 'ccc';
3634+
3635+ User-defined attributes, just like with Perl subs, will trigger a call to
3636+ C<MODIFY_CODE_ATTRIBUTES()>, as described in L<attributes>.
3637+
3638+ Note that not all built-in subroutine attributes necessarily make sense
3639+ applied to XSUBs.
3640+
3641+ Currently the parsing of white-space is crude: C<bbb(x, y)> is
3642+ misinterpreted as two separate attributes, C<'bbb(x,'> and C<'y)'>.
3643+
3644+ The C<ATTRS> keyword can't currently be used in conjunction with C<ALIAS>
3645+ or C<INTERFACE>; in this case, the attributes are just silently ignored.
36003646
36013647=head2 Sharing XSUB bodies
36023648
0 commit comments