PPI::Document - A single cohesive Perl document
PPI::Base \--> PPI::Element \--> PPI::Node \--> PPI::Document
# Load a document from a file use PPI::Document; my $Document = PPI::Document->load('My/Module.pm'); # Strip out comments $Document->prune( 'PPI::Token::Comment' ); # Find all the named subroutines my @subs = $Document->find( sub { isa($_[1], 'PPI::Statement::Sub') and $_[1]->name } ); # Save the file $Document->save('My/Module.pm.stripped');
The PPI::Document class represents a single Perl "document". A ::Document object acts as a normal PPI::Node, with some additions for loading/saving, and working with the line/column locations of tokens within a file.
The exemption to it's ::Node behaviour this is that a PPI::Document object can NEVER have a parent node, and is always the root node in a tree.
This method should be generally acted upon using the PPI::Node API, of which it is a subclass.
The load constructor loads a Perl document from a file, parses it, and returns a new PPI::Document object. Returns undef on error.
load
undef
The save method serializes the PPI::Document object and saves the resulting Perl document to a file. Returns undef on error.
save
index_locations
Within a document, all PPI::Element objects can be considered to have a "location", a line/column position within the document, if it were to be printed to a file. This position is primarily useful for debugging type activities.
When no longer needed, the flush_locations method clears all location data from the tokens.
flush_locations
May need to overload some methods to forcefully prevent objects becoming children of another Node.
See PPI
Adam Kennedy (Maintainer), http://ali.as/, cpan@ali.as
Copyright (c) 2004 Adam Kennedy. All rights reserved. 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.
To install PPI, copy and paste the appropriate command in to your terminal.
cpanm
cpanm PPI
CPAN shell
perl -MCPAN -e shell install PPI
For more information on module installation, please visit the detailed CPAN module installation guide.