| Filename | /Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/PPI/Token/Comment.pm |
| Statements | Executed 6196 statements in 11.7ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 4493 | 9 | 5 | 5.12ms | 5.12ms | PPI::Token::Comment::significant |
| 242 | 1 | 1 | 2.30ms | 7.72ms | PPI::Token::Comment::__TOKENIZER__commit |
| 1 | 1 | 1 | 12µs | 26µs | PPI::Token::Comment::BEGIN@61 |
| 1 | 1 | 1 | 8µs | 8µs | PPI::Token::Comment::BEGIN@65 |
| 1 | 1 | 1 | 6µs | 35µs | PPI::Token::Comment::BEGIN@64 |
| 1 | 1 | 1 | 3µs | 3µs | PPI::Token::Comment::BEGIN@62 |
| 0 | 0 | 0 | 0s | 0s | PPI::Token::Comment::__TOKENIZER__on_char |
| 0 | 0 | 0 | 0s | 0s | PPI::Token::Comment::__TOKENIZER__on_line_end |
| 0 | 0 | 0 | 0s | 0s | PPI::Token::Comment::line |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package PPI::Token::Comment; | ||||
| 2 | |||||
| 3 | =pod | ||||
| 4 | |||||
| 5 | =head1 NAME | ||||
| 6 | |||||
| 7 | PPI::Token::Comment - A comment in Perl source code | ||||
| 8 | |||||
| 9 | =head1 INHERITANCE | ||||
| 10 | |||||
| 11 | PPI::Token::Comment | ||||
| 12 | isa PPI::Token | ||||
| 13 | isa PPI::Element | ||||
| 14 | |||||
| 15 | =head1 SYNOPSIS | ||||
| 16 | |||||
| 17 | # This is a PPI::Token::Comment | ||||
| 18 | |||||
| 19 | print "Hello World!"; # So it this | ||||
| 20 | |||||
| 21 | $string =~ s/ foo # This, unfortunately, is not :( | ||||
| 22 | bar | ||||
| 23 | /w; | ||||
| 24 | |||||
| 25 | =head1 DESCRIPTION | ||||
| 26 | |||||
| 27 | In PPI, comments are represented by C<PPI::Token::Comment> objects. | ||||
| 28 | |||||
| 29 | These come in two flavours, line comment and inline comments. | ||||
| 30 | |||||
| 31 | A C<line comment> is a comment that stands on its own line. These comments | ||||
| 32 | hold their own newline and whitespace (both leading and trailing) as part | ||||
| 33 | of the one C<PPI::Token::Comment> object. | ||||
| 34 | |||||
| 35 | An inline comment is a comment that appears after some code, and | ||||
| 36 | continues to the end of the line. This does B<not> include whitespace, | ||||
| 37 | and the terminating newlines is considered a separate | ||||
| 38 | L<PPI::Token::Whitespace> token. | ||||
| 39 | |||||
| 40 | This is largely a convenience, simplifying a lot of normal code relating | ||||
| 41 | to the common things people do with comments. | ||||
| 42 | |||||
| 43 | Most commonly, it means when you C<prune> or C<delete> a comment, a line | ||||
| 44 | comment disappears taking the entire line with it, and an inline comment | ||||
| 45 | is removed from the inside of the line, allowing the newline to drop | ||||
| 46 | back onto the end of the code, as you would expect. | ||||
| 47 | |||||
| 48 | It also means you can move comments around in blocks much more easily. | ||||
| 49 | |||||
| 50 | For now, this is a suitably handy way to do things. However, I do reserve | ||||
| 51 | the right to change my mind on this one if it gets dangerously | ||||
| 52 | anachronistic somewhere down the line. | ||||
| 53 | |||||
| 54 | =head1 METHODS | ||||
| 55 | |||||
| 56 | Only very limited methods are available, beyond those provided by our | ||||
| 57 | parent L<PPI::Token> and L<PPI::Element> classes. | ||||
| 58 | |||||
| 59 | =cut | ||||
| 60 | |||||
| 61 | 2 | 20µs | 2 | 39µs | # spent 26µs (12+13) within PPI::Token::Comment::BEGIN@61 which was called:
# once (12µs+13µs) by PPI::Token::BEGIN@40 at line 61 # spent 26µs making 1 call to PPI::Token::Comment::BEGIN@61
# spent 13µs making 1 call to strict::import |
| 62 | 2 | 19µs | 1 | 3µs | # spent 3µs within PPI::Token::Comment::BEGIN@62 which was called:
# once (3µs+0s) by PPI::Token::BEGIN@40 at line 62 # spent 3µs making 1 call to PPI::Token::Comment::BEGIN@62 |
| 63 | |||||
| 64 | 2 | 33µs | 2 | 64µs | # spent 35µs (6+29) within PPI::Token::Comment::BEGIN@64 which was called:
# once (6µs+29µs) by PPI::Token::BEGIN@40 at line 64 # spent 35µs making 1 call to PPI::Token::Comment::BEGIN@64
# spent 29µs making 1 call to vars::import |
| 65 | # spent 8µs within PPI::Token::Comment::BEGIN@65 which was called:
# once (8µs+0s) by PPI::Token::BEGIN@40 at line 68 | ||||
| 66 | 1 | 400ns | $VERSION = '1.215'; | ||
| 67 | 1 | 8µs | @ISA = 'PPI::Token'; | ||
| 68 | 1 | 178µs | 1 | 8µs | } # spent 8µs making 1 call to PPI::Token::Comment::BEGIN@65 |
| 69 | |||||
| 70 | ### XS -> PPI/XS.xs:_PPI_Token_Comment__significant 0.900+ | ||||
| 71 | 4493 | 9.73ms | # spent 5.12ms within PPI::Token::Comment::significant which was called 4493 times, avg 1µs/call:
# 1824 times (1.88ms+0s) by PPI::Tokenizer::_previous_significant_tokens at line 699 of PPI/Tokenizer.pm, avg 1µs/call
# 944 times (1.19ms+0s) by PPI::Lexer::_lex_structure at line 1321 of PPI/Lexer.pm, avg 1µs/call
# 940 times (1.11ms+0s) by PPI::Lexer::_lex_document at line 272 of PPI/Lexer.pm, avg 1µs/call
# 665 times (813µs+0s) by PPI::Lexer::_lex_statement at line 608 of PPI/Lexer.pm, avg 1µs/call
# 92 times (91µs+0s) by PPI::Node::schild at line 282 of PPI/Node.pm, avg 988ns/call
# 11 times (14µs+0s) by PPI::Element::snext_sibling at line 370 of PPI/Element.pm, avg 1µs/call
# 10 times (12µs+0s) by PPI::Element::sprevious_sibling at line 418 of PPI/Element.pm, avg 1µs/call
# 5 times (7µs+0s) by PPI::Lexer::_curly at line 1264 of PPI/Lexer.pm, avg 1µs/call
# 2 times (3µs+0s) by PPI::Statement::Variable::type at line 67 of PPI/Statement/Variable.pm, avg 2µs/call | ||
| 72 | |||||
| 73 | # Most stuff goes through __TOKENIZER__commit. | ||||
| 74 | # This is such a rare case, do char at a time to keep the code small | ||||
| 75 | sub __TOKENIZER__on_char { | ||||
| 76 | my $t = $_[1]; | ||||
| 77 | |||||
| 78 | # Make sure not to include the trailing newline | ||||
| 79 | if ( substr( $t->{line}, $t->{line_cursor}, 1 ) eq "\n" ) { | ||||
| 80 | return $t->_finalize_token->__TOKENIZER__on_char( $t ); | ||||
| 81 | } | ||||
| 82 | |||||
| 83 | 1; | ||||
| 84 | } | ||||
| 85 | |||||
| 86 | # spent 7.72ms (2.30+5.42) within PPI::Token::Comment::__TOKENIZER__commit which was called 242 times, avg 32µs/call:
# 242 times (2.30ms+5.42ms) by PPI::Token::Whitespace::__TOKENIZER__on_char at line 206 of PPI/Token/Whitespace.pm, avg 32µs/call | ||||
| 87 | 242 | 72µs | my $t = $_[1]; | ||
| 88 | |||||
| 89 | # Get the rest of the line | ||||
| 90 | 242 | 224µs | my $rest = substr( $t->{line}, $t->{line_cursor} ); | ||
| 91 | 242 | 209µs | if ( chomp $rest ) { # Include the newline separately | ||
| 92 | # Add the current token, and the newline | ||||
| 93 | 242 | 285µs | 242 | 2.79ms | $t->_new_token('Comment', $rest); # spent 2.79ms making 242 calls to PPI::Tokenizer::_new_token, avg 12µs/call |
| 94 | 242 | 316µs | 242 | 2.62ms | $t->_new_token('Whitespace', "\n"); # spent 2.62ms making 242 calls to PPI::Tokenizer::_new_token, avg 11µs/call |
| 95 | } else { | ||||
| 96 | # Add this token only | ||||
| 97 | $t->_new_token('Comment', $rest); | ||||
| 98 | } | ||||
| 99 | |||||
| 100 | # Advance the line cursor to the end | ||||
| 101 | 242 | 188µs | $t->{line_cursor} = $t->{line_length} - 1; | ||
| 102 | |||||
| 103 | 242 | 455µs | 0; | ||
| 104 | } | ||||
| 105 | |||||
| 106 | # Comments end at the end of the line | ||||
| 107 | sub __TOKENIZER__on_line_end { | ||||
| 108 | $_[1]->_finalize_token if $_[1]->{token}; | ||||
| 109 | 1; | ||||
| 110 | } | ||||
| 111 | |||||
| 112 | =pod | ||||
| 113 | |||||
| 114 | =head2 line | ||||
| 115 | |||||
| 116 | The C<line> accessor returns true if the C<PPI::Token::Comment> is a | ||||
| 117 | line comment, or false if it is an inline comment. | ||||
| 118 | |||||
| 119 | =cut | ||||
| 120 | |||||
| 121 | sub line { | ||||
| 122 | # Entire line comments have a newline at the end | ||||
| 123 | $_[0]->{content} =~ /\n$/ ? 1 : 0; | ||||
| 124 | } | ||||
| 125 | |||||
| 126 | 1 | 2µs | 1; | ||
| 127 | |||||
| 128 | =pod | ||||
| 129 | |||||
| 130 | =head1 SUPPORT | ||||
| 131 | |||||
| 132 | See the L<support section|PPI/SUPPORT> in the main module. | ||||
| 133 | |||||
| 134 | =head1 AUTHOR | ||||
| 135 | |||||
| 136 | Adam Kennedy E<lt>adamk@cpan.orgE<gt> | ||||
| 137 | |||||
| 138 | =head1 COPYRIGHT | ||||
| 139 | |||||
| 140 | Copyright 2001 - 2011 Adam Kennedy. | ||||
| 141 | |||||
| 142 | This program is free software; you can redistribute | ||||
| 143 | it and/or modify it under the same terms as Perl itself. | ||||
| 144 | |||||
| 145 | The full text of the license can be found in the | ||||
| 146 | LICENSE file included with this module. | ||||
| 147 | |||||
| 148 | =cut |