| Filename | /Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/PPI/Statement/Sub.pm |
| Statements | Executed 11183 statements in 54.1ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1016 | 1 | 1 | 7.17ms | 47.5ms | PPI::Statement::Sub::prototype |
| 3042 | 1 | 1 | 3.39ms | 3.39ms | PPI::Statement::Sub::__LEXER__normal |
| 1 | 1 | 1 | 11µs | 22µs | PPI::Statement::Sub::BEGIN@33 |
| 1 | 1 | 1 | 8µs | 8µs | PPI::Statement::Sub::BEGIN@39 |
| 1 | 1 | 1 | 7µs | 32µs | PPI::Statement::Sub::BEGIN@35 |
| 1 | 1 | 1 | 6µs | 33µs | PPI::Statement::Sub::BEGIN@38 |
| 1 | 1 | 1 | 3µs | 3µs | PPI::Statement::Sub::BEGIN@34 |
| 1 | 1 | 1 | 3µs | 3µs | PPI::Statement::Sub::BEGIN@36 |
| 0 | 0 | 0 | 0s | 0s | PPI::Statement::Sub::__ANON__[:100] |
| 0 | 0 | 0 | 0s | 0s | PPI::Statement::Sub::_complete |
| 0 | 0 | 0 | 0s | 0s | PPI::Statement::Sub::block |
| 0 | 0 | 0 | 0s | 0s | PPI::Statement::Sub::forward |
| 0 | 0 | 0 | 0s | 0s | PPI::Statement::Sub::name |
| 0 | 0 | 0 | 0s | 0s | PPI::Statement::Sub::reserved |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package PPI::Statement::Sub; | ||||
| 2 | |||||
| 3 | =pod | ||||
| 4 | |||||
| 5 | =head1 NAME | ||||
| 6 | |||||
| 7 | PPI::Statement::Sub - Subroutine declaration | ||||
| 8 | |||||
| 9 | =head1 INHERITANCE | ||||
| 10 | |||||
| 11 | PPI::Statement::Sub | ||||
| 12 | isa PPI::Statement | ||||
| 13 | isa PPI::Node | ||||
| 14 | isa PPI::Element | ||||
| 15 | |||||
| 16 | =head1 DESCRIPTION | ||||
| 17 | |||||
| 18 | Except for the special BEGIN, CHECK, UNITCHECK, INIT, and END subroutines | ||||
| 19 | (which are part of L<PPI::Statement::Scheduled>) all subroutine declarations | ||||
| 20 | are lexed as a PPI::Statement::Sub object. | ||||
| 21 | |||||
| 22 | Primarily, this means all of the various C<sub foo {}> statements, but also | ||||
| 23 | forward declarations such as C<sub foo;> or C<sub foo($);>. It B<does not> | ||||
| 24 | include anonymous subroutines, as these are merely part of a normal statement. | ||||
| 25 | |||||
| 26 | =head1 METHODS | ||||
| 27 | |||||
| 28 | C<PPI::Statement::Sub> has a number of methods in addition to the standard | ||||
| 29 | L<PPI::Statement>, L<PPI::Node> and L<PPI::Element> methods. | ||||
| 30 | |||||
| 31 | =cut | ||||
| 32 | |||||
| 33 | 2 | 18µs | 2 | 33µs | # spent 22µs (11+11) within PPI::Statement::Sub::BEGIN@33 which was called:
# once (11µs+11µs) by PPI::Statement::Scheduled::BEGIN@57 at line 33 # spent 22µs making 1 call to PPI::Statement::Sub::BEGIN@33
# spent 11µs making 1 call to strict::import |
| 34 | 2 | 21µs | 1 | 3µs | # spent 3µs within PPI::Statement::Sub::BEGIN@34 which was called:
# once (3µs+0s) by PPI::Statement::Scheduled::BEGIN@57 at line 34 # spent 3µs making 1 call to PPI::Statement::Sub::BEGIN@34 |
| 35 | 2 | 24µs | 2 | 58µs | # spent 32µs (7+25) within PPI::Statement::Sub::BEGIN@35 which was called:
# once (7µs+25µs) by PPI::Statement::Scheduled::BEGIN@57 at line 35 # spent 32µs making 1 call to PPI::Statement::Sub::BEGIN@35
# spent 25µs making 1 call to Exporter::import |
| 36 | 2 | 18µs | 1 | 3µs | # spent 3µs within PPI::Statement::Sub::BEGIN@36 which was called:
# once (3µs+0s) by PPI::Statement::Scheduled::BEGIN@57 at line 36 # spent 3µs making 1 call to PPI::Statement::Sub::BEGIN@36 |
| 37 | |||||
| 38 | 2 | 27µs | 2 | 60µs | # spent 33µs (6+27) within PPI::Statement::Sub::BEGIN@38 which was called:
# once (6µs+27µs) by PPI::Statement::Scheduled::BEGIN@57 at line 38 # spent 33µs making 1 call to PPI::Statement::Sub::BEGIN@38
# spent 27µs making 1 call to vars::import |
| 39 | # spent 8µs within PPI::Statement::Sub::BEGIN@39 which was called:
# once (8µs+0s) by PPI::Statement::Scheduled::BEGIN@57 at line 42 | ||||
| 40 | 1 | 400ns | $VERSION = '1.215'; | ||
| 41 | 1 | 8µs | @ISA = 'PPI::Statement'; | ||
| 42 | 1 | 230µs | 1 | 8µs | } # spent 8µs making 1 call to PPI::Statement::Sub::BEGIN@39 |
| 43 | |||||
| 44 | # Lexer clue | ||||
| 45 | 3042 | 9.50ms | # spent 3.39ms within PPI::Statement::Sub::__LEXER__normal which was called 3042 times, avg 1µs/call:
# 3042 times (3.39ms+0s) by PPI::Lexer::_lex_statement at line 626 of PPI/Lexer.pm, avg 1µs/call | ||
| 46 | |||||
| 47 | sub _complete { | ||||
| 48 | my $child = $_[0]->schild(-1); | ||||
| 49 | return !! ( | ||||
| 50 | defined $child | ||||
| 51 | and | ||||
| 52 | $child->isa('PPI::Structure::Block') | ||||
| 53 | and | ||||
| 54 | $child->complete | ||||
| 55 | ); | ||||
| 56 | } | ||||
| 57 | |||||
| - - | |||||
| 62 | ##################################################################### | ||||
| 63 | # PPI::Statement::Sub Methods | ||||
| 64 | |||||
| 65 | =pod | ||||
| 66 | |||||
| 67 | =head2 name | ||||
| 68 | |||||
| 69 | The C<name> method returns the name of the subroutine being declared. | ||||
| 70 | |||||
| 71 | In some rare cases such as a naked C<sub> at the end of the file, this may return | ||||
| 72 | false. | ||||
| 73 | |||||
| 74 | =cut | ||||
| 75 | |||||
| 76 | sub name { | ||||
| 77 | my $self = shift; | ||||
| 78 | |||||
| 79 | # The second token should be the name, if we have one | ||||
| 80 | my $Token = $self->schild(1) or return ''; | ||||
| 81 | $Token->isa('PPI::Token::Word') and $Token->content; | ||||
| 82 | } | ||||
| 83 | |||||
| 84 | =pod | ||||
| 85 | |||||
| 86 | =head2 prototype | ||||
| 87 | |||||
| 88 | If it has one, the C<prototype> method returns the subroutine's prototype. | ||||
| 89 | It is returned in the same format as L<PPI::Token::Prototype/prototype>, | ||||
| 90 | cleaned and removed from its brackets. | ||||
| 91 | |||||
| 92 | Returns false if the subroutine does not define a prototype | ||||
| 93 | |||||
| 94 | =cut | ||||
| 95 | |||||
| 96 | # spent 47.5ms (7.17+40.4) within PPI::Statement::Sub::prototype which was called 1016 times, avg 47µs/call:
# 1016 times (7.17ms+40.4ms) by Perl::Critic::Policy::Subroutines::ProhibitSubroutinePrototypes::violates at line 36 of Perl/Critic/Policy/Subroutines/ProhibitSubroutinePrototypes.pm, avg 47µs/call | ||||
| 97 | 1016 | 179µs | my $self = shift; | ||
| 98 | my $Prototype = List::Util::first { | ||||
| 99 | 5080 | 38.8ms | 10160 | 31.7ms | _INSTANCE($_, 'PPI::Token::Prototype') # spent 27.4ms making 5080 calls to Params::Util::_INSTANCE, avg 5µs/call
# spent 4.30ms making 5080 calls to UNIVERSAL::isa, avg 846ns/call |
| 100 | 1016 | 2.95ms | 2032 | 40.4ms | } $self->children; # spent 38.4ms making 1016 calls to List::Util::first, avg 38µs/call
# spent 1.92ms making 1016 calls to PPI::Node::children, avg 2µs/call |
| 101 | 1016 | 2.28ms | defined($Prototype) ? $Prototype->prototype : ''; | ||
| 102 | } | ||||
| 103 | |||||
| 104 | =pod | ||||
| 105 | |||||
| 106 | =head2 block | ||||
| 107 | |||||
| 108 | With its name and implementation shared with L<PPI::Statement::Scheduled>, | ||||
| 109 | the C<block> method finds and returns the actual Structure object of the | ||||
| 110 | code block for this subroutine. | ||||
| 111 | |||||
| 112 | Returns false if this is a forward declaration, or otherwise does not have a | ||||
| 113 | code block. | ||||
| 114 | |||||
| 115 | =cut | ||||
| 116 | |||||
| 117 | sub block { | ||||
| 118 | my $self = shift; | ||||
| 119 | my $lastchild = $self->schild(-1) or return ''; | ||||
| 120 | $lastchild->isa('PPI::Structure::Block') and $lastchild; | ||||
| 121 | } | ||||
| 122 | |||||
| 123 | =pod | ||||
| 124 | |||||
| 125 | =head2 forward | ||||
| 126 | |||||
| 127 | The C<forward> method returns true if the subroutine declaration is a | ||||
| 128 | forward declaration. | ||||
| 129 | |||||
| 130 | That is, it returns false if the subroutine has a code block, or true | ||||
| 131 | if it does not. | ||||
| 132 | |||||
| 133 | =cut | ||||
| 134 | |||||
| 135 | sub forward { | ||||
| 136 | ! shift->block; | ||||
| 137 | } | ||||
| 138 | |||||
| 139 | =pod | ||||
| 140 | |||||
| 141 | =head2 reserved | ||||
| 142 | |||||
| 143 | The C<reserved> method provides a convenience method for checking to see | ||||
| 144 | if this is a special reserved subroutine. It does not check against any | ||||
| 145 | particular list of reserved sub names, but just returns true if the name | ||||
| 146 | is all uppercase, as defined in L<perlsub>. | ||||
| 147 | |||||
| 148 | Note that in the case of BEGIN, CHECK, UNITCHECK, INIT and END, these will be | ||||
| 149 | defined as L<PPI::Statement::Scheduled> objects, not subroutines. | ||||
| 150 | |||||
| 151 | Returns true if it is a special reserved subroutine, or false if not. | ||||
| 152 | |||||
| 153 | =cut | ||||
| 154 | |||||
| 155 | sub reserved { | ||||
| 156 | my $self = shift; | ||||
| 157 | my $name = $self->name or return ''; | ||||
| 158 | $name eq uc $name; | ||||
| 159 | } | ||||
| 160 | |||||
| 161 | 1 | 2µs | 1; | ||
| 162 | |||||
| 163 | =pod | ||||
| 164 | |||||
| 165 | =head1 TO DO | ||||
| 166 | |||||
| 167 | - Write unit tests for this package | ||||
| 168 | |||||
| 169 | =head1 SUPPORT | ||||
| 170 | |||||
| 171 | See the L<support section|PPI/SUPPORT> in the main module. | ||||
| 172 | |||||
| 173 | =head1 AUTHOR | ||||
| 174 | |||||
| 175 | Adam Kennedy E<lt>adamk@cpan.orgE<gt> | ||||
| 176 | |||||
| 177 | =head1 COPYRIGHT | ||||
| 178 | |||||
| 179 | Copyright 2001 - 2011 Adam Kennedy. | ||||
| 180 | |||||
| 181 | This program is free software; you can redistribute | ||||
| 182 | it and/or modify it under the same terms as Perl itself. | ||||
| 183 | |||||
| 184 | The full text of the license can be found in the | ||||
| 185 | LICENSE file included with this module. | ||||
| 186 | |||||
| 187 | =cut |