PPI/Token/Pod.pm

filter: Statementstmt 97.5% 39 / 40 Branchbran 77.7% 14 / 18 Conditioncond 58.3% 7 / 12 MC/DCmcdc 37.5% 3 / 8 Subroutinesub 100% 8 / 8 Podpod 100% 2 / 2 totaltotal 82.9% 73 / 88 CC 15 SCAR 22.5
CC
15
Cov
86%
merge
14.9
__TOKENIZER__on_line_start
3.0
BEGIN
1.0
CRAP 9.5
« PPI/Token/Number.pm ↑ Summary PPI/Structure.pm »
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 62 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 62 ▶use Params::Util qw{_INSTANCE};
Subroutine BEGIN: called CC=1 SCAR=0.0
29 62 ▶use PPI::Token ();
Subroutine BEGIN: called CC=1 SCAR=0.0
30  
31 62 ▶use vars qw{$VERSION @ISA};
Subroutine BEGIN: called CC=1 SCAR=0.0
32 BEGIN {
33 62 ▶ $VERSION = '1.236';
Subroutine BEGIN: called CC=1 SCAR=0.0
34 62 @ISA = 'PPI::Token';
35 }
36  
37  
38  
39  
40  
41 #####################################################################
42 # PPI::Token::Pod Methods
43  
44 =pod
45  
46 =head2 merge @podtokens
47  
48 The C<merge> constructor takes a number of C<PPI::Token::Pod> objects,
49 and returns a new object that represents one combined POD block with
50 the content of all of them.
51  
52 Returns a new C<PPI::Token::Pod> object, or C<undef> on error.
53  
54 =cut
55  
56 sub merge {
57 1 ▶ my $class = (! ref $_[0]) ? shift : return undef;
Subroutine merge: called CC=13 SCAR=27.0
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
!ref($_[0]) ? : 1 0 1
58  
59 # Check there are no bad arguments
60 1 ▶ if ( grep { ! _INSTANCE($_, 'PPI::Token::Pod') } @_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {not &_INSTANCE($_, "PPI::Token::Pod");} @_) 0 1 1
61 0 return undef;
62 }
63  
64 # Get the tokens, and extract the lines
65 1 ▶ my @content = ( map { [ $_->lines ] } @_ ) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my(@content) = map({[$_->lines];} @_) or return undef 0 1 1
66  
67 # Remove the leading =pod tags, trailing =cut tags, and any empty lines
68 # between them and the pod contents.
69 1 foreach my $pod ( @content ) {
70 # Leading =pod tag
71 2 ▶ if ( @$pod and $pod->[0] =~ /^=pod\b/o ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$pod and $pod->[0] =~ /^=pod\b/o) 2 0 2
Condition33%1/3
@$pod and $pod->[0] =~ /^=pod\b/o
!ll&&!rl&&r
002
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
ABresult
0X0
100
111
72 2 shift @$pod;
73 }
74  
75 # Trailing =cut tag
76 2 ▶ if ( @$pod and $pod->[-1] =~ /^=cut\b/o ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$pod and $pod->[-1] =~ /^=cut\b/o) 1 1 2
Condition66%2/3
@$pod and $pod->[-1] =~ /^=cut\b/o
!ll&&!rl&&r
011
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
ABresult
0X0
100
111
77 1 pop @$pod;
78 }
79  
80 # Leading and trailing empty lines
81 2 ▶ while ( @$pod and $pod->[0] eq '' ) { shift @$pod }
Branch: 1 branch
BranchTrueFalseTotal
if (@$pod and $pod->[0] eq "") 2 2 4
Condition66%2/3
@$pod and $pod->[0] eq ""
!ll&&!rl&&r
022
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 ""
ABresult
0X0
100
111
82 2 ▶ while ( @$pod and $pod->[-1] eq '' ) { pop @$pod }
Branch: 1 branch
BranchTrueFalseTotal
if (@$pod and $pod->[-1] eq "") 1 2 3
Condition66%2/3
@$pod and $pod->[-1] eq ""
!ll&&!rl&&r
021
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 ""
ABresult
0X0
100
111
83 }
84  
85 # Remove any empty pod sections, and add the =pod and =cut tags
86 # for the merged pod back to it.
87 1 @content = ( [ '=pod' ], grep { @$_ } @content, [ '=cut' ] );
88  
89 # Create the new object
90 1 $class->new( join "\n", map { join( "\n", @$_ ) . "\n" } @content );
91 }
92  
93 =pod
94  
95 =head2 lines
96  
97 The C<lines> method takes the string of POD and breaks it into lines,
98 returning them as a list.
99  
100 =cut
101  
102 sub lines {
103 2 ▶ split /(?:\015{1,2}\012|\015|\012)/, $_[0]->{content};
Subroutine lines: called CC=1 SCAR=0.0
Pod documented
104 }
105  
106  
107  
108  
109  
110  
111 #####################################################################
112 # PPI::Element Methods
113  
114 ### XS -> PPI/XS.xs:_PPI_Token_Pod__significant 0.900+
115 sub significant() { '' }
116  
117  
118  
119  
120  
121 #####################################################################
122 # Tokenizer Methods
123  
124 sub __TOKENIZER__on_line_start {
125 15976 ▶ my $t = $_[1];
Subroutine __TOKENIZER__on_line_start: called CC=3 SCAR=11.0
126  
127 # Add the line to the token first
128 15976 $t->{token}->{content} .= $t->{line};
129  
130 # Check the line to see if it is a =cut line
131 15976 ▶ if ( $t->{line} =~ /^=(\w+)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t->{"line"} =~ /^=(\w+)/) 2564 13412 15976
132 # End of the token
133 2564 ▶ $t->_finalize_token if $1 eq 'cut';
Branch: 1 branch
BranchTrueFalseTotal
if $1 eq "cut" 704 1860 2564
134 }
135  
136 15976 0;
137 }
138  
139 62 1;
140  
141 =pod
142  
143 =head1 SUPPORT
144  
145 See the L<support section|PPI/SUPPORT> in the main module.
146  
147 =head1 AUTHOR
148  
149 Adam Kennedy E<lt>adamk@cpan.orgE<gt>
150  
151 =head1 COPYRIGHT
152  
153 Copyright 2001 - 2011 Adam Kennedy.
154  
155 This program is free software; you can redistribute
156 it and/or modify it under the same terms as Perl itself.
157  
158 The full text of the license can be found in the
159 LICENSE file included with this module.
160  
161 =cut
« PPI/Token/Number.pm ↑ Summary PPI/Structure.pm »