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::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             parens.
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 and L parent classes.
46              
47             =cut
48              
49 65     65   481 use strict;
  65         143  
  65         1901  
50 65     65   367 use PPI::Token ();
  65         133  
  65         7752  
51              
52             our $VERSION = '1.277';
53              
54             our @ISA = "PPI::Token::Quote::Literal";
55              
56             =pod
57              
58             =head2 prototype
59              
60             The C accessor returns the actual prototype pattern, stripped
61             of flanking parens and of all whitespace. This mirrors the behavior of
62             the Perl C builtin function.
63              
64             Note that stripping parens and whitespace means that the return of
65             C can be an empty string.
66              
67             =cut
68              
69             sub prototype {
70 116     116 1 45293 my $self = shift;
71 116         342 my $proto = $self->content;
72 116         902 $proto =~ s/(^\(|\)$|\s+)//g;
73 116         324 $proto;
74             }
75              
76             1;
77              
78             =pod
79              
80             =head1 SUPPORT
81              
82             See the L in the main module.
83              
84             =head1 AUTHOR
85              
86             Adam Kennedy Eadamk@cpan.orgE
87              
88             =head1 COPYRIGHT
89              
90             Copyright 2001 - 2011 Adam Kennedy.
91              
92             This program is free software; you can redistribute
93             it and/or modify it under the same terms as Perl itself.
94              
95             The full text of the license can be found in the
96             LICENSE file included with this module.
97              
98             =cut