@@ -9602,6 +9602,85 @@ Perl_newMYSUB(pTHX_ I32 floor, OP *o, OP *proto, OP *attrs, OP *block)
9602
9602
return cv ;
9603
9603
}
9604
9604
9605
+ /*
9606
+ =for apidoc m|CV *|newATTRSUB_x|I32 floor|OP *o|OP *proto|OP *attrs|OP *block|bool o_is_gv
9607
+
9608
+ Construct a Perl subroutine, also performing some surrounding jobs.
9609
+
9610
+ This function is expected to be called in a Perl compilation context,
9611
+ and some aspects of the subroutine are taken from global variables
9612
+ associated with compilation. In particular, C<PL_compcv> represents
9613
+ the subroutine that is currently being compiled. It must be non-null
9614
+ when this function is called, and some aspects of the subroutine being
9615
+ constructed are taken from it. The constructed subroutine may actually
9616
+ be a reuse of the C<PL_compcv> object, but will not necessarily be so.
9617
+
9618
+ If C<block> is null then the subroutine will have no body, and for the
9619
+ time being it will be an error to call it. This represents a forward
9620
+ subroutine declaration such as S<C<sub foo ($$);>>. If C<block> is
9621
+ non-null then it provides the Perl code of the subroutine body, which
9622
+ will be executed when the subroutine is called. This body includes
9623
+ any argument unwrapping code resulting from a subroutine signature or
9624
+ similar. The pad use of the code must correspond to the pad attached
9625
+ to C<PL_compcv>. The code is not expected to include a C<leavesub> or
9626
+ C<leavesublv> op; this function will add such an op. C<block> is consumed
9627
+ by this function and will become part of the constructed subroutine.
9628
+
9629
+ C<proto> specifies the subroutine's prototype, unless one is supplied
9630
+ as an attribute (see below). If C<proto> is null, then the subroutine
9631
+ will not have a prototype. If C<proto> is non-null, it must point to a
9632
+ C<const> op whose value is a string, and the subroutine will have that
9633
+ string as its prototype. If a prototype is supplied as an attribute, the
9634
+ attribute takes precedence over C<proto>, but in that case C<proto> should
9635
+ preferably be null. In any case, C<proto> is consumed by this function.
9636
+
9637
+ C<attrs> supplies attributes to be applied the subroutine. A handful of
9638
+ attributes take effect by built-in means, being applied to C<PL_compcv>
9639
+ immediately when seen. Other attributes are collected up and attached
9640
+ to the subroutine by this route. C<attrs> may be null to supply no
9641
+ attributes, or point to a C<const> op for a single attribute, or point
9642
+ to a C<list> op whose children apart from the C<pushmark> are C<const>
9643
+ ops for one or more attributes. Each C<const> op must be a string,
9644
+ giving the attribute name optionally followed by parenthesised arguments,
9645
+ in the manner in which attributes appear in Perl source. The attributes
9646
+ will be applied to the sub by this function. C<attrs> is consumed by
9647
+ this function.
9648
+
9649
+ If C<o_is_gv> is false and C<o> is null, then the subroutine will
9650
+ be anonymous. If C<o_is_gv> is false and C<o> is non-null, then C<o>
9651
+ must point to a C<const> op, which will be consumed by this function,
9652
+ and its string value supplies a name for the subroutine. The name may
9653
+ be qualified or unqualified, and if it is unqualified then a default
9654
+ stash will be selected in some manner. If C<o_is_gv> is true, then C<o>
9655
+ doesn't point to an C<OP> at all, but is instead a cast pointer to a C<GV>
9656
+ by which the subroutine will be named.
9657
+
9658
+ If there is already a subroutine of the specified name, then the new
9659
+ sub will either replace the existing one in the glob or be merged with
9660
+ the existing one. A warning may be generated about redefinition.
9661
+
9662
+ If the subroutine has one of a few special names, such as C<BEGIN> or
9663
+ C<END>, then it will be claimed by the appropriate queue for automatic
9664
+ running of phase-related subroutines. In this case the relevant glob will
9665
+ be left not containing any subroutine, even if it did contain one before.
9666
+ In the case of C<BEGIN>, the subroutine will be executed and the reference
9667
+ to it disposed of before this function returns.
9668
+
9669
+ The function returns a pointer to the constructed subroutine. If the sub
9670
+ is anonymous then ownership of one counted reference to the subroutine
9671
+ is transferred to the caller. If the sub is named then the caller does
9672
+ not get ownership of a reference. In most such cases, where the sub
9673
+ has a non-phase name, the sub will be alive at the point it is returned
9674
+ by virtue of being contained in the glob that names it. A phase-named
9675
+ subroutine will usually be alive by virtue of the reference owned by the
9676
+ phase's automatic run queue. But a C<BEGIN> subroutine, having already
9677
+ been executed, will quite likely have been destroyed already by the
9678
+ time this function returns, making it erroneous for the caller to make
9679
+ any use of the returned pointer. It is the caller's responsibility to
9680
+ ensure that it knows which of these situations applies.
9681
+
9682
+ =cut
9683
+ */
9605
9684
9606
9685
/* _x = extended */
9607
9686
CV *
0 commit comments