1 package PPI::Token::Prototype;
7 PPI::Token::Prototype - A subroutine prototype descriptor
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
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.
32 # Create something that acts like a constant
33 sub MYCONSTANT () { 10 }
35 # Create the "any" core-looking function
38 if ( any { $_->cute } @babies ) {
44 This class provides one additional method beyond those defined by the
45 L<PPI::Token> and L<PPI::Element> parent classes.
52 use vars qw{$VERSION @ISA};
58 sub __TOKENIZER__on_char {
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;
69 # Shortcut if end of line
70 return 0 unless $1 =~ /\)$/;
72 # Found the closing bracket
73 $t->_finalize_token->__TOKENIZER__on_char( $t );
80 The C<prototype> accessor returns the actual prototype pattern, stripped
81 of braces and any whitespace inside the pattern.
87 my $proto = $self->content;
88 $proto =~ s/\(\)\s//g; # Strip brackets and whitespace
98 See the L<support section|PPI/SUPPORT> in the main module.
102 Adam Kennedy E<lt>adamk@cpan.orgE<gt>
106 Copyright 2001 - 2009 Adam Kennedy.
108 This program is free software; you can redistribute
109 it and/or modify it under the same terms as Perl itself.
111 The full text of the license can be found in the
112 LICENSE file included with this module.