| 1 | package PPI::Token::Pod; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | =pod | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | =head1 NAME | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | PPI::Token::Pod - Sections of POD in Perl documents | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | =head1 INHERITANCE | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | PPI::Token::Pod | ||||||||||||||||||||||||||||
| 12 | isa PPI::Token | ||||||||||||||||||||||||||||
| 13 | isa PPI::Element | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | A single C<PPI::Token::Pod> object represents a complete section of POD | ||||||||||||||||||||||||||||
| 18 | documentation within a Perl document. | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | =head1 METHODS | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | This class provides some additional methods beyond those provided by its | ||||||||||||||||||||||||||||
| 23 | L<PPI::Token> and L<PPI::Element> parent classes. | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | =cut | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 63 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 28 | 63 | ▶ | use Params::Util qw{_INSTANCE}; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 29 | 63 | ▶ | use PPI::Token (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 63 | our $VERSION = '1.260'; # VERSION | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 63 | our @ISA = "PPI::Token"; | |||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | ##################################################################### | ||||||||||||||||||||||||||||
| 40 | # PPI::Token::Pod Methods | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | =pod | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | =head2 merge @podtokens | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | The C<merge> constructor takes a number of C<PPI::Token::Pod> objects, | ||||||||||||||||||||||||||||
| 47 | and returns a new object that represents one combined POD block with | ||||||||||||||||||||||||||||
| 48 | the content of all of them. | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | Returns a new C<PPI::Token::Pod> object, or C<undef> on error. | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | =cut | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | sub merge { | ||||||||||||||||||||||||||||
| 55 | 1 | ▶ | my $class = (! ref $_[0]) ? shift : return undef; | ||||||||||||||||||||||||||
|
Subroutine
merge: called CC=13 SCAR=27.0
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | # Check there are no bad arguments | ||||||||||||||||||||||||||||
| 58 | 1 | ▶ | if ( grep { ! _INSTANCE($_, 'PPI::Token::Pod') } @_ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | 0 | return undef; | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | # Get the tokens, and extract the lines | ||||||||||||||||||||||||||||
| 63 | 1 | ▶ | my @content = ( map { [ $_->lines ] } @_ ) or return undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | # Remove the leading =pod tags, trailing =cut tags, and any empty lines | ||||||||||||||||||||||||||||
| 66 | # between them and the pod contents. | ||||||||||||||||||||||||||||
| 67 | 1 | foreach my $pod ( @content ) { | |||||||||||||||||||||||||||
| 68 | # Leading =pod tag | ||||||||||||||||||||||||||||
| 69 | 2 | ▶ | if ( @$pod and $pod->[0] =~ /^=pod\b/o ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@$pod and $pod->[0] =~ /^=pod\b/o
MC/DC0%0/2
@$pod and $pod->[0] =~ /^=pod\b/o
@$pod
$pod->[0] =~ /^=pod\b/o
Truth table33%1/3
A and B
A= @$podB= $pod->[0] =~ /^=pod\b/o
| |||||||||||||||||||||||||||||
| 70 | 2 | shift @$pod; | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | # Trailing =cut tag | ||||||||||||||||||||||||||||
| 74 | 2 | ▶ | if ( @$pod and $pod->[-1] =~ /^=cut\b/o ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@$pod and $pod->[-1] =~ /^=cut\b/o
MC/DC50%1/2
@$pod and $pod->[-1] =~ /^=cut\b/o
@$pod
$pod->[-1] =~ /^=cut\b/o
Truth table66%2/3
A and B
A= @$podB= $pod->[-1] =~ /^=cut\b/o
| |||||||||||||||||||||||||||||
| 75 | 1 | pop @$pod; | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | # Leading and trailing empty lines | ||||||||||||||||||||||||||||
| 79 | 2 | ▶ | while ( @$pod and $pod->[0] eq '' ) { shift @$pod } | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@$pod and $pod->[0] eq ""
MC/DC50%1/2
@$pod and $pod->[0] eq ""
@$pod
$pod->[0] eq ""
Truth table66%2/3
A and B
A= @$podB= $pod->[0] eq ""
| |||||||||||||||||||||||||||||
| 80 | 2 | ▶ | while ( @$pod and $pod->[-1] eq '' ) { pop @$pod } | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@$pod and $pod->[-1] eq ""
MC/DC50%1/2
@$pod and $pod->[-1] eq ""
@$pod
$pod->[-1] eq ""
Truth table66%2/3
A and B
A= @$podB= $pod->[-1] eq ""
| |||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | # Remove any empty pod sections, and add the =pod and =cut tags | ||||||||||||||||||||||||||||
| 84 | # for the merged pod back to it. | ||||||||||||||||||||||||||||
| 85 | 1 | @content = ( [ '=pod' ], grep { @$_ } @content, [ '=cut' ] ); | |||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | # Create the new object | ||||||||||||||||||||||||||||
| 88 | 1 | $class->new( join "\n", map { join( "\n", @$_ ) . "\n" } @content ); | |||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | =pod | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | =head2 lines | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | The C<lines> method takes the string of POD and breaks it into lines, | ||||||||||||||||||||||||||||
| 96 | returning them as a list. | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | =cut | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | sub lines { | ||||||||||||||||||||||||||||
| 101 | 2 | ▶ | split /(?:\015{1,2}\012|\015|\012)/, $_[0]->{content}; | ||||||||||||||||||||||||||
|
Subroutine
lines: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | ##################################################################### | ||||||||||||||||||||||||||||
| 110 | # PPI::Element Methods | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | ### XS -> PPI/XS.xs:_PPI_Token_Pod__significant 0.900+ | ||||||||||||||||||||||||||||
| 113 | sub significant() { '' } | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | ##################################################################### | ||||||||||||||||||||||||||||
| 120 | # Tokenizer Methods | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | sub __TOKENIZER__on_line_start { | ||||||||||||||||||||||||||||
| 123 | 15974 | ▶ | my $t = $_[1]; | ||||||||||||||||||||||||||
|
Subroutine
__TOKENIZER__on_line_start: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | # Add the line to the token first | ||||||||||||||||||||||||||||
| 126 | 15974 | $t->{token}->{content} .= $t->{line}; | |||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | # Check the line to see if it is a =cut line | ||||||||||||||||||||||||||||
| 129 | 15974 | ▶ | if ( $t->{line} =~ /^=(\w+)/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 130 | # End of the token | ||||||||||||||||||||||||||||
| 131 | 2570 | ▶ | $t->_finalize_token if $1 eq 'cut'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | 15974 | 0; | |||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | 63 | 1; | |||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | =pod | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | =head1 SUPPORT | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | See the L<support section|PPI/SUPPORT> in the main module. | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | Adam Kennedy E<lt>adamk@cpan.orgE<gt> | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | Copyright 2001 - 2011 Adam Kennedy. | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | This program is free software; you can redistribute | ||||||||||||||||||||||||||||
| 154 | it and/or modify it under the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | The full text of the license can be found in the | ||||||||||||||||||||||||||||
| 157 | LICENSE file included with this module. | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | =cut | ||||||||||||||||||||||||||||