X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FPod%2FInputObjects.pm;h=d895b104a48ccb71081182e039a26a3dba44305b;hb=53273a086103cdbbf7ebdd5f1a18b2c0777cbc1b;hp=1432895e9119df94973d1b25f423aa6abfecb3c8;hpb=146174a91a192983720a158796dc066226ad0e55;p=p5sagit%2Fp5-mst-13.2.git diff --git a/lib/Pod/InputObjects.pm b/lib/Pod/InputObjects.pm index 1432895..d895b10 100644 --- a/lib/Pod/InputObjects.pm +++ b/lib/Pod/InputObjects.pm @@ -2,7 +2,7 @@ # Pod/InputObjects.pm -- package which defines objects for input streams # and paragraphs and commands when parsing POD docs. # -# Copyright (C) 1996-1999 by Bradford Appleton. All rights reserved. +# Copyright (C) 1996-2000 by Bradford Appleton. All rights reserved. # This file is part of "PodParser". PodParser is free software; # you can redistribute it and/or modify it under the same terms # as Perl itself. @@ -11,8 +11,8 @@ package Pod::InputObjects; use vars qw($VERSION); -$VERSION = 1.090; ## Current version of this package -require 5.004; ## requires this Perl version or later +$VERSION = 1.14; ## Current version of this package +require 5.005; ## requires this Perl version or later ############################################################################# @@ -42,7 +42,7 @@ are defined: =begin __PRIVATE__ -=item B +=item package B An object corresponding to a source of POD input text. It is mostly a wrapper around a filehandle or C-type object (or anything @@ -51,23 +51,23 @@ additional information relevant to the parsing of PODs. =end __PRIVATE__ -=item B +=item package B An object corresponding to a paragraph of POD input text. It may be a plain paragraph, a verbatim paragraph, or a command paragraph (see L). -=item B +=item package B An object corresponding to an interior sequence command from the POD input text (see L). -=item B +=item package B An object corresponding to a tree of parsed POD text. Each "node" in a parse-tree (or I) is either a text-string or a reference to a B object. The nodes appear in the parse-tree -in they order in which they were parsed from left-to-right. +in the order in which they were parsed from left-to-right. =back @@ -232,7 +232,7 @@ It has the following methods/attributes: ##--------------------------------------------------------------------------- -=head2 B +=head2 Pod::Paragraph-EB my $pod_para1 = Pod::Paragraph->new(-text => $text); my $pod_para2 = Pod::Paragraph->new(-name => $cmd, @@ -268,7 +268,7 @@ sub new { ## If they are in the argument list, they will override the defaults. my $self = { -name => undef, - -text => (@_ == 1) ? $_[0] : undef, + -text => (@_ == 1) ? shift : undef, -file => '', -line => 0, -prefix => '=', @@ -284,7 +284,7 @@ sub new { ##--------------------------------------------------------------------------- -=head2 B +=head2 $pod_para-EB my $para_cmd = $pod_para->cmd_name(); @@ -303,7 +303,7 @@ sub cmd_name { ##--------------------------------------------------------------------------- -=head2 B +=head2 $pod_para-EB my $para_text = $pod_para->text(); @@ -318,7 +318,7 @@ sub text { ##--------------------------------------------------------------------------- -=head2 B +=head2 $pod_para-EB my $raw_pod_para = $pod_para->raw_text(); @@ -335,7 +335,7 @@ sub raw_text { ##--------------------------------------------------------------------------- -=head2 B +=head2 $pod_para-EB my $prefix = $pod_para->cmd_prefix(); @@ -351,7 +351,7 @@ sub cmd_prefix { ##--------------------------------------------------------------------------- -=head2 B +=head2 $pod_para-EB my $separator = $pod_para->cmd_separator(); @@ -367,7 +367,7 @@ sub cmd_separator { ##--------------------------------------------------------------------------- -=head2 B +=head2 $pod_para-EB my $ptree = $pod_parser->parse_text( $pod_para->text() ); $pod_para->parse_tree( $ptree ); @@ -387,13 +387,13 @@ sub parse_tree { ##--------------------------------------------------------------------------- -=head2 B +=head2 $pod_para-EB my ($filename, $line_number) = $pod_para->file_line(); my $position = $pod_para->file_line(); Returns the current filename and line number for the paragraph -object. If called in an array context, it returns a list of two +object. If called in a list context, it returns a list of two elements: first the filename, then the line number. If called in a scalar context, it returns a string containing the filename, followed by a colon (':'), followed by the line number. @@ -423,7 +423,7 @@ It has the following methods/attributes: ##--------------------------------------------------------------------------- -=head2 B +=head2 Pod::InteriorSequence-EB my $pod_seq1 = Pod::InteriorSequence->new(-name => $cmd -ldelim => $delimiter); @@ -447,7 +447,7 @@ C<-line> keywords indicate the filename and line number corresponding to the beginning of the interior sequence. If the C<$ptree> argument is given, it must be the last argument, and it must be either string, or else an array-ref suitable for passing to B (or -it may be a reference to an Pod::ParseTree object). +it may be a reference to a Pod::ParseTree object). =cut @@ -497,7 +497,7 @@ sub new { ##--------------------------------------------------------------------------- -=head2 B +=head2 $pod_seq-EB my $seq_cmd = $pod_seq->cmd_name(); @@ -522,8 +522,10 @@ sub _set_child2parent_links { my ($self, @children) = @_; ## Make sure any sequences know who their parent is for (@children) { - next unless (ref || ref eq 'SCALAR'); - if ($_->isa('Pod::InteriorSequence') or $_->can('nested')) { + next unless (length and ref and ref ne 'SCALAR'); + if (UNIVERSAL::isa($_, 'Pod::InteriorSequence') or + UNIVERSAL::can($_, 'nested')) + { $_->nested($self); } } @@ -537,13 +539,14 @@ sub _unset_child2parent_links { my $ptree = $self->{'-ptree'}; for (@$ptree) { next unless (length and ref and ref ne 'SCALAR'); - $_->_unset_child2parent_links() if $_->isa('Pod::InteriorSequence'); + $_->_unset_child2parent_links() + if UNIVERSAL::isa($_, 'Pod::InteriorSequence'); } } ##--------------------------------------------------------------------------- -=head2 B +=head2 $pod_seq-EB $pod_seq->prepend($text); $pod_seq1->prepend($pod_seq2); @@ -562,7 +565,7 @@ sub prepend { ##--------------------------------------------------------------------------- -=head2 B +=head2 $pod_seq-EB $pod_seq->append($text); $pod_seq1->append($pod_seq2); @@ -581,7 +584,7 @@ sub append { ##--------------------------------------------------------------------------- -=head2 B +=head2 $pod_seq-EB $outer_seq = $pod_seq->nested || print "not nested"; @@ -599,7 +602,7 @@ sub nested { ##--------------------------------------------------------------------------- -=head2 B +=head2 $pod_seq-EB my $seq_raw_text = $pod_seq->raw_text(); @@ -620,7 +623,7 @@ sub raw_text { ##--------------------------------------------------------------------------- -=head2 B +=head2 $pod_seq-EB my $ldelim = $pod_seq->left_delimiter(); @@ -639,7 +642,7 @@ sub left_delimiter { ##--------------------------------------------------------------------------- -=head2 B +=head2 $pod_seq-EB The rightmost delimiter beginning the argument text to the interior sequence (should be ">"). @@ -656,7 +659,7 @@ sub right_delimiter { ##--------------------------------------------------------------------------- -=head2 B +=head2 $pod_seq-EB my $ptree = $pod_parser->parse_text($paragraph_text); $pod_seq->parse_tree( $ptree ); @@ -677,13 +680,13 @@ sub parse_tree { ##--------------------------------------------------------------------------- -=head2 B +=head2 $pod_seq-EB my ($filename, $line_number) = $pod_seq->file_line(); my $position = $pod_seq->file_line(); Returns the current filename and line number for the interior sequence -object. If called in an array context, it returns a list of two +object. If called in a list context, it returns a list of two elements: first the filename, then the line number. If called in a scalar context, it returns a string containing the filename, followed by a colon (':'), followed by the line number. @@ -698,7 +701,7 @@ sub file_line { ##--------------------------------------------------------------------------- -=head2 B +=head2 Pod::InteriorSequence::B This method performs any necessary cleanup for the interior-sequence. If you override this method then it is B that you invoke @@ -735,7 +738,7 @@ itself contain a parse-tree (since interior sequences may be nested). ##--------------------------------------------------------------------------- -=head2 B +=head2 Pod::ParseTree-EB my $ptree1 = Pod::ParseTree->new; my $ptree2 = new Pod::ParseTree; @@ -763,7 +766,7 @@ sub new { ##--------------------------------------------------------------------------- -=head2 B +=head2 $ptree-EB my $top_node = $ptree->top(); $ptree->top( $top_node ); @@ -791,7 +794,7 @@ sub top { ##--------------------------------------------------------------------------- -=head2 B +=head2 $ptree-EB This method gets/sets the children of the top node in the parse-tree. If no arguments are given, it returns the list (array) of children @@ -811,7 +814,7 @@ sub children { ##--------------------------------------------------------------------------- -=head2 B +=head2 $ptree-EB This method prepends the given text or parse-tree to the current parse-tree. If the first item on the parse-tree is text and the argument is also text, @@ -839,7 +842,7 @@ sub prepend { ##--------------------------------------------------------------------------- -=head2 B +=head2 $ptree-EB This method appends the given text or parse-tree to the current parse-tree. If the last item on the parse-tree is text and the argument is also text, @@ -852,9 +855,15 @@ the current one. sub append { my $self = shift; local *ptree = $self; + my $can_append = @ptree && !(ref $ptree[-1]); for (@_) { - next unless length; - if (@ptree and !(ref $ptree[-1]) and !(ref $_)) { + if (ref) { + push @ptree, $_; + } + elsif(!length) { + next; + } + elsif ($can_append) { $ptree[-1] .= $_; } else { @@ -863,7 +872,7 @@ sub append { } } -=head2 B +=head2 $ptree-EB my $ptree_raw_text = $ptree->raw_text(); @@ -889,8 +898,9 @@ sub _unset_child2parent_links { my $self = shift; local *ptree = $self; for (@ptree) { - next unless (length and ref and ref ne 'SCALAR'); - $_->_unset_child2parent_links() if $_->isa('Pod::InteriorSequence'); + next unless (defined and length and ref and ref ne 'SCALAR'); + $_->_unset_child2parent_links() + if UNIVERSAL::isa($_, 'Pod::InteriorSequence'); } } @@ -898,7 +908,7 @@ sub _set_child2parent_links { ## nothing to do, Pod::ParseTrees cant have parent pointers } -=head2 B +=head2 Pod::ParseTree::B This method performs any necessary cleanup for the parse-tree. If you override this method then it is B @@ -918,10 +928,12 @@ sub DESTROY { =head1 SEE ALSO -See L, L, and L. +See L, L =head1 AUTHOR +Please report bugs using L. + Brad Appleton Ebradapp@enteract.comE =cut