Filename | /Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/PPI/Token/Prototype.pm |
Statements | Executed 9 statements in 283µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 16µs | 33µs | BEGIN@49 | PPI::Token::Prototype::
1 | 1 | 1 | 11µs | 11µs | BEGIN@53 | PPI::Token::Prototype::
1 | 1 | 1 | 9µs | 48µs | BEGIN@52 | PPI::Token::Prototype::
1 | 1 | 1 | 5µs | 5µs | BEGIN@50 | PPI::Token::Prototype::
0 | 0 | 0 | 0s | 0s | __TOKENIZER__on_char | PPI::Token::Prototype::
0 | 0 | 0 | 0s | 0s | prototype | PPI::Token::Prototype::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package PPI::Token::Prototype; | ||||
2 | |||||
3 | =pod | ||||
4 | |||||
5 | =head1 NAME | ||||
6 | |||||
7 | PPI::Token::Prototype - A subroutine prototype descriptor | ||||
8 | |||||
9 | =head1 INHERITANCE | ||||
10 | |||||
11 | PPI::Token::End | ||||
12 | isa PPI::Token | ||||
13 | isa PPI::Element | ||||
14 | |||||
15 | =head1 SYNOPSIS | ||||
16 | |||||
17 | sub ($@) prototype; | ||||
18 | |||||
19 | =head1 DESCRIPTION | ||||
20 | |||||
21 | Although it sort of looks like a list or condition, a subroutine | ||||
22 | prototype is a lot more like a string. Its job is to provide hints | ||||
23 | to the perl compiler on what type of arguments a particular subroutine | ||||
24 | expects, which the compiler uses to validate parameters at compile-time, | ||||
25 | and allows programmers to use the functions without explicit parameter | ||||
26 | braces. | ||||
27 | |||||
28 | Due to the rise of OO Perl coding, which ignores these prototypes, they | ||||
29 | are most often used to allow for constant-like things, and to "extend" | ||||
30 | the language and create things that act like keywords and core functions. | ||||
31 | |||||
32 | # Create something that acts like a constant | ||||
33 | sub MYCONSTANT () { 10 } | ||||
34 | |||||
35 | # Create the "any" core-looking function | ||||
36 | sub any (&@) { ... } | ||||
37 | |||||
38 | if ( any { $_->cute } @babies ) { | ||||
39 | ... | ||||
40 | } | ||||
41 | |||||
42 | =head1 METHODS | ||||
43 | |||||
44 | This class provides one additional method beyond those defined by the | ||||
45 | L<PPI::Token> and L<PPI::Element> parent classes. | ||||
46 | |||||
47 | =cut | ||||
48 | |||||
49 | 2 | 26µs | 2 | 49µs | # spent 33µs (16+16) within PPI::Token::Prototype::BEGIN@49 which was called:
# once (16µs+16µs) by PPI::Token::BEGIN@74 at line 49 # spent 33µs making 1 call to PPI::Token::Prototype::BEGIN@49
# spent 16µs making 1 call to strict::import |
50 | 2 | 25µs | 1 | 5µs | # spent 5µs within PPI::Token::Prototype::BEGIN@50 which was called:
# once (5µs+0s) by PPI::Token::BEGIN@74 at line 50 # spent 5µs making 1 call to PPI::Token::Prototype::BEGIN@50 |
51 | |||||
52 | 2 | 39µs | 2 | 86µs | # spent 48µs (9+39) within PPI::Token::Prototype::BEGIN@52 which was called:
# once (9µs+39µs) by PPI::Token::BEGIN@74 at line 52 # spent 48µs making 1 call to PPI::Token::Prototype::BEGIN@52
# spent 39µs making 1 call to vars::import |
53 | # spent 11µs within PPI::Token::Prototype::BEGIN@53 which was called:
# once (11µs+0s) by PPI::Token::BEGIN@74 at line 56 | ||||
54 | 1 | 500ns | $VERSION = '1.215'; | ||
55 | 1 | 11µs | @ISA = 'PPI::Token'; | ||
56 | 1 | 179µs | 1 | 11µs | } # spent 11µs making 1 call to PPI::Token::Prototype::BEGIN@53 |
57 | |||||
58 | sub __TOKENIZER__on_char { | ||||
59 | my $class = shift; | ||||
60 | my $t = shift; | ||||
61 | |||||
62 | # Suck in until we find the closing bracket (or the end of line) | ||||
63 | my $line = substr( $t->{line}, $t->{line_cursor} ); | ||||
64 | if ( $line =~ /^(.*?(?:\)|$))/ ) { | ||||
65 | $t->{token}->{content} .= $1; | ||||
66 | $t->{line_cursor} += length $1; | ||||
67 | } | ||||
68 | |||||
69 | # Shortcut if end of line | ||||
70 | return 0 unless $1 =~ /\)$/; | ||||
71 | |||||
72 | # Found the closing bracket | ||||
73 | $t->_finalize_token->__TOKENIZER__on_char( $t ); | ||||
74 | } | ||||
75 | |||||
76 | =pod | ||||
77 | |||||
78 | =head2 prototype | ||||
79 | |||||
80 | The C<prototype> accessor returns the actual prototype pattern, stripped | ||||
81 | of braces and any whitespace inside the pattern. | ||||
82 | |||||
83 | =cut | ||||
84 | |||||
85 | sub prototype { | ||||
86 | my $self = shift; | ||||
87 | my $proto = $self->content; | ||||
88 | $proto =~ s/\(\)\s//g; # Strip brackets and whitespace | ||||
89 | $proto; | ||||
90 | } | ||||
91 | |||||
92 | 1 | 2µs | 1; | ||
93 | |||||
94 | =pod | ||||
95 | |||||
96 | =head1 SUPPORT | ||||
97 | |||||
98 | See the L<support section|PPI/SUPPORT> in the main module. | ||||
99 | |||||
100 | =head1 AUTHOR | ||||
101 | |||||
102 | Adam Kennedy E<lt>adamk@cpan.orgE<gt> | ||||
103 | |||||
104 | =head1 COPYRIGHT | ||||
105 | |||||
106 | Copyright 2001 - 2011 Adam Kennedy. | ||||
107 | |||||
108 | This program is free software; you can redistribute | ||||
109 | it and/or modify it under the same terms as Perl itself. | ||||
110 | |||||
111 | The full text of the license can be found in the | ||||
112 | LICENSE file included with this module. | ||||
113 | |||||
114 | =cut |