File Coverage

blib/lib/PPI/Token/Prototype.pm
Criterion Covered Total %
statement 10 10 100.0
branch n/a
condition n/a
subroutine 3 3 100.0
pod 1 1 100.0
total 14 14 100.0


line stmt bran cond sub pod time 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::Prototype
12             isa PPI::Token::Quote::Literal
13             isa PPI::Token::Quote
14             isa PPI::Token
15             isa PPI::Element
16              
17             =head1 SYNOPSIS
18              
19             sub ($@) prototype;
20              
21             =head1 DESCRIPTION
22              
23             Although it sort of looks like a list or condition, a subroutine
24             prototype is a lot more like a string. Its job is to provide hints
25             to the perl compiler on what type of arguments a particular subroutine
26             expects, which the compiler uses to validate parameters at compile-time,
27             and allows programmers to use the functions without explicit parameter
28             parens.
29              
30             Due to the rise of OO Perl coding, which ignores these prototypes, they
31             are most often used to allow for constant-like things, and to "extend"
32             the language and create things that act like keywords and core functions.
33              
34             # Create something that acts like a constant
35             sub MYCONSTANT () { 10 }
36            
37             # Create the "any" core-looking function
38             sub any (&@) { ... }
39            
40             if ( any { $_->cute } @babies ) {
41             ...
42             }
43              
44             =head1 METHODS
45              
46             This class provides one additional method beyond those defined by the
47             L<PPI::Token> and L<PPI::Element> parent classes.
48              
49             =cut
50              
51 67     67   338 use strict;
  67         101  
  67         1769  
52 67     67   216 use PPI::Token ();
  67         89  
  67         8214  
53              
54             our $VERSION = '1.284';
55              
56             our @ISA = "PPI::Token::Quote::Literal";
57              
58             =pod
59              
60             =head2 prototype
61              
62             The C<prototype> accessor returns the actual prototype pattern, stripped
63             of flanking parens and of all whitespace. This mirrors the behavior of
64             the Perl C<prototype> builtin function.
65              
66             Note that stripping parens and whitespace means that the return of
67             C<prototype> can be an empty string.
68              
69             =cut
70              
71             sub prototype {
72 116     116 1 36945 my $self = shift;
73 116         293 my $proto = $self->content;
74 116         848 $proto =~ s/(^\(|\)$|\s+)//g;
75 116         267 $proto;
76             }
77              
78             1;
79              
80             =pod
81              
82             =head1 SUPPORT
83              
84             See the L<support section|PPI/SUPPORT> in the main module.
85              
86             =head1 AUTHOR
87              
88             Adam Kennedy E<lt>adamk@cpan.orgE<gt>
89              
90             =head1 COPYRIGHT
91              
92             Copyright 2001 - 2011 Adam Kennedy.
93              
94             This program is free software; you can redistribute
95             it and/or modify it under the same terms as Perl itself.
96              
97             The full text of the license can be found in the
98             LICENSE file included with this module.
99              
100             =cut