← Index
NYTProf Performance Profile   « line view »
For /Users/timbo/perl5/perlbrew/perls/perl-5.18.2/bin/perlcritic
  Run on Sat Mar 19 22:12:22 2016
Reported on Sat Mar 19 22:14:10 2016

Filename/Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/PPI/Token/Comment.pm
StatementsExecuted 6196 statements in 11.7ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
4493955.12ms5.12msPPI::Token::Comment::::significantPPI::Token::Comment::significant
242112.30ms7.72msPPI::Token::Comment::::__TOKENIZER__commitPPI::Token::Comment::__TOKENIZER__commit
11112µs26µsPPI::Token::Comment::::BEGIN@61PPI::Token::Comment::BEGIN@61
1118µs8µsPPI::Token::Comment::::BEGIN@65PPI::Token::Comment::BEGIN@65
1116µs35µsPPI::Token::Comment::::BEGIN@64PPI::Token::Comment::BEGIN@64
1113µs3µsPPI::Token::Comment::::BEGIN@62PPI::Token::Comment::BEGIN@62
0000s0sPPI::Token::Comment::::__TOKENIZER__on_charPPI::Token::Comment::__TOKENIZER__on_char
0000s0sPPI::Token::Comment::::__TOKENIZER__on_line_endPPI::Token::Comment::__TOKENIZER__on_line_end
0000s0sPPI::Token::Comment::::linePPI::Token::Comment::line
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package PPI::Token::Comment;
2
3=pod
4
5=head1 NAME
6
7PPI::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
27In PPI, comments are represented by C<PPI::Token::Comment> objects.
28
29These come in two flavours, line comment and inline comments.
30
31A C<line comment> is a comment that stands on its own line. These comments
32hold their own newline and whitespace (both leading and trailing) as part
33of the one C<PPI::Token::Comment> object.
34
35An inline comment is a comment that appears after some code, and
36continues to the end of the line. This does B<not> include whitespace,
37and the terminating newlines is considered a separate
38L<PPI::Token::Whitespace> token.
39
40This is largely a convenience, simplifying a lot of normal code relating
41to the common things people do with comments.
42
43Most commonly, it means when you C<prune> or C<delete> a comment, a line
44comment disappears taking the entire line with it, and an inline comment
45is removed from the inside of the line, allowing the newline to drop
46back onto the end of the code, as you would expect.
47
48It also means you can move comments around in blocks much more easily.
49
50For now, this is a suitably handy way to do things. However, I do reserve
51the right to change my mind on this one if it gets dangerously
52anachronistic somewhere down the line.
53
54=head1 METHODS
55
56Only very limited methods are available, beyond those provided by our
57parent L<PPI::Token> and L<PPI::Element> classes.
58
59=cut
60
61220µs239µ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
use strict;
# spent 26µs making 1 call to PPI::Token::Comment::BEGIN@61 # spent 13µs making 1 call to strict::import
62219µs13µ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
use PPI::Token ();
# spent 3µs making 1 call to PPI::Token::Comment::BEGIN@62
63
64233µs264µ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
use vars qw{$VERSION @ISA};
# 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
BEGIN {
661400ns $VERSION = '1.215';
6718µs @ISA = 'PPI::Token';
681178µs18µ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+
7144939.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
sub significant { '' }
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
75sub __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
sub __TOKENIZER__commit {
8724272µs my $t = $_[1];
88
89 # Get the rest of the line
90242224µs my $rest = substr( $t->{line}, $t->{line_cursor} );
91242209µs if ( chomp $rest ) { # Include the newline separately
92 # Add the current token, and the newline
93242285µs2422.79ms $t->_new_token('Comment', $rest);
# spent 2.79ms making 242 calls to PPI::Tokenizer::_new_token, avg 12µs/call
94242316µs2422.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
101242188µs $t->{line_cursor} = $t->{line_length} - 1;
102
103242455µs 0;
104}
105
106# Comments end at the end of the line
107sub __TOKENIZER__on_line_end {
108 $_[1]->_finalize_token if $_[1]->{token};
109 1;
110}
111
112=pod
113
114=head2 line
115
116The C<line> accessor returns true if the C<PPI::Token::Comment> is a
117line comment, or false if it is an inline comment.
118
119=cut
120
121sub line {
122 # Entire line comments have a newline at the end
123 $_[0]->{content} =~ /\n$/ ? 1 : 0;
124}
125
12612µs1;
127
128=pod
129
130=head1 SUPPORT
131
132See the L<support section|PPI/SUPPORT> in the main module.
133
134=head1 AUTHOR
135
136Adam Kennedy E<lt>adamk@cpan.orgE<gt>
137
138=head1 COPYRIGHT
139
140Copyright 2001 - 2011 Adam Kennedy.
141
142This program is free software; you can redistribute
143it and/or modify it under the same terms as Perl itself.
144
145The full text of the license can be found in the
146LICENSE file included with this module.
147
148=cut