.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "PPIx::Utilities::Node 3" .TH PPIx::Utilities::Node 3 2023-07-26 "perl v5.38.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME PPIx::Utilities::Node \- Extensions to PPI::Node. .SH VERSION .IX Header "VERSION" This document describes PPIx::Utilities::Node version 1.1.0. .SH SYNOPSIS .IX Header "SYNOPSIS" .Vb 1 \& use PPIx::Utilities::Node qw< split_ppi_node_by_namespace >; \& \& my $dom = PPI::Document\->new("..."); \& \& while ( \& my ($namespace, $sub_doms) = each split_ppi_node_by_namespace($dom) \& ) { \& foreach my $sub_dom ( @{$sub_doms} ) { \& ... \& } \& } .Ve .SH DESCRIPTION .IX Header "DESCRIPTION" This is a collection of functions for dealing with PPI::Nodes. .SH INTERFACE .IX Header "INTERFACE" Nothing is exported by default. .SS split_ppi_node_by_namespace($node) .IX Subsection "split_ppi_node_by_namespace($node)" Returns the sub-trees for each namespace in the node as a reference to a hash of references to arrays of PPI::Nodes. Say we've got the following code: .PP .Vb 1 \& #!perl \& \& my $x = blah(); \& \& package Foo; \& \& my $y = blah_blah(); \& \& { \& say \*(AqWhee!\*(Aq; \& \& package Bar; \& \& something(); \& } \& \& thingy(); \& \& package Baz; \& \& da_da_da(); \& \& package Foo; \& \& foreach ( blrfl() ) { \& ... \& } .Ve .PP Calling this function on a PPI::Document for the above returns a value that looks like this, using multi-line string literals for the actual code parts instead of PPI trees to make this easier to read: .PP .Vb 4 \& { \& main => [ \& q< \& #!perl \& \& my $x = blah(); \& >, \& ], \& Foo => [ \& q< \& package Foo; \& \& my $y = blah_blah(); \& \& { \& say \*(AqWhee!\*(Aq; \& \& } \& \& thingy(); \& >, \& q< \& package Foo; \& \& foreach ( blrfl() ) { \& ... \& } \& >, \& ], \& Bar => [ \& q< \& package Bar; \& \& something(); \& >, \& ], \& Baz => [ \& q< \& package Baz; \& \& da_da_da(); \& >, \& ], \& } .Ve .PP Note that the return value contains copies of the original nodes, and not the original nodes themselves due to the need to handle namespaces that are not file-scoped. (Notice how the first element for "Foo" above differs from the original code.) .SH "BUGS AND LIMITATIONS" .IX Header "BUGS AND LIMITATIONS" Please report any bugs or feature requests to \&\f(CW\*(C`bug\-ppix\-utilities@rt.cpan.org\*(C'\fR, or through the web interface at . .SH AUTHOR .IX Header "AUTHOR" Elliot Shank \f(CW\*(C`\*(C'\fR .SH COPYRIGHT .IX Header "COPYRIGHT" Copyright (c)2009\-2010, Elliot Shank \f(CW\*(C`\*(C'\fR. .PP This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The full text of this license can be found in the LICENSE file included with this module.