PPI/Token/Prototype.pm

filter: Statementstmt 100% 24 / 24 Branchbran 75.0% 3 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod 100% 1 / 1 totaltotal 97.1% 34 / 35 CC 3 SCAR 5.6
CC
3
Cov
96%
__TOKENIZER__on_char
3.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.8
« PPI/Token/DashedWord.pm ↑ Summary PPI/Token/Data.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 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<PPI::Token> and L<PPI::Element> parent classes.
46  
47 =cut
48  
49 62 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
50 62 ▶use PPI::Token ();
Subroutine BEGIN: called CC=1 SCAR=0.0
51  
52 62 ▶use vars qw{$VERSION @ISA};
Subroutine BEGIN: called CC=1 SCAR=0.0
53 BEGIN {
54 62 ▶ $VERSION = '1.236';
Subroutine BEGIN: called CC=1 SCAR=0.0
55 62 @ISA = 'PPI::Token';
56 }
57  
58 sub __TOKENIZER__on_char {
59 431 ▶ my $class = shift;
Subroutine __TOKENIZER__on_char: called CC=3 SCAR=11.0
60 431 my $t = shift;
61  
62 # Suck in until we find the closing paren (or the end of line)
63 431 pos $t->{line} = $t->{line_cursor};
64 431 ▶ die "regex should always match" if $t->{line} !~ m/\G(.*?(?:\)|$))/gc;
Branch: 1 branch
BranchTrueFalseTotal
unless $t->{"line"} =~ /\G(.*?(?:\)|$))/cg 0 431 431
65 431 $t->{token}->{content} .= $1;
66 431 $t->{line_cursor} += length $1;
67  
68 # Shortcut if end of line
69 431 ▶ return 0 unless $1 =~ /\)$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $1 =~ /\)$/ 9 422 431
70  
71 # Found the closing paren
72 422 $t->_finalize_token->__TOKENIZER__on_char( $t );
73 }
74  
75 =pod
76  
77 =head2 prototype
78  
79 The C<prototype> accessor returns the actual prototype pattern, stripped
80 of flanking parens and of all whitespace. This mirrors the behavior of
81 the Perl C<prototype> builtin function.
82  
83 Note that stripping parens and whitespace means that the return of
84 C<prototype> can be an empty string.
85  
86 =cut
87  
88 sub prototype {
89 194 ▶ my $self = shift;
Subroutine prototype: called CC=1 SCAR=0.0
Pod documented
90 194 my $proto = $self->content;
91 194 $proto =~ s/(^\(|\)$|\s+)//g;
92 194 $proto;
93 }
94  
95 62 1;
96  
97 =pod
98  
99 =head1 SUPPORT
100  
101 See the L<support section|PPI/SUPPORT> in the main module.
102  
103 =head1 AUTHOR
104  
105 Adam Kennedy E<lt>adamk@cpan.orgE<gt>
106  
107 =head1 COPYRIGHT
108  
109 Copyright 2001 - 2011 Adam Kennedy.
110  
111 This program is free software; you can redistribute
112 it and/or modify it under the same terms as Perl itself.
113  
114 The full text of the license can be found in the
115 LICENSE file included with this module.
116  
117 =cut
« PPI/Token/DashedWord.pm ↑ Summary PPI/Token/Data.pm »