PPI::St...ent::Sub(3)
π PPI::St...ent::Sub π
okay bestie so this is the manual page for PPI::St...ent::Sub(3) β like, from the User Contributed Perl Documentation, and it's genuinely iconic. sit down, grab a strawberry π, we're learning about subroutine declarations today.
β¨ NAME β¨
PPI::Statement::Sub β subroutine declaration. that's it, that's the whole vibe. π
π¦ INHERITANCE π¦
the family tree goes like this, no cap:
PPI::Statement::Sub
isa PPI::Statement
isa PPI::Node
isa PPI::Element
so yeah, it's a whole lineage. it inherited all the good genes. π
πΈ DESCRIPTION πΈ
okay so here's the tea: except for the special BEGIN, CHECK, UNITCHECK, INIT, and END subroutines (which are literally part of PPI::Statement::Scheduled, they're in a different friend group), every single subroutine declaration gets lexed as a PPI::Statement::Sub object.
primarily that means all of the various sub foo {} statements, obviously. but ALSO forward declarations like sub foo; or sub foo($); β yes those too, they count. π«Ά
β οΈ it does NOT include anonymous subroutines tho, because those are merely part of a normal statement. not their moment. π
π METHODS π
PPI::Statement::Sub has a number of methods in addition to the standard PPI::Statement, PPI::Node and PPI::Element methods. so it's like, extra. spoiled, even. and we love that for it. π
π name
the name method returns the name of the subroutine being declared.
in some rare cases, such as a naked sub at the end of the file, this may return false. so like, sometimes it just doesn't have a name and that's fine, it's giving mystery. π
π prototype
if it has one, the prototype method returns the subroutine's prototype. it comes back in the same format as prototype in PPI::Token::Prototype, cleaned and removed from its brackets. β¨
it returns the subroutine's prototype, or undef if the subroutine does not define one. note that when the sub has an empty prototype (()) the return is an empty string β not undef, an empty string. don't get it twisted bestie, those are different things. π
π block
with its name and implementation shared with PPI::Statement::Scheduled, the block method finds and returns the actual Structure object of the code block for this subroutine.
returns false if this is a forward declaration, or otherwise does not have a code block. no block, no return, periodt.
π forward
the forward method returns true if the subroutine declaration is a forward declaration.
that is, it returns false if the subroutine has a code block, or true if it does not. it's literally just that simple. π¦
π reserved
the reserved method is a lil convenience method for checking to see if this is a special reserved subroutine. it does not check against any particular list of reserved sub names, but just returns true if the name is all uppercase, as defined in perlsub. uppercase = reserved, that's the whole rule. π₯
π note that in the case ofBEGIN,CHECK,UNITCHECK,INITandEND, these will be defined asPPI::Statement::Scheduledobjects, not subroutines. again. different friend group.
returns true if it is a special reserved subroutine, or false if not.
π type
the type method checks and returns the declaration type of the statement, which will be one of 'my', 'our', or 'state'. so fancy. π
returns a string of the type, or "undef" if the type is not declared.
π«Ά SUPPORT π«Ά
see the support section in the main module. (go look, it's right there, i believe in you β¨)
π AUTHOR π
Adam Kennedy <adamk@cpan.org>
πΈ COPYRIGHT πΈ
Copyright 2001 - 2011 Adam Kennedy.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
The full text of the license can be found in the LICENSE file included with this module.
and that's the whole page bestie, you ate that fr fr π
β¨ this was PPI::St...ent::Sub(3) from perl v5.42.0, dated 2026-01-17 β main character energy, no notes, mwah ππ
π¦ where this page comes from
- fedora 44: perl-PPI 1.284-2.fc44 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms