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 of BEGIN, CHECK, UNITCHECK, INIT and END, these will be defined as PPI::Statement::Scheduled objects, 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 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