PPI/Token/Prototype.pm

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