1 package PPI::Token::Pod;
7 PPI::Token::Pod - Sections of POD in Perl documents
17 A single C<PPI::Token::Pod> object represents a complete section of POD
18 documentation within a Perl document.
22 This class provides some additional methods beyond those provided by its
23 L<PPI::Token> and L<PPI::Element> parent classes.
25 Got any ideas for more methods? Submit a report to rt.cpan.org!
30 use Params::Util qw{_INSTANCE};
33 use vars qw{$VERSION @ISA};
43 #####################################################################
44 # PPI::Token::Pod Methods
48 =head2 merge @podtokens
50 The C<merge> constructor takes a number of C<PPI::Token::Pod> objects,
51 and returns a new object that represents one combined POD block with
52 the content of all of them.
54 Returns a new C<PPI::Token::Pod> object, or C<undef> on error.
59 my $class = (! ref $_[0]) ? shift : return undef;
61 # Check there are no bad arguments
62 if ( grep { ! _INSTANCE($_, 'PPI::Token::Pod') } @_ ) {
66 # Get the tokens, and extract the lines
67 my @content = (map { $_->lines } @_) or return undef;
69 # Remove the leading =pod tags, trailing =cut tags, and any empty lines
70 # between them and the pod contents.
71 foreach my $pod ( @content ) {
73 if ( @$pod and $pod->[0] =~ /^=pod\b/o ) {
78 if ( @$pod and $pod->[-1] =~ /^=cut\b/o ) {
82 # Leading and trailing empty lines
83 while ( @$pod and $pod->[0] eq '' ) { shift @$pod }
84 while ( @$pod and $pod->[-1] eq '' ) { pop @$pod }
87 # Remove any empty pod sections, and add the =pod and =cut tags
88 # for the merged pod back to it.
89 @content = ( [ '=pod' ], grep { @$_ } @content, [ '=cut' ] );
91 # Create the new object
92 $class->new( join "\n", map { join( "\n", @$_ ) . "\n" } @content );
99 The C<lines> method takes the string of POD and breaks it into lines,
100 returning them as a list.
104 sub lines { split /(?:\015{1,2}\012|\015|\012)/, $_[0]->{content} }
111 #####################################################################
112 # PPI::Element Methods
114 ### XS -> PPI/XS.xs:_PPI_Token_Pod__significant 0.900+
115 sub significant { '' }
121 #####################################################################
124 sub __TOKENIZER__on_line_start {
127 # Add the line to the token first
128 $t->{token}->{content} .= $t->{line};
130 # Check the line to see if it is a =cut line
131 if ( $t->{line} =~ /^=(\w+)/ ) {
133 $t->_finalize_token if lc $1 eq 'cut';
145 See the L<support section|PPI/SUPPORT> in the main module.
149 Adam Kennedy E<lt>adamk@cpan.orgE<gt>
153 Copyright 2001 - 2009 Adam Kennedy.
155 This program is free software; you can redistribute
156 it and/or modify it under the same terms as Perl itself.
158 The full text of the license can be found in the
159 LICENSE file included with this module.