Utils/Language.pm

filter: Statementstmt 100% 20 / 20 Branchbran 75.0% 3 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod 100% 2 / 2 totaltotal 96.7% 30 / 31 CC 3 SCAR 6.3
CC
3
Cov
96%
precedence_of
3.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.9
« Utils.pm ↑ Summary
1 package PPIx::Utils::Language;
2  
3 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 4 our $VERSION = '0.002';
8  
9 4 our @EXPORT_OK = qw(precedence_of symbol_without_sigil);
10  
11 4 our %EXPORT_TAGS = (all => [@EXPORT_OK]);
12  
13 # From Perl::Critic::Utils
14 4 my %PRECEDENCE_OF = (
15 '->' => 1,
16 '++' => 2,
17 '--' => 2,
18 '**' => 3,
19 '!' => 4,
20 '~' => 4,
21 '\\' => 4,
22 '=~' => 5,
23 '!~' => 5,
24 '*' => 6,
25 '/' => 6,
26 '%' => 6,
27 'x' => 6,
28 '+' => 7,
29 '-' => 7,
30 '.' => 7,
31 '<<' => 8,
32 '>>' => 8,
33 '-R' => 9,
34 '-W' => 9,
35 '-X' => 9,
36 '-r' => 9,
37 '-w' => 9,
38 '-x' => 9,
39 '-e' => 9,
40 '-O' => 9,
41 '-o' => 9,
42 '-z' => 9,
43 '-s' => 9,
44 '-M' => 9,
45 '-A' => 9,
46 '-C' => 9,
47 '-S' => 9,
48 '-c' => 9,
49 '-b' => 9,
50 '-f' => 9,
51 '-d' => 9,
52 '-p' => 9,
53 '-l' => 9,
54 '-u' => 9,
55 '-g' => 9,
56 '-k' => 9,
57 '-t' => 9,
58 '-T' => 9,
59 '-B' => 9,
60 '<' => 10,
61 '>' => 10,
62 '<=' => 10,
63 '>=' => 10,
64 'lt' => 10,
65 'gt' => 10,
66 'le' => 10,
67 'ge' => 10,
68 '==' => 11,
69 '!=' => 11,
70 '<=>' => 11,
71 'eq' => 11,
72 'ne' => 11,
73 'cmp' => 11,
74 '~~' => 11,
75 '&' => 12,
76 '|' => 13,
77 '^' => 13,
78 '&&' => 14,
79 '//' => 15,
80 '||' => 15,
81 '..' => 16,
82 '...' => 17,
83 '?' => 18,
84 ':' => 18,
85 '=' => 19,
86 '+=' => 19,
87 '-=' => 19,
88 '*=' => 19,
89 '/=' => 19,
90 '%=' => 19,
91 '||=' => 19,
92 '&&=' => 19,
93 '|=' => 19,
94 '&=' => 19,
95 '**=' => 19,
96 'x=' => 19,
97 '.=' => 19,
98 '^=' => 19,
99 '<<=' => 19,
100 '>>=' => 19,
101 '//=' => 19,
102 ',' => 20,
103 '=>' => 20,
104 'not' => 22,
105 'and' => 23,
106 'or' => 24,
107 'xor' => 24,
108 );
109  
110 sub precedence_of {
111 9 ▶ my $elem = shift;
Subroutine precedence_of: called CC=3 SCAR=11.1
Pod documented
112 9 ▶ return undef if !$elem;
Branch: 1 branch
BranchTrueFalseTotal
unless $elem 0 9 9
113 9 ▶ return $PRECEDENCE_OF{ ref $elem ? "$elem" : $elem };
Branch: 1 branch
BranchTrueFalseTotal
ref $elem ? : 4 5 9
114 }
115 # End from Perl::Critic::Utils
116  
117 # From Perl::Critic::Utils::Perl
118 sub symbol_without_sigil {
119 6 ▶ my ($symbol) = @_;
Subroutine symbol_without_sigil: called CC=1 SCAR=0.0
Pod documented
120  
121 6 (my $without_sigil = $symbol) =~ s< \A [\$@%*&] ><>x;
122  
123 6 return $without_sigil;
124 }
125 # End from Perl::Critic::Utils::Perl
126  
127 4 1;
128  
129 =head1 NAME
130  
131 PPIx::Utils::Language - Utility functions for PPI related to the Perl language
132  
133 =head1 SYNOPSIS
134  
135 use PPIx::Utils::Language ':all';
136  
137 =head1 DESCRIPTION
138  
139 This package is a component of L<PPIx::Utils> that contains functions
140 related to aspects of the Perl language.
141  
142 =head1 FUNCTIONS
143  
144 All functions can be imported by name, or with the tag C<:all>.
145  
146 =head2 precedence_of
147  
148 my $precedence = precedence_of($element);
149  
150 Given a L<PPI::Token::Operator> or a string, returns the precedence of
151 the operator, where 1 is the highest precedence. Returns undef if the
152 precedence can't be determined (which is usually because it is not an
153 operator).
154  
155 =head2 symbol_without_sigil
156  
157 my $name = symbol_without_sigil($symbol);
158  
159 Returns the name of the specified symbol with any sigil at the front.
160 The parameter can be a vanilla Perl string or a L<PPI::Element>.
161  
162 =head1 BUGS
163  
164 Report any issues on the public bugtracker.
165  
166 =head1 AUTHOR
167  
168 Dan Book <dbook@cpan.org>
169  
170 Code originally from L<Perl::Critic::Utils> by Jeffrey Ryan Thalhammer
171 <jeff@imaginative-software.com> and L<Perl::Critic::Utils::Perl> by
172 Elliot Shank <perl@galumph.com>
173  
174 =head1 COPYRIGHT AND LICENSE
175  
176 This software is copyright (c) 2005-2011 Imaginative Software Systems,
177 2007-2011 Elliot Shank, 2017 Dan Book.
178  
179 This is free software; you can redistribute it and/or modify it under
180 the same terms as the Perl 5 programming language system itself.
181  
182 =head1 SEE ALSO
183  
184 L<Perl::Critic::Utils>, L<Perl::Critic::Utils::Perl>
« Utils.pm ↑ Summary