| Filename | /Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/PPI/Token/Pod.pm |
| Statements | Executed 38796 statements in 91.6ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 9695 | 1 | 1 | 61.5ms | 65.6ms | PPI::Token::Pod::__TOKENIZER__on_line_start |
| 9695 | 1 | 1 | 3.62ms | 3.62ms | PPI::Token::Pod::CORE:match (opcode) |
| 1 | 1 | 1 | 12µs | 24µs | PPI::Token::Pod::BEGIN@29 |
| 1 | 1 | 1 | 8µs | 8µs | PPI::Token::Pod::BEGIN@34 |
| 1 | 1 | 1 | 6µs | 28µs | PPI::Token::Pod::BEGIN@30 |
| 1 | 1 | 1 | 6µs | 34µs | PPI::Token::Pod::BEGIN@33 |
| 5 | 2 | 2 | 6µs | 6µs | PPI::Token::Pod::significant |
| 1 | 1 | 1 | 3µs | 3µs | PPI::Token::Pod::BEGIN@31 |
| 0 | 0 | 0 | 0s | 0s | PPI::Token::Pod::lines |
| 0 | 0 | 0 | 0s | 0s | PPI::Token::Pod::merge |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 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 | Got any ideas for more methods? Submit a report to rt.cpan.org! | ||||
| 26 | |||||
| 27 | =cut | ||||
| 28 | |||||
| 29 | 2 | 22µs | 2 | 36µs | # spent 24µs (12+12) within PPI::Token::Pod::BEGIN@29 which was called:
# once (12µs+12µs) by PPI::Token::BEGIN@41 at line 29 # spent 24µs making 1 call to PPI::Token::Pod::BEGIN@29
# spent 12µs making 1 call to strict::import |
| 30 | 2 | 25µs | 2 | 49µs | # spent 28µs (6+22) within PPI::Token::Pod::BEGIN@30 which was called:
# once (6µs+22µs) by PPI::Token::BEGIN@41 at line 30 # spent 28µs making 1 call to PPI::Token::Pod::BEGIN@30
# spent 22µs making 1 call to Exporter::import |
| 31 | 2 | 19µs | 1 | 3µs | # spent 3µs within PPI::Token::Pod::BEGIN@31 which was called:
# once (3µs+0s) by PPI::Token::BEGIN@41 at line 31 # spent 3µs making 1 call to PPI::Token::Pod::BEGIN@31 |
| 32 | |||||
| 33 | 2 | 28µs | 2 | 63µs | # spent 34µs (6+28) within PPI::Token::Pod::BEGIN@33 which was called:
# once (6µs+28µs) by PPI::Token::BEGIN@41 at line 33 # spent 34µs making 1 call to PPI::Token::Pod::BEGIN@33
# spent 28µs making 1 call to vars::import |
| 34 | # spent 8µs within PPI::Token::Pod::BEGIN@34 which was called:
# once (8µs+0s) by PPI::Token::BEGIN@41 at line 37 | ||||
| 35 | 1 | 400ns | $VERSION = '1.215'; | ||
| 36 | 1 | 8µs | @ISA = 'PPI::Token'; | ||
| 37 | 1 | 293µs | 1 | 8µs | } # spent 8µs making 1 call to PPI::Token::Pod::BEGIN@34 |
| 38 | |||||
| - - | |||||
| 43 | ##################################################################### | ||||
| 44 | # PPI::Token::Pod Methods | ||||
| 45 | |||||
| 46 | =pod | ||||
| 47 | |||||
| 48 | =head2 merge @podtokens | ||||
| 49 | |||||
| 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. | ||||
| 53 | |||||
| 54 | Returns a new C<PPI::Token::Pod> object, or C<undef> on error. | ||||
| 55 | |||||
| 56 | =begin testing merge after PPI::Node 4 | ||||
| 57 | |||||
| 58 | # Create the test fragments | ||||
| 59 | my $one = PPI::Token::Pod->new("=pod\n\nOne\n\n=cut\n"); | ||||
| 60 | my $two = PPI::Token::Pod->new("=pod\n\nTwo"); | ||||
| 61 | isa_ok( $one, 'PPI::Token::Pod' ); | ||||
| 62 | isa_ok( $two, 'PPI::Token::Pod' ); | ||||
| 63 | |||||
| 64 | # Create the combined Pod | ||||
| 65 | my $merged = PPI::Token::Pod->merge($one, $two); | ||||
| 66 | isa_ok( $merged, 'PPI::Token::Pod' ); | ||||
| 67 | is( $merged->content, "=pod\n\nOne\n\nTwo\n\n=cut\n", 'Merged POD looks ok' ); | ||||
| 68 | |||||
| 69 | =end testing | ||||
| 70 | |||||
| 71 | =cut | ||||
| 72 | |||||
| 73 | sub merge { | ||||
| 74 | my $class = (! ref $_[0]) ? shift : return undef; | ||||
| 75 | |||||
| 76 | # Check there are no bad arguments | ||||
| 77 | if ( grep { ! _INSTANCE($_, 'PPI::Token::Pod') } @_ ) { | ||||
| 78 | return undef; | ||||
| 79 | } | ||||
| 80 | |||||
| 81 | # Get the tokens, and extract the lines | ||||
| 82 | my @content = ( map { [ $_->lines ] } @_ ) or return undef; | ||||
| 83 | |||||
| 84 | # Remove the leading =pod tags, trailing =cut tags, and any empty lines | ||||
| 85 | # between them and the pod contents. | ||||
| 86 | foreach my $pod ( @content ) { | ||||
| 87 | # Leading =pod tag | ||||
| 88 | if ( @$pod and $pod->[0] =~ /^=pod\b/o ) { | ||||
| 89 | shift @$pod; | ||||
| 90 | } | ||||
| 91 | |||||
| 92 | # Trailing =cut tag | ||||
| 93 | if ( @$pod and $pod->[-1] =~ /^=cut\b/o ) { | ||||
| 94 | pop @$pod; | ||||
| 95 | } | ||||
| 96 | |||||
| 97 | # Leading and trailing empty lines | ||||
| 98 | while ( @$pod and $pod->[0] eq '' ) { shift @$pod } | ||||
| 99 | while ( @$pod and $pod->[-1] eq '' ) { pop @$pod } | ||||
| 100 | } | ||||
| 101 | |||||
| 102 | # Remove any empty pod sections, and add the =pod and =cut tags | ||||
| 103 | # for the merged pod back to it. | ||||
| 104 | @content = ( [ '=pod' ], grep { @$_ } @content, [ '=cut' ] ); | ||||
| 105 | |||||
| 106 | # Create the new object | ||||
| 107 | $class->new( join "\n", map { join( "\n", @$_ ) . "\n" } @content ); | ||||
| 108 | } | ||||
| 109 | |||||
| 110 | =pod | ||||
| 111 | |||||
| 112 | =head2 lines | ||||
| 113 | |||||
| 114 | The C<lines> method takes the string of POD and breaks it into lines, | ||||
| 115 | returning them as a list. | ||||
| 116 | |||||
| 117 | =cut | ||||
| 118 | |||||
| 119 | sub lines { | ||||
| 120 | split /(?:\015{1,2}\012|\015|\012)/, $_[0]->{content}; | ||||
| 121 | } | ||||
| 122 | |||||
| - - | |||||
| 128 | ##################################################################### | ||||
| 129 | # PPI::Element Methods | ||||
| 130 | |||||
| 131 | ### XS -> PPI/XS.xs:_PPI_Token_Pod__significant 0.900+ | ||||
| 132 | 5 | 14µs | # spent 6µs within PPI::Token::Pod::significant which was called 5 times, avg 1µs/call:
# 3 times (3µs+0s) by PPI::Tokenizer::_previous_significant_tokens at line 699 of PPI/Tokenizer.pm, avg 1µs/call
# 2 times (3µs+0s) by PPI::Lexer::_lex_structure at line 1321 of PPI/Lexer.pm, avg 1µs/call | ||
| 133 | |||||
| - - | |||||
| 138 | ##################################################################### | ||||
| 139 | # Tokenizer Methods | ||||
| 140 | |||||
| 141 | # spent 65.6ms (61.5+4.04) within PPI::Token::Pod::__TOKENIZER__on_line_start which was called 9695 times, avg 7µs/call:
# 9695 times (61.5ms+4.04ms) by PPI::Tokenizer::_process_next_line at line 499 of PPI/Tokenizer.pm, avg 7µs/call | ||||
| 142 | 9695 | 1.36ms | my $t = $_[1]; | ||
| 143 | |||||
| 144 | # Add the line to the token first | ||||
| 145 | 9695 | 5.74ms | $t->{token}->{content} .= $t->{line}; | ||
| 146 | |||||
| 147 | # Check the line to see if it is a =cut line | ||||
| 148 | 9695 | 46.0ms | 9841 | 4.04ms | if ( $t->{line} =~ /^=(\w+)/ ) { # spent 3.62ms making 9695 calls to PPI::Token::Pod::CORE:match, avg 373ns/call
# spent 415µs making 146 calls to PPI::Tokenizer::_finalize_token, avg 3µs/call |
| 149 | # End of the token | ||||
| 150 | $t->_finalize_token if lc $1 eq 'cut'; | ||||
| 151 | } | ||||
| 152 | |||||
| 153 | 9695 | 38.1ms | 0; | ||
| 154 | } | ||||
| 155 | |||||
| 156 | 1 | 2µs | 1; | ||
| 157 | |||||
| 158 | =pod | ||||
| 159 | |||||
| 160 | =head1 SUPPORT | ||||
| 161 | |||||
| 162 | See the L<support section|PPI/SUPPORT> in the main module. | ||||
| 163 | |||||
| 164 | =head1 AUTHOR | ||||
| 165 | |||||
| 166 | Adam Kennedy E<lt>adamk@cpan.orgE<gt> | ||||
| 167 | |||||
| 168 | =head1 COPYRIGHT | ||||
| 169 | |||||
| 170 | Copyright 2001 - 2011 Adam Kennedy. | ||||
| 171 | |||||
| 172 | This program is free software; you can redistribute | ||||
| 173 | it and/or modify it under the same terms as Perl itself. | ||||
| 174 | |||||
| 175 | The full text of the license can be found in the | ||||
| 176 | LICENSE file included with this module. | ||||
| 177 | |||||
| 178 | =cut | ||||
# spent 3.62ms within PPI::Token::Pod::CORE:match which was called 9695 times, avg 373ns/call:
# 9695 times (3.62ms+0s) by PPI::Token::Pod::__TOKENIZER__on_line_start at line 148, avg 373ns/call |