PPIx::DocumentName::Result - Full result set for PPIx::DocumentName
version 1.01
use PPIx::DocumentName 1.00 -api => 1; my $result = PPIx::DocumentName->extract( $ppi_document ); # say the "name" of the document say $result->name; # the result object can also be stringified into the name found: say "$result"; # get the full PPI::Document object for the entire document my $ppi = $result->document; # get the node where we found the name # (usually a PPI::Statement::Package or PPI::Token::Comment) my $node = $result->node; # get the location where we found the name my $location = $result->node->location;
This class represents the results from PPIx::DocumentName when running under its new -api => 1
API.
my $name = $result->name;
Returns the name that was found in the document.
my $str = $result->to_string; my $str = "$result";
Convert this object to a string. This is the same as the name
method. This method will also be invoked if stringified inside a double quoted string.
my $ppi = $result->document;
Returns the PPI::Document of the document.
my $node = $result->node;
Returns the PPI::Node where the name was found. This will usually be either PPI::Statement::Package or PPI::Token::Comment, although other types could be used in the future.
Main module that generates objects of this class.
For node
to be useful, the document
object needs to remain in scope, this is the main reason the result object keeps it around, so if you want to use the node
to get the location information, make sure that you do not throw away the result object.
Bad:
my $node = PPIx::DocumentName->extract( $ppi_document )->node; my $location = $node->location; # undef
Fine:
my $result = PPIx::DocumentName->extract( $ppi_document ); my $node = $result->node; my $location = $node->location; # ok
This software is copyright (c) 2015-2021 by Kent Fredric <kentfredric@gmail.com>.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.