Add built local::lib
[catagits/Gitalist.git] / local-lib5 / lib / perl5 / PPI / Token / Prototype.pm
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 use strict;
50 use PPI::Token ();
51
52 use vars qw{$VERSION @ISA};
53 BEGIN {
54         $VERSION = '1.206';
55         @ISA     = 'PPI::Token';
56 }
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;
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 - 2009 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